summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp
diff options
context:
space:
mode:
authorderaadt <>2017-05-02 03:59:45 +0000
committerderaadt <>2017-05-02 03:59:45 +0000
commit2b561cb0e87f2ee535e8c64907883cd275ad3fec (patch)
treebb9d050c5c2984047e6475e087694d6764f24157 /src/lib/libcrypto/evp
parent024e2580a5280d4df3724dab76ce52e14fe2060c (diff)
downloadopenbsd-2b561cb0e87f2ee535e8c64907883cd275ad3fec.tar.gz
openbsd-2b561cb0e87f2ee535e8c64907883cd275ad3fec.tar.bz2
openbsd-2b561cb0e87f2ee535e8c64907883cd275ad3fec.zip
use freezero() instead of memset/explicit_bzero + free. Substantially
reduces conditional logic (-218, +82). MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH cache alignment calculation bn/bn_exp.c wasn'tt quite right. Two other tricky bits with ASN1_STRING_FLAG_NDEF and BN_FLG_STATIC_DATA where the condition cannot be collapsed completely. Passes regress. ok beck
Diffstat (limited to 'src/lib/libcrypto/evp')
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c5
-rw-r--r--src/lib/libcrypto/evp/digest.c11
-rw-r--r--src/lib/libcrypto/evp/e_aes.c5
-rw-r--r--src/lib/libcrypto/evp/e_chacha20poly1305.c5
-rw-r--r--src/lib/libcrypto/evp/p_open.c6
5 files changed, 12 insertions, 20 deletions
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
index 1920c6d180..7c7cf9a8b3 100644
--- a/src/lib/libcrypto/evp/bio_enc.c
+++ b/src/lib/libcrypto/evp/bio_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_enc.c,v 1.19 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: bio_enc.c,v 1.20 2017/05/02 03:59:44 deraadt 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 *
@@ -135,8 +135,7 @@ enc_free(BIO *a)
135 return (0); 135 return (0);
136 b = (BIO_ENC_CTX *)a->ptr; 136 b = (BIO_ENC_CTX *)a->ptr;
137 EVP_CIPHER_CTX_cleanup(&(b->cipher)); 137 EVP_CIPHER_CTX_cleanup(&(b->cipher));
138 explicit_bzero(a->ptr, sizeof(BIO_ENC_CTX)); 138 freezero(a->ptr, sizeof(BIO_ENC_CTX));
139 free(a->ptr);
140 a->ptr = NULL; 139 a->ptr = NULL;
141 a->init = 0; 140 a->init = 0;
142 a->flags = 0; 141 a->flags = 0;
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c
index ee1f955959..7471c1e822 100644
--- a/src/lib/libcrypto/evp/digest.c
+++ b/src/lib/libcrypto/evp/digest.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: digest.c,v 1.27 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: digest.c,v 1.28 2017/05/02 03:59:44 deraadt 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 *
@@ -193,8 +193,7 @@ EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
193 if (ctx->digest != type) { 193 if (ctx->digest != type) {
194 if (ctx->digest && ctx->digest->ctx_size && ctx->md_data && 194 if (ctx->digest && ctx->digest->ctx_size && ctx->md_data &&
195 !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) { 195 !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) {
196 explicit_bzero(ctx->md_data, ctx->digest->ctx_size); 196 freezero(ctx->md_data, ctx->digest->ctx_size);
197 free(ctx->md_data);
198 ctx->md_data = NULL; 197 ctx->md_data = NULL;
199 } 198 }
200 ctx->digest = type; 199 ctx->digest = type;
@@ -360,10 +359,8 @@ EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
360 !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_CLEANED)) 359 !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_CLEANED))
361 ctx->digest->cleanup(ctx); 360 ctx->digest->cleanup(ctx);
362 if (ctx->digest && ctx->digest->ctx_size && ctx->md_data && 361 if (ctx->digest && ctx->digest->ctx_size && ctx->md_data &&
363 !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) { 362 !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE))
364 explicit_bzero(ctx->md_data, ctx->digest->ctx_size); 363 freezero(ctx->md_data, ctx->digest->ctx_size);
365 free(ctx->md_data);
366 }
367 EVP_PKEY_CTX_free(ctx->pctx); 364 EVP_PKEY_CTX_free(ctx->pctx);
368#ifndef OPENSSL_NO_ENGINE 365#ifndef OPENSSL_NO_ENGINE
369 if (ctx->engine) 366 if (ctx->engine)
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c
index 97cb5154a5..7c713db026 100644
--- a/src/lib/libcrypto/evp/e_aes.c
+++ b/src/lib/libcrypto/evp/e_aes.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_aes.c,v 1.33 2017/01/31 13:17:21 inoguchi Exp $ */ 1/* $OpenBSD: e_aes.c,v 1.34 2017/05/02 03:59:44 deraadt Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2001-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -1422,8 +1422,7 @@ aead_aes_gcm_cleanup(EVP_AEAD_CTX *ctx)
1422{ 1422{
1423 struct aead_aes_gcm_ctx *gcm_ctx = ctx->aead_state; 1423 struct aead_aes_gcm_ctx *gcm_ctx = ctx->aead_state;
1424 1424
1425 explicit_bzero(gcm_ctx, sizeof(*gcm_ctx)); 1425 freezero(gcm_ctx, sizeof(*gcm_ctx));
1426 free(gcm_ctx);
1427} 1426}
1428 1427
1429static int 1428static int
diff --git a/src/lib/libcrypto/evp/e_chacha20poly1305.c b/src/lib/libcrypto/evp/e_chacha20poly1305.c
index e135f9a104..051d5548b5 100644
--- a/src/lib/libcrypto/evp/e_chacha20poly1305.c
+++ b/src/lib/libcrypto/evp/e_chacha20poly1305.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_chacha20poly1305.c,v 1.15 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: e_chacha20poly1305.c,v 1.16 2017/05/02 03:59:44 deraadt Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2015 Reyk Floter <reyk@openbsd.org> 4 * Copyright (c) 2015 Reyk Floter <reyk@openbsd.org>
@@ -83,8 +83,7 @@ aead_chacha20_poly1305_cleanup(EVP_AEAD_CTX *ctx)
83{ 83{
84 struct aead_chacha20_poly1305_ctx *c20_ctx = ctx->aead_state; 84 struct aead_chacha20_poly1305_ctx *c20_ctx = ctx->aead_state;
85 85
86 explicit_bzero(c20_ctx->key, sizeof(c20_ctx->key)); 86 freezero(c20_ctx, sizeof(c20_ctx));
87 free(c20_ctx);
88} 87}
89 88
90static void 89static void
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c
index 1eb238dfde..57a46706b9 100644
--- a/src/lib/libcrypto/evp/p_open.c
+++ b/src/lib/libcrypto/evp/p_open.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_open.c,v 1.18 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: p_open.c,v 1.19 2017/05/02 03:59:44 deraadt 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 *
@@ -109,9 +109,7 @@ EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
109 ret = 1; 109 ret = 1;
110 110
111err: 111err:
112 if (key != NULL) 112 freezero(key, size);
113 explicit_bzero(key, size);
114 free(key);
115 return (ret); 113 return (ret);
116} 114}
117 115