diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/p5_pbev2.c')
-rw-r--r-- | src/lib/libcrypto/asn1/p5_pbev2.c | 109 |
1 files changed, 14 insertions, 95 deletions
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c index 6a7b578c0e..43dfe09479 100644 --- a/src/lib/libcrypto/asn1/p5_pbev2.c +++ b/src/lib/libcrypto/asn1/p5_pbev2.c | |||
@@ -58,108 +58,27 @@ | |||
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 v2.0 password based encryption structures */ | 65 | /* PKCS#5 v2.0 password based encryption structures */ |
66 | 66 | ||
67 | int i2d_PBE2PARAM(PBE2PARAM *a, unsigned char **pp) | 67 | ASN1_SEQUENCE(PBE2PARAM) = { |
68 | { | 68 | ASN1_SIMPLE(PBE2PARAM, keyfunc, X509_ALGOR), |
69 | M_ASN1_I2D_vars(a); | 69 | ASN1_SIMPLE(PBE2PARAM, encryption, X509_ALGOR) |
70 | M_ASN1_I2D_len (a->keyfunc, i2d_X509_ALGOR); | 70 | } ASN1_SEQUENCE_END(PBE2PARAM) |
71 | M_ASN1_I2D_len (a->encryption, i2d_X509_ALGOR); | ||
72 | |||
73 | M_ASN1_I2D_seq_total (); | ||
74 | |||
75 | M_ASN1_I2D_put (a->keyfunc, i2d_X509_ALGOR); | ||
76 | M_ASN1_I2D_put (a->encryption, i2d_X509_ALGOR); | ||
77 | |||
78 | M_ASN1_I2D_finish(); | ||
79 | } | ||
80 | |||
81 | PBE2PARAM *PBE2PARAM_new(void) | ||
82 | { | ||
83 | PBE2PARAM *ret=NULL; | ||
84 | ASN1_CTX c; | ||
85 | M_ASN1_New_Malloc(ret, PBE2PARAM); | ||
86 | M_ASN1_New(ret->keyfunc,X509_ALGOR_new); | ||
87 | M_ASN1_New(ret->encryption,X509_ALGOR_new); | ||
88 | return (ret); | ||
89 | M_ASN1_New_Error(ASN1_F_PBE2PARAM_NEW); | ||
90 | } | ||
91 | |||
92 | PBE2PARAM *d2i_PBE2PARAM(PBE2PARAM **a, unsigned char **pp, long length) | ||
93 | { | ||
94 | M_ASN1_D2I_vars(a,PBE2PARAM *,PBE2PARAM_new); | ||
95 | M_ASN1_D2I_Init(); | ||
96 | M_ASN1_D2I_start_sequence(); | ||
97 | M_ASN1_D2I_get (ret->keyfunc, d2i_X509_ALGOR); | ||
98 | M_ASN1_D2I_get (ret->encryption, d2i_X509_ALGOR); | ||
99 | M_ASN1_D2I_Finish(a, PBE2PARAM_free, ASN1_F_D2I_PBE2PARAM); | ||
100 | } | ||
101 | |||
102 | void PBE2PARAM_free (PBE2PARAM *a) | ||
103 | { | ||
104 | if(a==NULL) return; | ||
105 | X509_ALGOR_free(a->keyfunc); | ||
106 | X509_ALGOR_free(a->encryption); | ||
107 | OPENSSL_free (a); | ||
108 | } | ||
109 | |||
110 | int i2d_PBKDF2PARAM(PBKDF2PARAM *a, unsigned char **pp) | ||
111 | { | ||
112 | M_ASN1_I2D_vars(a); | ||
113 | M_ASN1_I2D_len (a->salt, i2d_ASN1_TYPE); | ||
114 | M_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER); | ||
115 | M_ASN1_I2D_len (a->keylength, i2d_ASN1_INTEGER); | ||
116 | M_ASN1_I2D_len (a->prf, i2d_X509_ALGOR); | ||
117 | 71 | ||
118 | M_ASN1_I2D_seq_total (); | 72 | IMPLEMENT_ASN1_FUNCTIONS(PBE2PARAM) |
119 | 73 | ||
120 | M_ASN1_I2D_put (a->salt, i2d_ASN1_TYPE); | 74 | ASN1_SEQUENCE(PBKDF2PARAM) = { |
121 | M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER); | 75 | ASN1_SIMPLE(PBKDF2PARAM, salt, ASN1_ANY), |
122 | M_ASN1_I2D_put (a->keylength, i2d_ASN1_INTEGER); | 76 | ASN1_SIMPLE(PBKDF2PARAM, iter, ASN1_INTEGER), |
123 | M_ASN1_I2D_put (a->prf, i2d_X509_ALGOR); | 77 | ASN1_OPT(PBKDF2PARAM, keylength, ASN1_INTEGER), |
78 | ASN1_OPT(PBKDF2PARAM, prf, X509_ALGOR) | ||
79 | } ASN1_SEQUENCE_END(PBKDF2PARAM) | ||
124 | 80 | ||
125 | M_ASN1_I2D_finish(); | 81 | IMPLEMENT_ASN1_FUNCTIONS(PBKDF2PARAM) |
126 | } | ||
127 | |||
128 | PBKDF2PARAM *PBKDF2PARAM_new(void) | ||
129 | { | ||
130 | PBKDF2PARAM *ret=NULL; | ||
131 | ASN1_CTX c; | ||
132 | M_ASN1_New_Malloc(ret, PBKDF2PARAM); | ||
133 | M_ASN1_New(ret->salt, ASN1_TYPE_new); | ||
134 | M_ASN1_New(ret->iter, M_ASN1_INTEGER_new); | ||
135 | ret->keylength = NULL; | ||
136 | ret->prf = NULL; | ||
137 | return (ret); | ||
138 | M_ASN1_New_Error(ASN1_F_PBKDF2PARAM_NEW); | ||
139 | } | ||
140 | |||
141 | PBKDF2PARAM *d2i_PBKDF2PARAM(PBKDF2PARAM **a, unsigned char **pp, | ||
142 | long length) | ||
143 | { | ||
144 | M_ASN1_D2I_vars(a,PBKDF2PARAM *,PBKDF2PARAM_new); | ||
145 | M_ASN1_D2I_Init(); | ||
146 | M_ASN1_D2I_start_sequence(); | ||
147 | M_ASN1_D2I_get (ret->salt, d2i_ASN1_TYPE); | ||
148 | M_ASN1_D2I_get (ret->iter, d2i_ASN1_INTEGER); | ||
149 | M_ASN1_D2I_get_opt (ret->keylength, d2i_ASN1_INTEGER, V_ASN1_INTEGER); | ||
150 | M_ASN1_D2I_get_opt (ret->prf, d2i_X509_ALGOR, V_ASN1_SEQUENCE); | ||
151 | M_ASN1_D2I_Finish(a, PBKDF2PARAM_free, ASN1_F_D2I_PBKDF2PARAM); | ||
152 | } | ||
153 | |||
154 | void PBKDF2PARAM_free (PBKDF2PARAM *a) | ||
155 | { | ||
156 | if(a==NULL) return; | ||
157 | ASN1_TYPE_free(a->salt); | ||
158 | M_ASN1_INTEGER_free(a->iter); | ||
159 | M_ASN1_INTEGER_free(a->keylength); | ||
160 | X509_ALGOR_free(a->prf); | ||
161 | OPENSSL_free (a); | ||
162 | } | ||
163 | 82 | ||
164 | /* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm: | 83 | /* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm: |
165 | * yes I know this is horrible! | 84 | * yes I know this is horrible! |
@@ -198,7 +117,7 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, | |||
198 | goto err; | 117 | goto err; |
199 | 118 | ||
200 | /* Dummy cipherinit to just setup the IV */ | 119 | /* Dummy cipherinit to just setup the IV */ |
201 | EVP_CipherInit(&ctx, cipher, NULL, iv, 0); | 120 | EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, iv, 0); |
202 | if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) { | 121 | if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) { |
203 | ASN1err(ASN1_F_PKCS5_PBE2_SET, | 122 | ASN1err(ASN1_F_PKCS5_PBE2_SET, |
204 | ASN1_R_ERROR_SETTING_CIPHER_PARAMS); | 123 | ASN1_R_ERROR_SETTING_CIPHER_PARAMS); |