diff options
Diffstat (limited to 'src/lib/libcrypto/pkcs12/p12_key.c')
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_key.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c index b364671ed2..b042dcf05c 100644 --- a/src/lib/libcrypto/pkcs12/p12_key.c +++ b/src/lib/libcrypto/pkcs12/p12_key.c | |||
| @@ -74,25 +74,30 @@ void h__dump (unsigned char *p, int len); | |||
| 74 | #define min(a,b) ((a) < (b) ? (a) : (b)) | 74 | #define min(a,b) ((a) < (b) ? (a) : (b)) |
| 75 | #endif | 75 | #endif |
| 76 | 76 | ||
| 77 | int PKCS12_key_gen_asc (const char *pass, int passlen, unsigned char *salt, | 77 | int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt, |
| 78 | int saltlen, int id, int iter, int n, unsigned char *out, | 78 | int saltlen, int id, int iter, int n, unsigned char *out, |
| 79 | const EVP_MD *md_type) | 79 | const EVP_MD *md_type) |
| 80 | { | 80 | { |
| 81 | int ret; | 81 | int ret; |
| 82 | unsigned char *unipass; | 82 | unsigned char *unipass; |
| 83 | int uniplen; | 83 | int uniplen; |
| 84 | if (!asc2uni (pass, &unipass, &uniplen)) { | 84 | if(!pass) { |
| 85 | unipass = NULL; | ||
| 86 | uniplen = 0; | ||
| 87 | } else if (!asc2uni(pass, &unipass, &uniplen)) { | ||
| 85 | PKCS12err(PKCS12_F_PKCS12_KEY_GEN_ASC,ERR_R_MALLOC_FAILURE); | 88 | PKCS12err(PKCS12_F_PKCS12_KEY_GEN_ASC,ERR_R_MALLOC_FAILURE); |
| 86 | return 0; | 89 | return 0; |
| 87 | } | 90 | } |
| 88 | ret = PKCS12_key_gen_uni (unipass, uniplen, salt, saltlen, | 91 | ret = PKCS12_key_gen_uni(unipass, uniplen, salt, saltlen, |
| 89 | id, iter, n, out, md_type); | 92 | id, iter, n, out, md_type); |
| 90 | memset(unipass, 0, uniplen); /* Clear password from memory */ | 93 | if(unipass) { |
| 91 | Free(unipass); | 94 | memset(unipass, 0, uniplen); /* Clear password from memory */ |
| 95 | OPENSSL_free(unipass); | ||
| 96 | } | ||
| 92 | return ret; | 97 | return ret; |
| 93 | } | 98 | } |
| 94 | 99 | ||
| 95 | int PKCS12_key_gen_uni (unsigned char *pass, int passlen, unsigned char *salt, | 100 | int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt, |
| 96 | int saltlen, int id, int iter, int n, unsigned char *out, | 101 | int saltlen, int id, int iter, int n, unsigned char *out, |
| 97 | const EVP_MD *md_type) | 102 | const EVP_MD *md_type) |
| 98 | { | 103 | { |
| @@ -106,10 +111,12 @@ int PKCS12_key_gen_uni (unsigned char *pass, int passlen, unsigned char *salt, | |||
| 106 | int tmpn = n; | 111 | int tmpn = n; |
| 107 | #endif | 112 | #endif |
| 108 | 113 | ||
| 114 | #if 0 | ||
| 109 | if (!pass) { | 115 | if (!pass) { |
| 110 | PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_PASSED_NULL_PARAMETER); | 116 | PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_PASSED_NULL_PARAMETER); |
| 111 | return 0; | 117 | return 0; |
| 112 | } | 118 | } |
| 119 | #endif | ||
| 113 | 120 | ||
| 114 | #ifdef DEBUG_KEYGEN | 121 | #ifdef DEBUG_KEYGEN |
| 115 | fprintf(stderr, "KEYGEN DEBUG\n"); | 122 | fprintf(stderr, "KEYGEN DEBUG\n"); |
| @@ -121,13 +128,14 @@ int PKCS12_key_gen_uni (unsigned char *pass, int passlen, unsigned char *salt, | |||
| 121 | #endif | 128 | #endif |
| 122 | v = EVP_MD_block_size (md_type); | 129 | v = EVP_MD_block_size (md_type); |
| 123 | u = EVP_MD_size (md_type); | 130 | u = EVP_MD_size (md_type); |
| 124 | D = Malloc (v); | 131 | D = OPENSSL_malloc (v); |
| 125 | Ai = Malloc (u); | 132 | Ai = OPENSSL_malloc (u); |
| 126 | B = Malloc (v + 1); | 133 | B = OPENSSL_malloc (v + 1); |
| 127 | Slen = v * ((saltlen+v-1)/v); | 134 | Slen = v * ((saltlen+v-1)/v); |
| 128 | Plen = v * ((passlen+v-1)/v); | 135 | if(passlen) Plen = v * ((passlen+v-1)/v); |
| 136 | else Plen = 0; | ||
| 129 | Ilen = Slen + Plen; | 137 | Ilen = Slen + Plen; |
| 130 | I = Malloc (Ilen); | 138 | I = OPENSSL_malloc (Ilen); |
| 131 | Ij = BN_new(); | 139 | Ij = BN_new(); |
| 132 | Bpl1 = BN_new(); | 140 | Bpl1 = BN_new(); |
| 133 | if (!D || !Ai || !B || !I || !Ij || !Bpl1) { | 141 | if (!D || !Ai || !B || !I || !Ij || !Bpl1) { |
| @@ -150,10 +158,10 @@ int PKCS12_key_gen_uni (unsigned char *pass, int passlen, unsigned char *salt, | |||
| 150 | } | 158 | } |
| 151 | memcpy (out, Ai, min (n, u)); | 159 | memcpy (out, Ai, min (n, u)); |
| 152 | if (u >= n) { | 160 | if (u >= n) { |
| 153 | Free (Ai); | 161 | OPENSSL_free (Ai); |
| 154 | Free (B); | 162 | OPENSSL_free (B); |
| 155 | Free (D); | 163 | OPENSSL_free (D); |
| 156 | Free (I); | 164 | OPENSSL_free (I); |
| 157 | BN_free (Ij); | 165 | BN_free (Ij); |
| 158 | BN_free (Bpl1); | 166 | BN_free (Bpl1); |
| 159 | #ifdef DEBUG_KEYGEN | 167 | #ifdef DEBUG_KEYGEN |
