diff options
Diffstat (limited to 'src/lib/libcrypto/evp')
-rw-r--r-- | src/lib/libcrypto/evp/bio_b64.c | 1 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/bio_enc.c | 9 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/c_all.c | 5 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/digest.c | 17 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_aes.c | 1 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_idea.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_rc2.c | 1 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_rc4.c | 5 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/encode.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/evp_enc.c | 30 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/evp_key.c | 6 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/evp_lib.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/evp_pbe.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/p5_crpt.c | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/p5_crpt2.c | 3 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/p_open.c | 2 |
16 files changed, 66 insertions, 30 deletions
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c index f12eac1b55..6e550f6a43 100644 --- a/src/lib/libcrypto/evp/bio_b64.c +++ b/src/lib/libcrypto/evp/bio_b64.c | |||
@@ -165,6 +165,7 @@ static int b64_read(BIO *b, char *out, int outl) | |||
165 | { | 165 | { |
166 | i=ctx->buf_len-ctx->buf_off; | 166 | i=ctx->buf_len-ctx->buf_off; |
167 | if (i > outl) i=outl; | 167 | if (i > outl) i=outl; |
168 | OPENSSL_assert(ctx->buf_off+i < sizeof ctx->buf); | ||
168 | memcpy(out,&(ctx->buf[ctx->buf_off]),i); | 169 | memcpy(out,&(ctx->buf[ctx->buf_off]),i); |
169 | ret=i; | 170 | ret=i; |
170 | out+=i; | 171 | out+=i; |
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c index 64fb2353af..ab81851503 100644 --- a/src/lib/libcrypto/evp/bio_enc.c +++ b/src/lib/libcrypto/evp/bio_enc.c | |||
@@ -132,7 +132,7 @@ static int enc_free(BIO *a) | |||
132 | if (a == NULL) return(0); | 132 | if (a == NULL) return(0); |
133 | b=(BIO_ENC_CTX *)a->ptr; | 133 | b=(BIO_ENC_CTX *)a->ptr; |
134 | EVP_CIPHER_CTX_cleanup(&(b->cipher)); | 134 | EVP_CIPHER_CTX_cleanup(&(b->cipher)); |
135 | memset(a->ptr,0,sizeof(BIO_ENC_CTX)); | 135 | OPENSSL_cleanse(a->ptr,sizeof(BIO_ENC_CTX)); |
136 | OPENSSL_free(a->ptr); | 136 | OPENSSL_free(a->ptr); |
137 | a->ptr=NULL; | 137 | a->ptr=NULL; |
138 | a->init=0; | 138 | a->init=0; |
@@ -271,7 +271,7 @@ static int enc_write(BIO *b, const char *in, int inl) | |||
271 | if (i <= 0) | 271 | if (i <= 0) |
272 | { | 272 | { |
273 | BIO_copy_next_retry(b); | 273 | BIO_copy_next_retry(b); |
274 | return(i); | 274 | return (ret == inl) ? i : ret - inl; |
275 | } | 275 | } |
276 | n-=i; | 276 | n-=i; |
277 | ctx->buf_off+=i; | 277 | ctx->buf_off+=i; |
@@ -325,10 +325,7 @@ again: | |||
325 | { | 325 | { |
326 | i=enc_write(b,NULL,0); | 326 | i=enc_write(b,NULL,0); |
327 | if (i < 0) | 327 | if (i < 0) |
328 | { | 328 | return i; |
329 | ret=i; | ||
330 | break; | ||
331 | } | ||
332 | } | 329 | } |
333 | 330 | ||
334 | if (!ctx->finished) | 331 | if (!ctx->finished) |
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c index 2d3e57c4fa..1b31a14e37 100644 --- a/src/lib/libcrypto/evp/c_all.c +++ b/src/lib/libcrypto/evp/c_all.c | |||
@@ -73,4 +73,9 @@ void OPENSSL_add_all_algorithms_noconf(void) | |||
73 | { | 73 | { |
74 | OpenSSL_add_all_ciphers(); | 74 | OpenSSL_add_all_ciphers(); |
75 | OpenSSL_add_all_digests(); | 75 | OpenSSL_add_all_digests(); |
76 | #ifndef OPENSSL_NO_ENGINE | ||
77 | # if defined(__OpenBSD__) || defined(__FreeBSD__) | ||
78 | ENGINE_setup_bsd_cryptodev(); | ||
79 | # endif | ||
80 | #endif | ||
76 | } | 81 | } |
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c index a969ac69ed..b22eed4421 100644 --- a/src/lib/libcrypto/evp/digest.c +++ b/src/lib/libcrypto/evp/digest.c | |||
@@ -113,7 +113,9 @@ | |||
113 | #include "cryptlib.h" | 113 | #include "cryptlib.h" |
114 | #include <openssl/objects.h> | 114 | #include <openssl/objects.h> |
115 | #include <openssl/evp.h> | 115 | #include <openssl/evp.h> |
116 | #ifndef OPENSSL_NO_ENGINE | ||
116 | #include <openssl/engine.h> | 117 | #include <openssl/engine.h> |
118 | #endif | ||
117 | 119 | ||
118 | void EVP_MD_CTX_init(EVP_MD_CTX *ctx) | 120 | void EVP_MD_CTX_init(EVP_MD_CTX *ctx) |
119 | { | 121 | { |
@@ -138,6 +140,7 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type) | |||
138 | int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) | 140 | int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) |
139 | { | 141 | { |
140 | EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED); | 142 | EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED); |
143 | #ifndef OPENSSL_NO_ENGINE | ||
141 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts | 144 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts |
142 | * so this context may already have an ENGINE! Try to avoid releasing | 145 | * so this context may already have an ENGINE! Try to avoid releasing |
143 | * the previous handle, re-querying for an ENGINE, and having a | 146 | * the previous handle, re-querying for an ENGINE, and having a |
@@ -183,11 +186,13 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) | |||
183 | else | 186 | else |
184 | ctx->engine = NULL; | 187 | ctx->engine = NULL; |
185 | } | 188 | } |
186 | else if(!ctx->digest) | 189 | else |
190 | if(!ctx->digest) | ||
187 | { | 191 | { |
188 | EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_NO_DIGEST_SET); | 192 | EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_NO_DIGEST_SET); |
189 | return 0; | 193 | return 0; |
190 | } | 194 | } |
195 | #endif | ||
191 | if (ctx->digest != type) | 196 | if (ctx->digest != type) |
192 | { | 197 | { |
193 | if (ctx->digest && ctx->digest->ctx_size) | 198 | if (ctx->digest && ctx->digest->ctx_size) |
@@ -196,7 +201,9 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) | |||
196 | if (type->ctx_size) | 201 | if (type->ctx_size) |
197 | ctx->md_data=OPENSSL_malloc(type->ctx_size); | 202 | ctx->md_data=OPENSSL_malloc(type->ctx_size); |
198 | } | 203 | } |
204 | #ifndef OPENSSL_NO_ENGINE | ||
199 | skip_to_init: | 205 | skip_to_init: |
206 | #endif | ||
200 | return ctx->digest->init(ctx); | 207 | return ctx->digest->init(ctx); |
201 | } | 208 | } |
202 | 209 | ||
@@ -219,6 +226,8 @@ int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) | |||
219 | int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) | 226 | int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) |
220 | { | 227 | { |
221 | int ret; | 228 | int ret; |
229 | |||
230 | OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE); | ||
222 | ret=ctx->digest->final(ctx,md); | 231 | ret=ctx->digest->final(ctx,md); |
223 | if (size != NULL) | 232 | if (size != NULL) |
224 | *size=ctx->digest->md_size; | 233 | *size=ctx->digest->md_size; |
@@ -244,12 +253,14 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) | |||
244 | EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); | 253 | EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); |
245 | return 0; | 254 | return 0; |
246 | } | 255 | } |
256 | #ifndef OPENSSL_NO_ENGINE | ||
247 | /* Make sure it's safe to copy a digest context using an ENGINE */ | 257 | /* Make sure it's safe to copy a digest context using an ENGINE */ |
248 | if (in->engine && !ENGINE_init(in->engine)) | 258 | if (in->engine && !ENGINE_init(in->engine)) |
249 | { | 259 | { |
250 | EVPerr(EVP_F_EVP_MD_CTX_COPY,ERR_R_ENGINE_LIB); | 260 | EVPerr(EVP_F_EVP_MD_CTX_COPY,ERR_R_ENGINE_LIB); |
251 | return 0; | 261 | return 0; |
252 | } | 262 | } |
263 | #endif | ||
253 | 264 | ||
254 | EVP_MD_CTX_cleanup(out); | 265 | EVP_MD_CTX_cleanup(out); |
255 | memcpy(out,in,sizeof *out); | 266 | memcpy(out,in,sizeof *out); |
@@ -299,13 +310,15 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) | |||
299 | ctx->digest->cleanup(ctx); | 310 | ctx->digest->cleanup(ctx); |
300 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data) | 311 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data) |
301 | { | 312 | { |
302 | memset(ctx->md_data,0,ctx->digest->ctx_size); | 313 | OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size); |
303 | OPENSSL_free(ctx->md_data); | 314 | OPENSSL_free(ctx->md_data); |
304 | } | 315 | } |
316 | #ifndef OPENSSL_NO_ENGINE | ||
305 | if(ctx->engine) | 317 | if(ctx->engine) |
306 | /* The EVP_MD we used belongs to an ENGINE, release the | 318 | /* The EVP_MD we used belongs to an ENGINE, release the |
307 | * functional reference we held for this reason. */ | 319 | * functional reference we held for this reason. */ |
308 | ENGINE_finish(ctx->engine); | 320 | ENGINE_finish(ctx->engine); |
321 | #endif | ||
309 | memset(ctx,'\0',sizeof *ctx); | 322 | memset(ctx,'\0',sizeof *ctx); |
310 | 323 | ||
311 | return 1; | 324 | return 1; |
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c index c323fa2892..fe8bcda631 100644 --- a/src/lib/libcrypto/evp/e_aes.c +++ b/src/lib/libcrypto/evp/e_aes.c | |||
@@ -52,7 +52,6 @@ | |||
52 | #include <openssl/evp.h> | 52 | #include <openssl/evp.h> |
53 | #include <openssl/err.h> | 53 | #include <openssl/err.h> |
54 | #include <string.h> | 54 | #include <string.h> |
55 | #include <assert.h> | ||
56 | #include <openssl/aes.h> | 55 | #include <openssl/aes.h> |
57 | #include "evp_locl.h" | 56 | #include "evp_locl.h" |
58 | 57 | ||
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c index ed838d3e62..b9efa75ae7 100644 --- a/src/lib/libcrypto/evp/e_idea.c +++ b/src/lib/libcrypto/evp/e_idea.c | |||
@@ -109,7 +109,7 @@ static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | |||
109 | 109 | ||
110 | idea_set_encrypt_key(key,&tmp); | 110 | idea_set_encrypt_key(key,&tmp); |
111 | idea_set_decrypt_key(&tmp,ctx->cipher_data); | 111 | idea_set_decrypt_key(&tmp,ctx->cipher_data); |
112 | memset((unsigned char *)&tmp,0, | 112 | OPENSSL_cleanse((unsigned char *)&tmp, |
113 | sizeof(IDEA_KEY_SCHEDULE)); | 113 | sizeof(IDEA_KEY_SCHEDULE)); |
114 | } | 114 | } |
115 | return 1; | 115 | return 1; |
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c index 4685198e2e..d42cbfd17e 100644 --- a/src/lib/libcrypto/evp/e_rc2.c +++ b/src/lib/libcrypto/evp/e_rc2.c | |||
@@ -174,6 +174,7 @@ static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | |||
174 | if (type != NULL) | 174 | if (type != NULL) |
175 | { | 175 | { |
176 | l=EVP_CIPHER_CTX_iv_length(c); | 176 | l=EVP_CIPHER_CTX_iv_length(c); |
177 | OPENSSL_assert(l <= sizeof iv); | ||
177 | i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l); | 178 | i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l); |
178 | if (i != l) | 179 | if (i != l) |
179 | return(-1); | 180 | return(-1); |
diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c index 4064cc5fa0..d58f507837 100644 --- a/src/lib/libcrypto/evp/e_rc4.c +++ b/src/lib/libcrypto/evp/e_rc4.c | |||
@@ -69,8 +69,6 @@ | |||
69 | 69 | ||
70 | typedef struct | 70 | typedef struct |
71 | { | 71 | { |
72 | /* FIXME: what is the key for? */ | ||
73 | unsigned char key[EVP_RC4_KEY_SIZE]; | ||
74 | RC4_KEY ks; /* working key */ | 72 | RC4_KEY ks; /* working key */ |
75 | } EVP_RC4_KEY; | 73 | } EVP_RC4_KEY; |
76 | 74 | ||
@@ -121,9 +119,8 @@ const EVP_CIPHER *EVP_rc4_40(void) | |||
121 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 119 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
122 | const unsigned char *iv, int enc) | 120 | const unsigned char *iv, int enc) |
123 | { | 121 | { |
124 | memcpy(&data(ctx)->key[0],key,EVP_CIPHER_CTX_key_length(ctx)); | ||
125 | RC4_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx), | 122 | RC4_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx), |
126 | data(ctx)->key); | 123 | key); |
127 | return 1; | 124 | return 1; |
128 | } | 125 | } |
129 | 126 | ||
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c index 12c6379df1..08209357ce 100644 --- a/src/lib/libcrypto/evp/encode.c +++ b/src/lib/libcrypto/evp/encode.c | |||
@@ -136,6 +136,7 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, | |||
136 | 136 | ||
137 | *outl=0; | 137 | *outl=0; |
138 | if (inl == 0) return; | 138 | if (inl == 0) return; |
139 | OPENSSL_assert(ctx->length <= sizeof ctx->enc_data); | ||
139 | if ((ctx->num+inl) < ctx->length) | 140 | if ((ctx->num+inl) < ctx->length) |
140 | { | 141 | { |
141 | memcpy(&(ctx->enc_data[ctx->num]),in,inl); | 142 | memcpy(&(ctx->enc_data[ctx->num]),in,inl); |
@@ -258,6 +259,7 @@ int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, | |||
258 | /* only save the good data :-) */ | 259 | /* only save the good data :-) */ |
259 | if (!B64_NOT_BASE64(v)) | 260 | if (!B64_NOT_BASE64(v)) |
260 | { | 261 | { |
262 | OPENSSL_assert(n < sizeof ctx->enc_data); | ||
261 | d[n++]=tmp; | 263 | d[n++]=tmp; |
262 | ln++; | 264 | ln++; |
263 | } | 265 | } |
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c index 32a1c7a2e9..be0758a879 100644 --- a/src/lib/libcrypto/evp/evp_enc.c +++ b/src/lib/libcrypto/evp/evp_enc.c | |||
@@ -60,11 +60,11 @@ | |||
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include <openssl/evp.h> | 61 | #include <openssl/evp.h> |
62 | #include <openssl/err.h> | 62 | #include <openssl/err.h> |
63 | #ifndef OPENSSL_NO_ENGINE | ||
63 | #include <openssl/engine.h> | 64 | #include <openssl/engine.h> |
65 | #endif | ||
64 | #include "evp_locl.h" | 66 | #include "evp_locl.h" |
65 | 67 | ||
66 | #include <assert.h> | ||
67 | |||
68 | const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT; | 68 | const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT; |
69 | 69 | ||
70 | void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) | 70 | void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) |
@@ -93,6 +93,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
93 | enc = 1; | 93 | enc = 1; |
94 | ctx->encrypt = enc; | 94 | ctx->encrypt = enc; |
95 | } | 95 | } |
96 | #ifndef OPENSSL_NO_ENGINE | ||
96 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts | 97 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts |
97 | * so this context may already have an ENGINE! Try to avoid releasing | 98 | * so this context may already have an ENGINE! Try to avoid releasing |
98 | * the previous handle, re-querying for an ENGINE, and having a | 99 | * the previous handle, re-querying for an ENGINE, and having a |
@@ -100,6 +101,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
100 | if (ctx->engine && ctx->cipher && (!cipher || | 101 | if (ctx->engine && ctx->cipher && (!cipher || |
101 | (cipher && (cipher->nid == ctx->cipher->nid)))) | 102 | (cipher && (cipher->nid == ctx->cipher->nid)))) |
102 | goto skip_to_init; | 103 | goto skip_to_init; |
104 | #endif | ||
103 | if (cipher) | 105 | if (cipher) |
104 | { | 106 | { |
105 | /* Ensure a context left lying around from last time is cleared | 107 | /* Ensure a context left lying around from last time is cleared |
@@ -109,6 +111,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
109 | 111 | ||
110 | /* Restore encrypt field: it is zeroed by cleanup */ | 112 | /* Restore encrypt field: it is zeroed by cleanup */ |
111 | ctx->encrypt = enc; | 113 | ctx->encrypt = enc; |
114 | #ifndef OPENSSL_NO_ENGINE | ||
112 | if(impl) | 115 | if(impl) |
113 | { | 116 | { |
114 | if (!ENGINE_init(impl)) | 117 | if (!ENGINE_init(impl)) |
@@ -142,6 +145,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
142 | } | 145 | } |
143 | else | 146 | else |
144 | ctx->engine = NULL; | 147 | ctx->engine = NULL; |
148 | #endif | ||
145 | 149 | ||
146 | ctx->cipher=cipher; | 150 | ctx->cipher=cipher; |
147 | ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size); | 151 | ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size); |
@@ -161,11 +165,13 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
161 | EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_NO_CIPHER_SET); | 165 | EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_NO_CIPHER_SET); |
162 | return 0; | 166 | return 0; |
163 | } | 167 | } |
168 | #ifndef OPENSSL_NO_ENGINE | ||
164 | skip_to_init: | 169 | skip_to_init: |
170 | #endif | ||
165 | /* we assume block size is a power of 2 in *cryptUpdate */ | 171 | /* we assume block size is a power of 2 in *cryptUpdate */ |
166 | assert(ctx->cipher->block_size == 1 | 172 | OPENSSL_assert(ctx->cipher->block_size == 1 |
167 | || ctx->cipher->block_size == 8 | 173 | || ctx->cipher->block_size == 8 |
168 | || ctx->cipher->block_size == 16); | 174 | || ctx->cipher->block_size == 16); |
169 | 175 | ||
170 | if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) { | 176 | if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) { |
171 | switch(EVP_CIPHER_CTX_mode(ctx)) { | 177 | switch(EVP_CIPHER_CTX_mode(ctx)) { |
@@ -181,6 +187,7 @@ skip_to_init: | |||
181 | 187 | ||
182 | case EVP_CIPH_CBC_MODE: | 188 | case EVP_CIPH_CBC_MODE: |
183 | 189 | ||
190 | OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <= sizeof ctx->iv); | ||
184 | if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx)); | 191 | if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx)); |
185 | memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx)); | 192 | memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx)); |
186 | break; | 193 | break; |
@@ -237,7 +244,7 @@ int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *imp | |||
237 | int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, | 244 | int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, |
238 | const unsigned char *key, const unsigned char *iv) | 245 | const unsigned char *key, const unsigned char *iv) |
239 | { | 246 | { |
240 | return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, 0); | 247 | return EVP_CipherInit(ctx, cipher, key, iv, 0); |
241 | } | 248 | } |
242 | 249 | ||
243 | int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, | 250 | int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, |
@@ -251,6 +258,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
251 | { | 258 | { |
252 | int i,j,bl; | 259 | int i,j,bl; |
253 | 260 | ||
261 | OPENSSL_assert(inl > 0); | ||
254 | if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0) | 262 | if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0) |
255 | { | 263 | { |
256 | if(ctx->cipher->do_cipher(ctx,out,in,inl)) | 264 | if(ctx->cipher->do_cipher(ctx,out,in,inl)) |
@@ -266,6 +274,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
266 | } | 274 | } |
267 | i=ctx->buf_len; | 275 | i=ctx->buf_len; |
268 | bl=ctx->cipher->block_size; | 276 | bl=ctx->cipher->block_size; |
277 | OPENSSL_assert(bl <= sizeof ctx->buf); | ||
269 | if (i != 0) | 278 | if (i != 0) |
270 | { | 279 | { |
271 | if (i+inl < bl) | 280 | if (i+inl < bl) |
@@ -314,6 +323,7 @@ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | |||
314 | int i,n,b,bl,ret; | 323 | int i,n,b,bl,ret; |
315 | 324 | ||
316 | b=ctx->cipher->block_size; | 325 | b=ctx->cipher->block_size; |
326 | OPENSSL_assert(b <= sizeof ctx->buf); | ||
317 | if (b == 1) | 327 | if (b == 1) |
318 | { | 328 | { |
319 | *outl=0; | 329 | *outl=0; |
@@ -358,6 +368,7 @@ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
358 | return EVP_EncryptUpdate(ctx, out, outl, in, inl); | 368 | return EVP_EncryptUpdate(ctx, out, outl, in, inl); |
359 | 369 | ||
360 | b=ctx->cipher->block_size; | 370 | b=ctx->cipher->block_size; |
371 | OPENSSL_assert(b <= sizeof ctx->final); | ||
361 | 372 | ||
362 | if(ctx->final_used) | 373 | if(ctx->final_used) |
363 | { | 374 | { |
@@ -420,6 +431,7 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | |||
420 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH); | 431 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH); |
421 | return(0); | 432 | return(0); |
422 | } | 433 | } |
434 | OPENSSL_assert(b <= sizeof ctx->final); | ||
423 | n=ctx->final[b-1]; | 435 | n=ctx->final[b-1]; |
424 | if (n > b) | 436 | if (n > b) |
425 | { | 437 | { |
@@ -450,16 +462,18 @@ int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) | |||
450 | { | 462 | { |
451 | if(c->cipher->cleanup && !c->cipher->cleanup(c)) | 463 | if(c->cipher->cleanup && !c->cipher->cleanup(c)) |
452 | return 0; | 464 | return 0; |
453 | /* Zero cipher context data */ | 465 | /* Cleanse cipher context data */ |
454 | if (c->cipher_data) | 466 | if (c->cipher_data) |
455 | memset(c->cipher_data, 0, c->cipher->ctx_size); | 467 | OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size); |
456 | } | 468 | } |
457 | if (c->cipher_data) | 469 | if (c->cipher_data) |
458 | OPENSSL_free(c->cipher_data); | 470 | OPENSSL_free(c->cipher_data); |
471 | #ifndef OPENSSL_NO_ENGINE | ||
459 | if (c->engine) | 472 | if (c->engine) |
460 | /* The EVP_CIPHER we used belongs to an ENGINE, release the | 473 | /* The EVP_CIPHER we used belongs to an ENGINE, release the |
461 | * functional reference we held for this reason. */ | 474 | * functional reference we held for this reason. */ |
462 | ENGINE_finish(c->engine); | 475 | ENGINE_finish(c->engine); |
476 | #endif | ||
463 | memset(c,0,sizeof(EVP_CIPHER_CTX)); | 477 | memset(c,0,sizeof(EVP_CIPHER_CTX)); |
464 | return 1; | 478 | return 1; |
465 | } | 479 | } |
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c index 4271393069..5f387a94d3 100644 --- a/src/lib/libcrypto/evp/evp_key.c +++ b/src/lib/libcrypto/evp/evp_key.c | |||
@@ -103,7 +103,7 @@ int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify) | |||
103 | buff,0,(len>=BUFSIZ)?BUFSIZ-1:len,buf); | 103 | buff,0,(len>=BUFSIZ)?BUFSIZ-1:len,buf); |
104 | ret = UI_process(ui); | 104 | ret = UI_process(ui); |
105 | UI_free(ui); | 105 | UI_free(ui); |
106 | memset(buff,0,BUFSIZ); | 106 | OPENSSL_cleanse(buff,BUFSIZ); |
107 | return ret; | 107 | return ret; |
108 | } | 108 | } |
109 | 109 | ||
@@ -118,6 +118,8 @@ int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, | |||
118 | 118 | ||
119 | nkey=type->key_len; | 119 | nkey=type->key_len; |
120 | niv=type->iv_len; | 120 | niv=type->iv_len; |
121 | OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH); | ||
122 | OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH); | ||
121 | 123 | ||
122 | if (data == NULL) return(nkey); | 124 | if (data == NULL) return(nkey); |
123 | 125 | ||
@@ -166,7 +168,7 @@ int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, | |||
166 | if ((nkey == 0) && (niv == 0)) break; | 168 | if ((nkey == 0) && (niv == 0)) break; |
167 | } | 169 | } |
168 | EVP_MD_CTX_cleanup(&c); | 170 | EVP_MD_CTX_cleanup(&c); |
169 | memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE); | 171 | OPENSSL_cleanse(&(md_buf[0]),EVP_MAX_MD_SIZE); |
170 | return(type->key_len); | 172 | return(type->key_len); |
171 | } | 173 | } |
172 | 174 | ||
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c index a431945ef5..52a3b287be 100644 --- a/src/lib/libcrypto/evp/evp_lib.c +++ b/src/lib/libcrypto/evp/evp_lib.c | |||
@@ -90,6 +90,7 @@ int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | |||
90 | if (type != NULL) | 90 | if (type != NULL) |
91 | { | 91 | { |
92 | l=EVP_CIPHER_CTX_iv_length(c); | 92 | l=EVP_CIPHER_CTX_iv_length(c); |
93 | OPENSSL_assert(l <= sizeof c->iv); | ||
93 | i=ASN1_TYPE_get_octetstring(type,c->oiv,l); | 94 | i=ASN1_TYPE_get_octetstring(type,c->oiv,l); |
94 | if (i != l) | 95 | if (i != l) |
95 | return(-1); | 96 | return(-1); |
@@ -106,6 +107,7 @@ int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | |||
106 | if (type != NULL) | 107 | if (type != NULL) |
107 | { | 108 | { |
108 | j=EVP_CIPHER_CTX_iv_length(c); | 109 | j=EVP_CIPHER_CTX_iv_length(c); |
110 | OPENSSL_assert(j <= sizeof c->iv); | ||
109 | i=ASN1_TYPE_set_octetstring(type,c->oiv,j); | 111 | i=ASN1_TYPE_set_octetstring(type,c->oiv,j); |
110 | } | 112 | } |
111 | return(i); | 113 | return(i); |
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c index bcd4d29f85..0da88fdcff 100644 --- a/src/lib/libcrypto/evp/evp_pbe.c +++ b/src/lib/libcrypto/evp/evp_pbe.c | |||
@@ -88,7 +88,7 @@ int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen, | |||
88 | char obj_tmp[80]; | 88 | char obj_tmp[80]; |
89 | EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM); | 89 | EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM); |
90 | if (!pbe_obj) strcpy (obj_tmp, "NULL"); | 90 | if (!pbe_obj) strcpy (obj_tmp, "NULL"); |
91 | else i2t_ASN1_OBJECT(obj_tmp, 80, pbe_obj); | 91 | else i2t_ASN1_OBJECT(obj_tmp, sizeof obj_tmp, pbe_obj); |
92 | ERR_add_error_data(2, "TYPE=", obj_tmp); | 92 | ERR_add_error_data(2, "TYPE=", obj_tmp); |
93 | return 0; | 93 | return 0; |
94 | } | 94 | } |
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c index 27a8286489..a1874e83b2 100644 --- a/src/lib/libcrypto/evp/p5_crpt.c +++ b/src/lib/libcrypto/evp/p5_crpt.c | |||
@@ -140,12 +140,14 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen, | |||
140 | EVP_DigestFinal_ex (&ctx, md_tmp, NULL); | 140 | EVP_DigestFinal_ex (&ctx, md_tmp, NULL); |
141 | } | 141 | } |
142 | EVP_MD_CTX_cleanup(&ctx); | 142 | EVP_MD_CTX_cleanup(&ctx); |
143 | OPENSSL_assert(EVP_CIPHER_key_length(cipher) <= sizeof md_tmp); | ||
143 | memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher)); | 144 | memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher)); |
145 | OPENSSL_assert(EVP_CIPHER_iv_length(cipher) <= 16); | ||
144 | memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)), | 146 | memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)), |
145 | EVP_CIPHER_iv_length(cipher)); | 147 | EVP_CIPHER_iv_length(cipher)); |
146 | EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de); | 148 | EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de); |
147 | memset(md_tmp, 0, EVP_MAX_MD_SIZE); | 149 | OPENSSL_cleanse(md_tmp, EVP_MAX_MD_SIZE); |
148 | memset(key, 0, EVP_MAX_KEY_LENGTH); | 150 | OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH); |
149 | memset(iv, 0, EVP_MAX_IV_LENGTH); | 151 | OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH); |
150 | return 1; | 152 | return 1; |
151 | } | 153 | } |
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c index 7485d6a278..1f94e1ef88 100644 --- a/src/lib/libcrypto/evp/p5_crpt2.c +++ b/src/lib/libcrypto/evp/p5_crpt2.c | |||
@@ -190,6 +190,7 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | |||
190 | goto err; | 190 | goto err; |
191 | } | 191 | } |
192 | keylen = EVP_CIPHER_CTX_key_length(ctx); | 192 | keylen = EVP_CIPHER_CTX_key_length(ctx); |
193 | OPENSSL_assert(keylen <= sizeof key); | ||
193 | 194 | ||
194 | /* Now decode key derivation function */ | 195 | /* Now decode key derivation function */ |
195 | 196 | ||
@@ -230,7 +231,7 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | |||
230 | iter = ASN1_INTEGER_get(kdf->iter); | 231 | iter = ASN1_INTEGER_get(kdf->iter); |
231 | PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key); | 232 | PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key); |
232 | EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de); | 233 | EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de); |
233 | memset(key, 0, keylen); | 234 | OPENSSL_cleanse(key, keylen); |
234 | PBKDF2PARAM_free(kdf); | 235 | PBKDF2PARAM_free(kdf); |
235 | return 1; | 236 | return 1; |
236 | 237 | ||
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c index 6976f2a867..5a933d1cda 100644 --- a/src/lib/libcrypto/evp/p_open.c +++ b/src/lib/libcrypto/evp/p_open.c | |||
@@ -101,7 +101,7 @@ int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char *ek, | |||
101 | 101 | ||
102 | ret=1; | 102 | ret=1; |
103 | err: | 103 | err: |
104 | if (key != NULL) memset(key,0,size); | 104 | if (key != NULL) OPENSSL_cleanse(key,size); |
105 | OPENSSL_free(key); | 105 | OPENSSL_free(key); |
106 | return(ret); | 106 | return(ret); |
107 | } | 107 | } |