summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/evp')
-rw-r--r--src/lib/libcrypto/evp/evp.h6
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c40
2 files changed, 44 insertions, 2 deletions
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
index 1684b13e49..c09e2c046a 100644
--- a/src/lib/libcrypto/evp/evp.h
+++ b/src/lib/libcrypto/evp/evp.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp.h,v 1.68 2018/08/24 20:22:15 tb Exp $ */ 1/* $OpenBSD: evp.h,v 1.69 2018/09/12 06:35:38 djm Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -496,6 +496,10 @@ int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx);
496int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx); 496int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx);
497int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx); 497int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx);
498int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx); 498int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx);
499int EVP_CIPHER_CTX_get_iv(const EVP_CIPHER_CTX *ctx,
500 unsigned char *iv, size_t len);
501int EVP_CIPHER_CTX_set_iv(EVP_CIPHER_CTX *ctx,
502 const unsigned char *iv, size_t len);
499int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in); 503int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in);
500void * EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx); 504void * EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx);
501void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data); 505void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data);
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c
index 3571755620..90107739e7 100644
--- a/src/lib/libcrypto/evp/evp_lib.c
+++ b/src/lib/libcrypto/evp/evp_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_lib.c,v 1.16 2018/08/24 19:36:52 tb Exp $ */ 1/* $OpenBSD: evp_lib.c,v 1.17 2018/09/12 06:35:38 djm Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -274,6 +274,44 @@ EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx)
274} 274}
275 275
276int 276int
277EVP_CIPHER_CTX_get_iv(const EVP_CIPHER_CTX *ctx, unsigned char *iv, size_t len)
278{
279 if (ctx == NULL || len != EVP_CIPHER_CTX_iv_length(ctx))
280 return 0;
281 if (len > EVP_MAX_IV_LENGTH)
282 return 0; /* sanity check; shouldn't happen */
283 /*
284 * Skip the memcpy entirely when the requested IV length is zero,
285 * since the iv pointer may be NULL or invalid.
286 */
287 if (len != 0) {
288 if (iv == NULL)
289 return 0;
290 memcpy(iv, ctx->iv, len);
291 }
292 return 1;
293}
294
295int
296EVP_CIPHER_CTX_set_iv(EVP_CIPHER_CTX *ctx, const unsigned char *iv, size_t len)
297{
298 if (ctx == NULL || len != EVP_CIPHER_CTX_iv_length(ctx))
299 return 0;
300 if (len > EVP_MAX_IV_LENGTH)
301 return 0; /* sanity check; shouldn't happen */
302 /*
303 * Skip the memcpy entirely when the requested IV length is zero,
304 * since the iv pointer may be NULL or invalid.
305 */
306 if (len != 0) {
307 if (iv == NULL)
308 return 0;
309 memcpy(ctx->iv, iv, len);
310 }
311 return 1;
312}
313
314int
277EVP_MD_block_size(const EVP_MD *md) 315EVP_MD_block_size(const EVP_MD *md)
278{ 316{
279 return md->block_size; 317 return md->block_size;