💾 Archived View for gmi.noulin.net › gitRepositories › bcrypt › file › bcryptTest.c.gmi captured on 2023-01-29 at 13:17:14. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
bcryptTest.c (1675B)
1 #! /usr/bin/env sheepy 2 3 #include "libsheepyObject.h" 4 #include "bcrypt.h" 5 6 int argc; char **argv; 7 8 void callback(i64 err, char hash[BCRYPT_HASHSIZE], void *env) { 9 puts(hash); 10 } 11 12 void checkCallback(i64 err, int result, void *callbackEnv) { 13 if (result) { 14 printf("The password matches\n"); 15 } else { 16 printf("The password does NOT match\n"); 17 } 18 } 19 20 int main(int ARGC, char** ARGV) { 21 22 argc = ARGC; argv = ARGV; 23 24 initLibsheepy(argv[0]); 25 26 puts("C template"); 27 28 29 char salt[BCRYPT_HASHSIZE]; 30 char hash[BCRYPT_HASHSIZE]; 31 int ret; 32 33 u64 start = getMonotonicTime(); 34 ret = bcryptGensaltSync(12, salt); 35 ret = bcryptHashSync("thepassword", salt, hash); 36 u64 end = getMonotonicTime(); 37 printf("Hashed in %ld miliseconds\n", (end-start)/1000000); 38 39 40 //Verifying a password: 41 42 start = getMonotonicTime(); 43 ret = bcryptCheckSync("thepassword", "expectedhash"); 44 end = getMonotonicTime(); 45 printf("Verified password in %ld miliseconds\n", (end-start)/1000000); 46 47 if (ret) { 48 printf("The password matches\n"); 49 } else { 50 printf("The password does NOT match\n"); 51 } 52 53 start = getMonotonicTime(); 54 ret = bcryptCheckSync("thepassword", hash); 55 end = getMonotonicTime(); 56 printf("Verified password in %ld miliseconds\n", (end-start)/1000000); 57 58 if (ret) { 59 printf("The password matches\n"); 60 } else { 61 printf("The password does NOT match\n"); 62 } 63 64 puts(hash); 65 66 bcryptHash("passwd", 12, NULL, NULL); 67 bcryptHash("passwd", 12, callback, NULL); 68 bcryptHash("passwd", 12, callback, NULL); 69 bcryptCheck("passwd", "expectedhash", checkCallback, NULL); 70 bcryptCheck("passwd", hash, checkCallback, NULL); 71 72 puts("Waiting for tpool..."); 73 tpoolWait; 74 finalizeLibsheepy(); 75 76 }