diff options
Diffstat (limited to 'src/lib/libcrypto/pkcs12/p12_p8e.c')
| -rw-r--r-- | src/lib/libcrypto/pkcs12/p12_p8e.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/lib/libcrypto/pkcs12/p12_p8e.c b/src/lib/libcrypto/pkcs12/p12_p8e.c index 3d71a02a1c..1ee6a32f6a 100644 --- a/src/lib/libcrypto/pkcs12/p12_p8e.c +++ b/src/lib/libcrypto/pkcs12/p12_p8e.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: p12_p8e.c,v 1.3 2014/06/12 15:49:30 deraadt Exp $ */ | 1 | /* $OpenBSD: p12_p8e.c,v 1.4 2014/07/08 09:24:53 jsing Exp $ */ |
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project 2001. | 3 | * project 2001. |
| 4 | */ | 4 | */ |
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -60,10 +60,10 @@ | |||
| 60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
| 61 | #include <openssl/pkcs12.h> | 61 | #include <openssl/pkcs12.h> |
| 62 | 62 | ||
| 63 | X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, | 63 | X509_SIG * |
| 64 | const char *pass, int passlen, | 64 | PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, const char *pass, |
| 65 | unsigned char *salt, int saltlen, int iter, | 65 | int passlen, unsigned char *salt, int saltlen, int iter, |
| 66 | PKCS8_PRIV_KEY_INFO *p8inf) | 66 | PKCS8_PRIV_KEY_INFO *p8inf) |
| 67 | { | 67 | { |
| 68 | X509_SIG *p8 = NULL; | 68 | X509_SIG *p8 = NULL; |
| 69 | X509_ALGOR *pbe; | 69 | X509_ALGOR *pbe; |
| @@ -73,25 +73,27 @@ X509_SIG *PKCS8_encrypt(int pbe_nid, const EVP_CIPHER *cipher, | |||
| 73 | goto err; | 73 | goto err; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | if(pbe_nid == -1) pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen); | 76 | if (pbe_nid == -1) |
| 77 | else pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen); | 77 | pbe = PKCS5_pbe2_set(cipher, iter, salt, saltlen); |
| 78 | if(!pbe) { | 78 | else |
| 79 | pbe = PKCS5_pbe_set(pbe_nid, iter, salt, saltlen); | ||
| 80 | if (!pbe) { | ||
| 79 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_ASN1_LIB); | 81 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, ERR_R_ASN1_LIB); |
| 80 | goto err; | 82 | goto err; |
| 81 | } | 83 | } |
| 82 | X509_ALGOR_free(p8->algor); | 84 | X509_ALGOR_free(p8->algor); |
| 83 | p8->algor = pbe; | 85 | p8->algor = pbe; |
| 84 | M_ASN1_OCTET_STRING_free(p8->digest); | 86 | M_ASN1_OCTET_STRING_free(p8->digest); |
| 85 | p8->digest = PKCS12_item_i2d_encrypt(pbe, ASN1_ITEM_rptr(PKCS8_PRIV_KEY_INFO), | 87 | p8->digest = PKCS12_item_i2d_encrypt(pbe, |
| 86 | pass, passlen, p8inf, 1); | 88 | ASN1_ITEM_rptr(PKCS8_PRIV_KEY_INFO), pass, passlen, p8inf, 1); |
| 87 | if(!p8->digest) { | 89 | if (!p8->digest) { |
| 88 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR); | 90 | PKCS12err(PKCS12_F_PKCS8_ENCRYPT, PKCS12_R_ENCRYPT_ERROR); |
| 89 | goto err; | 91 | goto err; |
| 90 | } | 92 | } |
| 91 | 93 | ||
| 92 | return p8; | 94 | return p8; |
| 93 | 95 | ||
| 94 | err: | 96 | err: |
| 95 | X509_SIG_free(p8); | 97 | X509_SIG_free(p8); |
| 96 | return NULL; | 98 | return NULL; |
| 97 | } | 99 | } |
