| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| MODULE = Crypt::OpenSSL::PBKDF2 PACKAGE = Crypt::OpenSSL::PBKDF2 |
| 6 |
|
| |
| 7 |
|
| #include <openssl/ssl.h> |
| 8 |
|
| #include <openssl/evp.h> |
| 9 |
|
| #include <openssl/err.h> |
| 10 |
|
| |
| 11 |
|
| SV * |
| 12 |
|
| derive(pass, salt, saltlen, iter, hlen, ...) |
| 13 |
|
| const char * pass |
| 14 |
|
| unsigned char * salt |
| 15 |
|
| int saltlen |
| 16 |
|
| int iter |
| 17 |
|
| int hlen |
| 18 |
|
| PREINIT: |
| 19 |
10 |
| const char * alg = "sha1"; |
| 20 |
|
| INIT: |
| 21 |
10 |
| unsigned char * hash = NULL; |
| 22 |
10 |
| int plen = strlen(pass); |
| 23 |
|
| const EVP_MD *md; |
| 24 |
|
| CODE: |
| 25 |
10 |
▶ | if( items > 5 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( items > 5 ) |
3 |
7 |
10 |
|
| 26 |
6 |
| alg = (const char *)SvPV_nolen(ST(5)); |
| 27 |
10 |
▶ | if ((md = EVP_get_digestbyname(alg)) == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((md = EVP_get_digestbyname(alg)) == NULL) |
2 |
8 |
10 |
|
| 28 |
2 |
| croak("invalid hashing algorithm"); |
| 29 |
|
| |
| 30 |
8 |
▶ | if ( Newxz(hash, hlen, unsigned char) == NULL ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( Newxz(hash, hlen, unsigned char) == NULL ) |
0 |
8 |
8 |
|
| 31 |
0 |
| croak("unable to allocate buffer for hash"); |
| 32 |
8 |
| SSL_library_init(); |
| 33 |
8 |
| ERR_load_crypto_strings(); |
| 34 |
8 |
▶ | if (PKCS5_PBKDF2_HMAC(pass, plen, salt, saltlen, iter, md, hlen, hash) != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (PKCS5_PBKDF2_HMAC(pass, plen, salt, saltlen, iter, md, hlen, hash) != 1) |
0 |
8 |
8 |
|
| 35 |
0 |
| croak("an error occurred: %s", ERR_error_string(ERR_get_error(), NULL)); |
| 36 |
8 |
| RETVAL = newSVpv((char *)hash, hlen); |
| 37 |
8 |
| ERR_free_strings(); |
| 38 |
8 |
| Safefree(hash); |
| 39 |
|
| OUTPUT: |
| 40 |
|
| RETVAL |
| 41 |
|
| |
| 42 |
|
| SV * |
| 43 |
|
| derive_bin(pass, passlen, salt, saltlen, iter, hlen, ...) |
| 44 |
|
| unsigned char * pass |
| 45 |
|
| int passlen |
| 46 |
|
| unsigned char * salt |
| 47 |
|
| int saltlen |
| 48 |
|
| int iter |
| 49 |
|
| int hlen |
| 50 |
|
| PREINIT: |
| 51 |
8 |
| const char * alg = "sha1"; |
| 52 |
|
| INIT: |
| 53 |
8 |
| unsigned char * hash = NULL; |
| 54 |
|
| const EVP_MD *md; |
| 55 |
|
| CODE: |
| 56 |
8 |
▶ | if( items > 6 ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( items > 6 ) |
1 |
7 |
8 |
|
| 57 |
2 |
| alg = (const char *)SvPV_nolen(ST(6)); |
| 58 |
8 |
▶ | if ((md = EVP_get_digestbyname(alg)) == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((md = EVP_get_digestbyname(alg)) == NULL) |
0 |
8 |
8 |
|
| 59 |
0 |
| croak("invalid hashing algorithm"); |
| 60 |
|
| |
| 61 |
8 |
▶ | if ( Newxz(hash, hlen, unsigned char) == NULL ) |
Branch: 1 branch
| Branch | True | False | Total |
| if ( Newxz(hash, hlen, unsigned char) == NULL ) |
0 |
8 |
8 |
|
| 62 |
0 |
| croak ("unable to allocate buffer for hash"); |
| 63 |
8 |
| SSL_library_init(); |
| 64 |
8 |
| ERR_load_crypto_strings(); |
| 65 |
8 |
▶ | if (PKCS5_PBKDF2_HMAC((const char *)pass, passlen, salt, saltlen, iter, md, hlen, hash) != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (PKCS5_PBKDF2_HMAC((const char *)pass, passlen, salt, saltlen, iter, md, hlen, hash) != 1) |
0 |
8 |
8 |
|
| 66 |
0 |
| croak ("an error occurred: %s", ERR_error_string(ERR_get_error(), NULL)); |
| 67 |
8 |
| RETVAL = newSVpv((char *)hash, hlen); |
| 68 |
8 |
| ERR_free_strings(); |
| 69 |
8 |
| Safefree(hash); |
| 70 |
|
| OUTPUT: |
| 71 |
|
| RETVAL |