| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #define PERL_NO_GET_CONTEXT | 
| 2 |  |  |  |  |  |  | #include "EXTERN.h" | 
| 3 |  |  |  |  |  |  | #include "perl.h" | 
| 4 |  |  |  |  |  |  | #include "XSUB.h" | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | #include "crypt_blowfish.h" | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | #define BCRYPT_HASHSIZE 64 | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 9 |  |  |  |  |  | static int timing_safe_compare(const unsigned char *str1, const unsigned char *str2, STRLEN length) { | 
| 11 | 9 |  |  |  |  |  | int ret = 0; | 
| 12 |  |  |  |  |  |  | int i; | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 549 | 100 |  |  |  |  | for (i = 0; i < length; ++i) | 
| 15 | 540 |  |  |  |  |  | ret |= (str1[i] ^ str2[i]); | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 9 |  |  |  |  |  | return ret == 0; | 
| 18 |  |  |  |  |  |  | } | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | MODULE = Crypt::Bcrypt              PACKAGE = Crypt::Bcrypt | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | PROTOTYPES: DISABLE | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | const char* _bcrypt_hashpw(const char* password, const char* settings) | 
| 25 |  |  |  |  |  |  | CODE: | 
| 26 |  |  |  |  |  |  | char outhash[BCRYPT_HASHSIZE]; | 
| 27 | 22 |  |  |  |  |  | const char* output = _crypt_blowfish_rn(password, settings, outhash, BCRYPT_HASHSIZE); | 
| 28 | 22 | 50 |  |  |  |  | if (output == NULL) | 
| 29 | 0 |  |  |  |  |  | Perl_croak(aTHX_ "Could not hash: %s", strerror(errno)); | 
| 30 | 22 |  |  |  |  |  | RETVAL = outhash; | 
| 31 |  |  |  |  |  |  | OUTPUT: | 
| 32 |  |  |  |  |  |  | RETVAL | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | int bcrypt_check(const char* password, const char* hash, STRLEN length(hash)) | 
| 35 |  |  |  |  |  |  | CODE: | 
| 36 |  |  |  |  |  |  | char outhash[BCRYPT_HASHSIZE]; | 
| 37 |  |  |  |  |  |  | STRLEN hashlen; | 
| 38 | 9 |  |  |  |  |  | const char* ret = _crypt_blowfish_rn(password, hash, outhash, BCRYPT_HASHSIZE); | 
| 39 | 9 | 50 |  |  |  |  | if (!ret || strlen(outhash) != STRLEN_length_of_hash) | 
|  |  | 50 |  |  |  |  |  | 
| 40 | 0 |  |  |  |  |  | RETVAL = 0; | 
| 41 |  |  |  |  |  |  | else | 
| 42 | 9 |  |  |  |  |  | RETVAL = timing_safe_compare((const unsigned char *)hash, (const unsigned char *)outhash, STRLEN_length_of_hash); | 
| 43 |  |  |  |  |  |  | OUTPUT: | 
| 44 |  |  |  |  |  |  | RETVAL |