diff options
| author | markus <> | 2002-09-05 12:51:50 +0000 |
|---|---|---|
| committer | markus <> | 2002-09-05 12:51:50 +0000 |
| commit | 15b5d84f9da2ce4bfae8580e56e34a859f74ad71 (patch) | |
| tree | bf939e82d7fd73cc8a01cf6959002209972091bc /src/lib/libcrypto/asn1/p5_pbe.c | |
| parent | 027351f729b9e837200dae6e1520cda6577ab930 (diff) | |
| download | openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.gz openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.bz2 openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.zip | |
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/asn1/p5_pbe.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/p5_pbe.c | 52 |
1 files changed, 9 insertions, 43 deletions
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c index b831836e7b..891150638e 100644 --- a/src/lib/libcrypto/asn1/p5_pbe.c +++ b/src/lib/libcrypto/asn1/p5_pbe.c | |||
| @@ -58,53 +58,18 @@ | |||
| 58 | 58 | ||
| 59 | #include <stdio.h> | 59 | #include <stdio.h> |
| 60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
| 61 | #include <openssl/asn1_mac.h> | 61 | #include <openssl/asn1t.h> |
| 62 | #include <openssl/x509.h> | 62 | #include <openssl/x509.h> |
| 63 | #include <openssl/rand.h> | 63 | #include <openssl/rand.h> |
| 64 | 64 | ||
| 65 | /* PKCS#5 password based encryption structure */ | 65 | /* PKCS#5 password based encryption structure */ |
| 66 | 66 | ||
| 67 | int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp) | 67 | ASN1_SEQUENCE(PBEPARAM) = { |
| 68 | { | 68 | ASN1_SIMPLE(PBEPARAM, salt, ASN1_OCTET_STRING), |
| 69 | M_ASN1_I2D_vars(a); | 69 | ASN1_SIMPLE(PBEPARAM, iter, ASN1_INTEGER) |
| 70 | M_ASN1_I2D_len (a->salt, i2d_ASN1_OCTET_STRING); | 70 | } ASN1_SEQUENCE_END(PBEPARAM) |
| 71 | M_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER); | ||
| 72 | |||
| 73 | M_ASN1_I2D_seq_total (); | ||
| 74 | 71 | ||
| 75 | M_ASN1_I2D_put (a->salt, i2d_ASN1_OCTET_STRING); | 72 | IMPLEMENT_ASN1_FUNCTIONS(PBEPARAM) |
| 76 | M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER); | ||
| 77 | M_ASN1_I2D_finish(); | ||
| 78 | } | ||
| 79 | |||
| 80 | PBEPARAM *PBEPARAM_new(void) | ||
| 81 | { | ||
| 82 | PBEPARAM *ret=NULL; | ||
| 83 | ASN1_CTX c; | ||
| 84 | M_ASN1_New_Malloc(ret, PBEPARAM); | ||
| 85 | M_ASN1_New(ret->iter,ASN1_INTEGER_new); | ||
| 86 | M_ASN1_New(ret->salt,ASN1_OCTET_STRING_new); | ||
| 87 | return (ret); | ||
| 88 | M_ASN1_New_Error(ASN1_F_PBEPARAM_NEW); | ||
| 89 | } | ||
| 90 | |||
| 91 | PBEPARAM *d2i_PBEPARAM(PBEPARAM **a, unsigned char **pp, long length) | ||
| 92 | { | ||
| 93 | M_ASN1_D2I_vars(a,PBEPARAM *,PBEPARAM_new); | ||
| 94 | M_ASN1_D2I_Init(); | ||
| 95 | M_ASN1_D2I_start_sequence(); | ||
| 96 | M_ASN1_D2I_get (ret->salt, d2i_ASN1_OCTET_STRING); | ||
| 97 | M_ASN1_D2I_get (ret->iter, d2i_ASN1_INTEGER); | ||
| 98 | M_ASN1_D2I_Finish(a, PBEPARAM_free, ASN1_F_D2I_PBEPARAM); | ||
| 99 | } | ||
| 100 | |||
| 101 | void PBEPARAM_free (PBEPARAM *a) | ||
| 102 | { | ||
| 103 | if(a==NULL) return; | ||
| 104 | ASN1_OCTET_STRING_free(a->salt); | ||
| 105 | ASN1_INTEGER_free (a->iter); | ||
| 106 | Free ((char *)a); | ||
| 107 | } | ||
| 108 | 73 | ||
| 109 | /* Return an algorithm identifier for a PKCS#5 PBE algorithm */ | 74 | /* Return an algorithm identifier for a PKCS#5 PBE algorithm */ |
| 110 | 75 | ||
| @@ -123,13 +88,14 @@ X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, | |||
| 123 | if(iter <= 0) iter = PKCS5_DEFAULT_ITER; | 88 | if(iter <= 0) iter = PKCS5_DEFAULT_ITER; |
| 124 | ASN1_INTEGER_set (pbe->iter, iter); | 89 | ASN1_INTEGER_set (pbe->iter, iter); |
| 125 | if (!saltlen) saltlen = PKCS5_SALT_LEN; | 90 | if (!saltlen) saltlen = PKCS5_SALT_LEN; |
| 126 | if (!(pbe->salt->data = Malloc (saltlen))) { | 91 | if (!(pbe->salt->data = OPENSSL_malloc (saltlen))) { |
| 127 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); | 92 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); |
| 128 | return NULL; | 93 | return NULL; |
| 129 | } | 94 | } |
| 130 | pbe->salt->length = saltlen; | 95 | pbe->salt->length = saltlen; |
| 131 | if (salt) memcpy (pbe->salt->data, salt, saltlen); | 96 | if (salt) memcpy (pbe->salt->data, salt, saltlen); |
| 132 | else RAND_bytes (pbe->salt->data, saltlen); | 97 | else if (RAND_pseudo_bytes (pbe->salt->data, saltlen) < 0) |
| 98 | return NULL; | ||
| 133 | 99 | ||
| 134 | if (!(astype = ASN1_TYPE_new())) { | 100 | if (!(astype = ASN1_TYPE_new())) { |
| 135 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); | 101 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); |
