summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2015-09-10 15:56:26 +0000
committerjsing <>2015-09-10 15:56:26 +0000
commit1b9402de2dd1b97eca2be1996ed51c82f0663c92 (patch)
tree27c1922db8e3f519794fe6a13a1dfba3d4759090
parente1b77a3f14ebb06ead650e78b43ddd6546237b0a (diff)
downloadopenbsd-1b9402de2dd1b97eca2be1996ed51c82f0663c92.tar.gz
openbsd-1b9402de2dd1b97eca2be1996ed51c82f0663c92.tar.bz2
openbsd-1b9402de2dd1b97eca2be1996ed51c82f0663c92.zip
Correct spelling of OPENSSL_cleanse.
ok miod@
-rw-r--r--src/lib/libcrypto/aes/aes_wrap.c4
-rw-r--r--src/lib/libcrypto/asn1/a_sign.c7
-rw-r--r--src/lib/libcrypto/asn1/a_verify.c5
-rw-r--r--src/lib/libcrypto/asn1/n_pkey.c8
-rw-r--r--src/lib/libcrypto/asn1/p8_pkey.c5
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c4
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c8
-rw-r--r--src/lib/libcrypto/bn/bn_rand.c5
-rw-r--r--src/lib/libcrypto/cmac/cmac.c14
-rw-r--r--src/lib/libcrypto/cms/cms_asn1.c6
-rw-r--r--src/lib/libcrypto/cms/cms_enc.c8
-rw-r--r--src/lib/libcrypto/cms/cms_env.c10
-rw-r--r--src/lib/libcrypto/cms/cms_pwri.c4
-rw-r--r--src/lib/libcrypto/des/str2key.c6
-rw-r--r--src/lib/libcrypto/ec/ec_key.c4
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c8
-rw-r--r--src/lib/libcrypto/ec/ec_mult.c6
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp224.c4
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp256.c4
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp521.c4
-rw-r--r--src/lib/libcrypto/ecdh/ech_lib.c4
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_lib.c4
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c4
-rw-r--r--src/lib/libcrypto/evp/e_aes.c10
-rw-r--r--src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c4
-rw-r--r--src/lib/libcrypto/evp/e_chacha20poly1305.c4
-rw-r--r--src/lib/libcrypto/evp/e_idea.c5
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c4
-rw-r--r--src/lib/libcrypto/evp/evp_key.c6
-rw-r--r--src/lib/libcrypto/evp/p5_crpt.c8
-rw-r--r--src/lib/libcrypto/evp/p5_crpt2.c4
-rw-r--r--src/lib/libcrypto/evp/p_open.c5
-rw-r--r--src/lib/libcrypto/gost/gost2814789.c4
-rw-r--r--src/lib/libcrypto/gost/gostr341001_key.c6
-rw-r--r--src/lib/libcrypto/gost/gostr341194.c4
-rw-r--r--src/lib/libcrypto/gost/streebog.c6
-rw-r--r--src/lib/libcrypto/hmac/hm_ameth.c4
-rw-r--r--src/lib/libcrypto/hmac/hm_pmeth.c4
-rw-r--r--src/lib/libcrypto/md4/md4_one.c4
-rw-r--r--src/lib/libcrypto/md5/md5_one.c4
-rw-r--r--src/lib/libcrypto/modes/gcm128.c4
-rw-r--r--src/lib/libcrypto/pem/pem_info.c6
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c22
-rw-r--r--src/lib/libcrypto/pem/pem_pk8.c5
-rw-r--r--src/lib/libcrypto/pem/pem_pkey.c4
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c4
-rw-r--r--src/lib/libcrypto/pem/pvkfmt.c10
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crpt.c7
-rw-r--r--src/lib/libcrypto/pkcs12/p12_decr.c7
-rw-r--r--src/lib/libcrypto/pkcs12/p12_key.c4
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c16
-rw-r--r--src/lib/libcrypto/rand/randfile.c4
-rw-r--r--src/lib/libcrypto/ripemd/rmd_one.c4
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c11
-rw-r--r--src/lib/libcrypto/rsa/rsa_saos.c6
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c6
-rw-r--r--src/lib/libcrypto/sha/sha1_one.c4
-rw-r--r--src/lib/libcrypto/sha/sha256.c6
-rw-r--r--src/lib/libcrypto/sha/sha512.c6
-rw-r--r--src/lib/libcrypto/sha/sha_one.c4
-rw-r--r--src/lib/libcrypto/ui/ui_openssl.c4
-rw-r--r--src/lib/libcrypto/ui/ui_util.c4
-rw-r--r--src/lib/libssl/d1_clnt.c4
-rw-r--r--src/lib/libssl/d1_lib.c4
-rw-r--r--src/lib/libssl/s3_clnt.c4
-rw-r--r--src/lib/libssl/s3_lib.c4
-rw-r--r--src/lib/libssl/s3_srvr.c8
-rw-r--r--src/lib/libssl/src/crypto/aes/aes_wrap.c4
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_sign.c7
-rw-r--r--src/lib/libssl/src/crypto/asn1/a_verify.c5
-rw-r--r--src/lib/libssl/src/crypto/asn1/n_pkey.c8
-rw-r--r--src/lib/libssl/src/crypto/asn1/p8_pkey.c5
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_exp.c4
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_lib.c8
-rw-r--r--src/lib/libssl/src/crypto/bn/bn_rand.c5
-rw-r--r--src/lib/libssl/src/crypto/cmac/cmac.c14
-rw-r--r--src/lib/libssl/src/crypto/cms/cms_asn1.c6
-rw-r--r--src/lib/libssl/src/crypto/cms/cms_enc.c8
-rw-r--r--src/lib/libssl/src/crypto/cms/cms_env.c10
-rw-r--r--src/lib/libssl/src/crypto/cms/cms_pwri.c4
-rw-r--r--src/lib/libssl/src/crypto/des/str2key.c6
-rw-r--r--src/lib/libssl/src/crypto/ec/ec_key.c4
-rw-r--r--src/lib/libssl/src/crypto/ec/ec_lib.c8
-rw-r--r--src/lib/libssl/src/crypto/ec/ec_mult.c6
-rw-r--r--src/lib/libssl/src/crypto/ec/ecp_nistp224.c4
-rw-r--r--src/lib/libssl/src/crypto/ec/ecp_nistp256.c4
-rw-r--r--src/lib/libssl/src/crypto/ec/ecp_nistp521.c4
-rw-r--r--src/lib/libssl/src/crypto/ecdh/ech_lib.c4
-rw-r--r--src/lib/libssl/src/crypto/ecdsa/ecs_lib.c4
-rw-r--r--src/lib/libssl/src/crypto/evp/bio_enc.c4
-rw-r--r--src/lib/libssl/src/crypto/evp/e_aes.c10
-rw-r--r--src/lib/libssl/src/crypto/evp/e_aes_cbc_hmac_sha1.c4
-rw-r--r--src/lib/libssl/src/crypto/evp/e_chacha20poly1305.c4
-rw-r--r--src/lib/libssl/src/crypto/evp/e_idea.c5
-rw-r--r--src/lib/libssl/src/crypto/evp/evp_enc.c4
-rw-r--r--src/lib/libssl/src/crypto/evp/evp_key.c6
-rw-r--r--src/lib/libssl/src/crypto/evp/p5_crpt.c8
-rw-r--r--src/lib/libssl/src/crypto/evp/p5_crpt2.c4
-rw-r--r--src/lib/libssl/src/crypto/evp/p_open.c5
-rw-r--r--src/lib/libssl/src/crypto/gost/gost2814789.c4
-rw-r--r--src/lib/libssl/src/crypto/gost/gostr341001_key.c6
-rw-r--r--src/lib/libssl/src/crypto/gost/gostr341194.c4
-rw-r--r--src/lib/libssl/src/crypto/gost/streebog.c6
-rw-r--r--src/lib/libssl/src/crypto/hmac/hm_ameth.c4
-rw-r--r--src/lib/libssl/src/crypto/hmac/hm_pmeth.c4
-rw-r--r--src/lib/libssl/src/crypto/md4/md4_one.c4
-rw-r--r--src/lib/libssl/src/crypto/md5/md5_one.c4
-rw-r--r--src/lib/libssl/src/crypto/modes/gcm128.c4
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_info.c6
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_lib.c22
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_pk8.c5
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_pkey.c4
-rw-r--r--src/lib/libssl/src/crypto/pem/pem_seal.c4
-rw-r--r--src/lib/libssl/src/crypto/pem/pvkfmt.c10
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_crpt.c7
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_decr.c7
-rw-r--r--src/lib/libssl/src/crypto/pkcs12/p12_key.c4
-rw-r--r--src/lib/libssl/src/crypto/pkcs7/pk7_doit.c16
-rw-r--r--src/lib/libssl/src/crypto/rand/randfile.c4
-rw-r--r--src/lib/libssl/src/crypto/ripemd/rmd_one.c4
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_eay.c11
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_saos.c6
-rw-r--r--src/lib/libssl/src/crypto/rsa/rsa_sign.c6
-rw-r--r--src/lib/libssl/src/crypto/sha/sha1_one.c4
-rw-r--r--src/lib/libssl/src/crypto/sha/sha256.c6
-rw-r--r--src/lib/libssl/src/crypto/sha/sha512.c6
-rw-r--r--src/lib/libssl/src/crypto/sha/sha_one.c4
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_openssl.c4
-rw-r--r--src/lib/libssl/src/crypto/ui/ui_util.c4
-rw-r--r--src/lib/libssl/src/ssl/d1_clnt.c4
-rw-r--r--src/lib/libssl/src/ssl/d1_lib.c4
-rw-r--r--src/lib/libssl/src/ssl/s3_clnt.c4
-rw-r--r--src/lib/libssl/src/ssl/s3_enc.c6
-rw-r--r--src/lib/libssl/src/ssl/s3_lib.c4
-rw-r--r--src/lib/libssl/src/ssl/s3_srvr.c8
-rw-r--r--src/lib/libssl/src/ssl/ssl_sess.c8
-rw-r--r--src/lib/libssl/src/ssl/t1_enc.c6
-rw-r--r--src/lib/libssl/ssl_sess.c8
-rw-r--r--src/lib/libssl/t1_enc.c6
139 files changed, 423 insertions, 399 deletions
diff --git a/src/lib/libcrypto/aes/aes_wrap.c b/src/lib/libcrypto/aes/aes_wrap.c
index 4479473e6b..ac2f83a993 100644
--- a/src/lib/libcrypto/aes/aes_wrap.c
+++ b/src/lib/libcrypto/aes/aes_wrap.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: aes_wrap.c,v 1.9 2014/07/11 08:44:47 jsing Exp $ */ 1/* $OpenBSD: aes_wrap.c,v 1.10 2015/09/10 15:56:24 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -126,7 +126,7 @@ AES_unwrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out,
126 if (!iv) 126 if (!iv)
127 iv = default_iv; 127 iv = default_iv;
128 if (memcmp(A, iv, 8)) { 128 if (memcmp(A, iv, 8)) {
129 OPENSSL_cleanse(out, inlen); 129 explicit_bzero(out, inlen);
130 return 0; 130 return 0;
131 } 131 }
132 return inlen; 132 return inlen;
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c
index d9385312a7..195daa3b9f 100644
--- a/src/lib/libcrypto/asn1/a_sign.c
+++ b/src/lib/libcrypto/asn1/a_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_sign.c,v 1.20 2015/07/19 18:29:31 miod Exp $ */ 1/* $OpenBSD: a_sign.c,v 1.21 2015/09/10 15:56:24 jsing 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 *
@@ -112,6 +112,7 @@
112#include <sys/types.h> 112#include <sys/types.h>
113 113
114#include <stdio.h> 114#include <stdio.h>
115#include <string.h>
115#include <time.h> 116#include <time.h>
116 117
117#include <openssl/bn.h> 118#include <openssl/bn.h>
@@ -229,11 +230,11 @@ ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
229err: 230err:
230 EVP_MD_CTX_cleanup(ctx); 231 EVP_MD_CTX_cleanup(ctx);
231 if (buf_in != NULL) { 232 if (buf_in != NULL) {
232 OPENSSL_cleanse((char *)buf_in, inl); 233 explicit_bzero((char *)buf_in, inl);
233 free(buf_in); 234 free(buf_in);
234 } 235 }
235 if (buf_out != NULL) { 236 if (buf_out != NULL) {
236 OPENSSL_cleanse((char *)buf_out, outll); 237 explicit_bzero((char *)buf_out, outll);
237 free(buf_out); 238 free(buf_out);
238 } 239 }
239 return (outl); 240 return (outl);
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c
index 3fc79b78f6..12b76501e0 100644
--- a/src/lib/libcrypto/asn1/a_verify.c
+++ b/src/lib/libcrypto/asn1/a_verify.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_verify.c,v 1.21 2015/01/28 04:14:31 beck Exp $ */ 1/* $OpenBSD: a_verify.c,v 1.22 2015/09/10 15:56:24 jsing 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 *
@@ -59,6 +59,7 @@
59#include <sys/types.h> 59#include <sys/types.h>
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include <string.h>
62#include <time.h> 63#include <time.h>
63 64
64#include <openssl/bn.h> 65#include <openssl/bn.h>
@@ -152,7 +153,7 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
152 goto err; 153 goto err;
153 } 154 }
154 155
155 OPENSSL_cleanse(buf_in, (unsigned int)inl); 156 explicit_bzero(buf_in, (unsigned int)inl);
156 free(buf_in); 157 free(buf_in);
157 158
158 if (EVP_DigestVerifyFinal(&ctx, signature->data, 159 if (EVP_DigestVerifyFinal(&ctx, signature->data,
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c
index d3a7431356..491f988e92 100644
--- a/src/lib/libcrypto/asn1/n_pkey.c
+++ b/src/lib/libcrypto/asn1/n_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: n_pkey.c,v 1.26 2015/03/19 14:00:22 tedu Exp $ */ 1/* $OpenBSD: n_pkey.c,v 1.27 2015/09/10 15:56:24 jsing 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 *
@@ -277,7 +277,7 @@ i2d_RSA_NET(const RSA *a, unsigned char **pp,
277 i2d_NETSCAPE_PKEY(pkey, &zz); 277 i2d_NETSCAPE_PKEY(pkey, &zz);
278 278
279 /* Wipe the private key encoding */ 279 /* Wipe the private key encoding */
280 OPENSSL_cleanse(pkey->private_key->data, rsalen); 280 explicit_bzero(pkey->private_key->data, rsalen);
281 281
282 if (cb == NULL) 282 if (cb == NULL)
283 cb = EVP_read_pw_string; 283 cb = EVP_read_pw_string;
@@ -297,7 +297,7 @@ i2d_RSA_NET(const RSA *a, unsigned char **pp,
297 297
298 if (!EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, buf, i,1, key, NULL)) 298 if (!EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, buf, i,1, key, NULL))
299 goto err; 299 goto err;
300 OPENSSL_cleanse(buf, sizeof(buf)); 300 explicit_bzero(buf, sizeof(buf));
301 301
302 /* Encrypt private key in place */ 302 /* Encrypt private key in place */
303 zz = enckey->enckey->digest->data; 303 zz = enckey->enckey->digest->data;
@@ -394,7 +394,7 @@ d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
394 394
395 if (!EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, buf, i,1, key, NULL)) 395 if (!EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, buf, i,1, key, NULL))
396 goto err; 396 goto err;
397 OPENSSL_cleanse(buf, sizeof(buf)); 397 explicit_bzero(buf, sizeof(buf));
398 398
399 if (!EVP_DecryptInit_ex(&ctx, EVP_rc4(), NULL, key, NULL)) 399 if (!EVP_DecryptInit_ex(&ctx, EVP_rc4(), NULL, key, NULL))
400 goto err; 400 goto err;
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c
index 2f7a469673..71d579456a 100644
--- a/src/lib/libcrypto/asn1/p8_pkey.c
+++ b/src/lib/libcrypto/asn1/p8_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p8_pkey.c,v 1.16 2015/07/16 18:21:57 miod Exp $ */ 1/* $OpenBSD: p8_pkey.c,v 1.17 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/asn1t.h> 62#include <openssl/asn1t.h>
62#include <openssl/x509.h> 63#include <openssl/x509.h>
@@ -71,7 +72,7 @@ pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
71 if (key->pkey != NULL && 72 if (key->pkey != NULL &&
72 key->pkey->type == V_ASN1_OCTET_STRING && 73 key->pkey->type == V_ASN1_OCTET_STRING &&
73 key->pkey->value.octet_string != NULL) 74 key->pkey->value.octet_string != NULL)
74 OPENSSL_cleanse(key->pkey->value.octet_string->data, 75 explicit_bzero(key->pkey->value.octet_string->data,
75 key->pkey->value.octet_string->length); 76 key->pkey->value.octet_string->length);
76 } 77 }
77 return 1; 78 return 1;
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
index 4a28c2c605..c4ca36d136 100644
--- a/src/lib/libcrypto/bn/bn_exp.c
+++ b/src/lib/libcrypto/bn/bn_exp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_exp.c,v 1.22 2015/03/21 08:05:20 doug Exp $ */ 1/* $OpenBSD: bn_exp.c,v 1.23 2015/09/10 15:56:25 jsing 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 *
@@ -825,7 +825,7 @@ err:
825 if ((in_mont == NULL) && (mont != NULL)) 825 if ((in_mont == NULL) && (mont != NULL))
826 BN_MONT_CTX_free(mont); 826 BN_MONT_CTX_free(mont);
827 if (powerbuf != NULL) { 827 if (powerbuf != NULL) {
828 OPENSSL_cleanse(powerbuf, powerbufLen); 828 explicit_bzero(powerbuf, powerbufLen);
829 free(powerbufFree); 829 free(powerbufFree);
830 } 830 }
831 BN_CTX_end(ctx); 831 BN_CTX_end(ctx);
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
index d0cb49cd1e..7cc76c1e85 100644
--- a/src/lib/libcrypto/bn/bn_lib.c
+++ b/src/lib/libcrypto/bn/bn_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_lib.c,v 1.33 2014/07/12 16:03:36 miod Exp $ */ 1/* $OpenBSD: bn_lib.c,v 1.34 2015/09/10 15:56:25 jsing 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 *
@@ -221,11 +221,11 @@ BN_clear_free(BIGNUM *a)
221 return; 221 return;
222 bn_check_top(a); 222 bn_check_top(a);
223 if (a->d != NULL && !(BN_get_flags(a, BN_FLG_STATIC_DATA))) { 223 if (a->d != NULL && !(BN_get_flags(a, BN_FLG_STATIC_DATA))) {
224 OPENSSL_cleanse(a->d, a->dmax * sizeof(a->d[0])); 224 explicit_bzero(a->d, a->dmax * sizeof(a->d[0]));
225 free(a->d); 225 free(a->d);
226 } 226 }
227 i = BN_get_flags(a, BN_FLG_MALLOCED); 227 i = BN_get_flags(a, BN_FLG_MALLOCED);
228 OPENSSL_cleanse(a, sizeof(BIGNUM)); 228 explicit_bzero(a, sizeof(BIGNUM));
229 if (i) 229 if (i)
230 free(a); 230 free(a);
231} 231}
@@ -395,7 +395,7 @@ bn_expand2(BIGNUM *b, int words)
395 if (!a) 395 if (!a)
396 return NULL; 396 return NULL;
397 if (b->d) { 397 if (b->d) {
398 OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0])); 398 explicit_bzero(b->d, b->dmax * sizeof(b->d[0]));
399 free(b->d); 399 free(b->d);
400 } 400 }
401 b->d = a; 401 b->d = a;
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c
index ac5c5eb308..783f6c22f8 100644
--- a/src/lib/libcrypto/bn/bn_rand.c
+++ b/src/lib/libcrypto/bn/bn_rand.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_rand.c,v 1.17 2015/02/19 06:10:29 jsing Exp $ */ 1/* $OpenBSD: bn_rand.c,v 1.18 2015/09/10 15:56:25 jsing 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 *
@@ -111,6 +111,7 @@
111 111
112#include <stdio.h> 112#include <stdio.h>
113#include <stdlib.h> 113#include <stdlib.h>
114#include <string.h>
114#include <time.h> 115#include <time.h>
115 116
116#include <openssl/err.h> 117#include <openssl/err.h>
@@ -186,7 +187,7 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
186 187
187err: 188err:
188 if (buf != NULL) { 189 if (buf != NULL) {
189 OPENSSL_cleanse(buf, bytes); 190 explicit_bzero(buf, bytes);
190 free(buf); 191 free(buf);
191 } 192 }
192 bn_check_top(rnd); 193 bn_check_top(rnd);
diff --git a/src/lib/libcrypto/cmac/cmac.c b/src/lib/libcrypto/cmac/cmac.c
index 18635b942a..d01ae0f3ae 100644
--- a/src/lib/libcrypto/cmac/cmac.c
+++ b/src/lib/libcrypto/cmac/cmac.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cmac.c,v 1.9 2014/07/12 14:58:32 miod Exp $ */ 1/* $OpenBSD: cmac.c,v 1.10 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -107,10 +107,10 @@ void
107CMAC_CTX_cleanup(CMAC_CTX *ctx) 107CMAC_CTX_cleanup(CMAC_CTX *ctx)
108{ 108{
109 EVP_CIPHER_CTX_cleanup(&ctx->cctx); 109 EVP_CIPHER_CTX_cleanup(&ctx->cctx);
110 OPENSSL_cleanse(ctx->tbl, EVP_MAX_BLOCK_LENGTH); 110 explicit_bzero(ctx->tbl, EVP_MAX_BLOCK_LENGTH);
111 OPENSSL_cleanse(ctx->k1, EVP_MAX_BLOCK_LENGTH); 111 explicit_bzero(ctx->k1, EVP_MAX_BLOCK_LENGTH);
112 OPENSSL_cleanse(ctx->k2, EVP_MAX_BLOCK_LENGTH); 112 explicit_bzero(ctx->k2, EVP_MAX_BLOCK_LENGTH);
113 OPENSSL_cleanse(ctx->last_block, EVP_MAX_BLOCK_LENGTH); 113 explicit_bzero(ctx->last_block, EVP_MAX_BLOCK_LENGTH);
114 ctx->nlast_block = -1; 114 ctx->nlast_block = -1;
115} 115}
116 116
@@ -183,7 +183,7 @@ CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen,
183 return 0; 183 return 0;
184 make_kn(ctx->k1, ctx->tbl, bl); 184 make_kn(ctx->k1, ctx->tbl, bl);
185 make_kn(ctx->k2, ctx->k1, bl); 185 make_kn(ctx->k2, ctx->k1, bl);
186 OPENSSL_cleanse(ctx->tbl, bl); 186 explicit_bzero(ctx->tbl, bl);
187 /* Reset context again ready for first data block */ 187 /* Reset context again ready for first data block */
188 if (!EVP_EncryptInit_ex(&ctx->cctx, NULL, NULL, NULL, zero_iv)) 188 if (!EVP_EncryptInit_ex(&ctx->cctx, NULL, NULL, NULL, zero_iv))
189 return 0; 189 return 0;
@@ -260,7 +260,7 @@ CMAC_Final(CMAC_CTX *ctx, unsigned char *out, size_t *poutlen)
260 out[i] = ctx->last_block[i] ^ ctx->k2[i]; 260 out[i] = ctx->last_block[i] ^ ctx->k2[i];
261 } 261 }
262 if (!EVP_Cipher(&ctx->cctx, out, out, bl)) { 262 if (!EVP_Cipher(&ctx->cctx, out, out, bl)) {
263 OPENSSL_cleanse(out, bl); 263 explicit_bzero(out, bl);
264 return 0; 264 return 0;
265 } 265 }
266 return 1; 266 return 1;
diff --git a/src/lib/libcrypto/cms/cms_asn1.c b/src/lib/libcrypto/cms/cms_asn1.c
index 02a594575d..e450259832 100644
--- a/src/lib/libcrypto/cms/cms_asn1.c
+++ b/src/lib/libcrypto/cms/cms_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_asn1.c,v 1.6 2015/07/25 15:22:10 jsing Exp $ */ 1/* $OpenBSD: cms_asn1.c,v 1.7 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -888,13 +888,13 @@ cms_ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
888 } else if (ri->type == CMS_RECIPINFO_KEK) { 888 } else if (ri->type == CMS_RECIPINFO_KEK) {
889 CMS_KEKRecipientInfo *kekri = ri->d.kekri; 889 CMS_KEKRecipientInfo *kekri = ri->d.kekri;
890 if (kekri->key) { 890 if (kekri->key) {
891 OPENSSL_cleanse(kekri->key, kekri->keylen); 891 explicit_bzero(kekri->key, kekri->keylen);
892 free(kekri->key); 892 free(kekri->key);
893 } 893 }
894 } else if (ri->type == CMS_RECIPINFO_PASS) { 894 } else if (ri->type == CMS_RECIPINFO_PASS) {
895 CMS_PasswordRecipientInfo *pwri = ri->d.pwri; 895 CMS_PasswordRecipientInfo *pwri = ri->d.pwri;
896 if (pwri->pass) { 896 if (pwri->pass) {
897 OPENSSL_cleanse(pwri->pass, pwri->passlen); 897 explicit_bzero(pwri->pass, pwri->passlen);
898 free(pwri->pass); 898 free(pwri->pass);
899 } 899 }
900 } 900 }
diff --git a/src/lib/libcrypto/cms/cms_enc.c b/src/lib/libcrypto/cms/cms_enc.c
index f97e4d5f34..c967a18a3c 100644
--- a/src/lib/libcrypto/cms/cms_enc.c
+++ b/src/lib/libcrypto/cms/cms_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_enc.c,v 1.6 2014/10/22 13:02:04 jsing Exp $ */ 1/* $OpenBSD: cms_enc.c,v 1.7 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -164,7 +164,7 @@ cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
164 goto err; 164 goto err;
165 } else { 165 } else {
166 /* Use random key */ 166 /* Use random key */
167 OPENSSL_cleanse(ec->key, ec->keylen); 167 explicit_bzero(ec->key, ec->keylen);
168 free(ec->key); 168 free(ec->key);
169 ec->key = tkey; 169 ec->key = tkey;
170 ec->keylen = tkeylen; 170 ec->keylen = tkeylen;
@@ -197,12 +197,12 @@ cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
197 197
198err: 198err:
199 if (ec->key && !keep_key) { 199 if (ec->key && !keep_key) {
200 OPENSSL_cleanse(ec->key, ec->keylen); 200 explicit_bzero(ec->key, ec->keylen);
201 free(ec->key); 201 free(ec->key);
202 ec->key = NULL; 202 ec->key = NULL;
203 } 203 }
204 if (tkey) { 204 if (tkey) {
205 OPENSSL_cleanse(tkey, tkeylen); 205 explicit_bzero(tkey, tkeylen);
206 free(tkey); 206 free(tkey);
207 } 207 }
208 if (ok) 208 if (ok)
diff --git a/src/lib/libcrypto/cms/cms_env.c b/src/lib/libcrypto/cms/cms_env.c
index 63b24b6374..e483c4539f 100644
--- a/src/lib/libcrypto/cms/cms_env.c
+++ b/src/lib/libcrypto/cms/cms_env.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_env.c,v 1.8 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: cms_env.c,v 1.9 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -406,7 +406,7 @@ cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri)
406 ret = 1; 406 ret = 1;
407 407
408 if (ec->key) { 408 if (ec->key) {
409 OPENSSL_cleanse(ec->key, ec->keylen); 409 explicit_bzero(ec->key, ec->keylen);
410 free(ec->key); 410 free(ec->key);
411 } 411 }
412 412
@@ -654,7 +654,7 @@ cms_RecipientInfo_kekri_encrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri)
654err: 654err:
655 if (!r && wkey) 655 if (!r && wkey)
656 free(wkey); 656 free(wkey);
657 OPENSSL_cleanse(&actx, sizeof(actx)); 657 explicit_bzero(&actx, sizeof(actx));
658 658
659 return r; 659 return r;
660} 660}
@@ -727,7 +727,7 @@ cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri)
727err: 727err:
728 if (!r && ukey) 728 if (!r && ukey)
729 free(ukey); 729 free(ukey);
730 OPENSSL_cleanse(&actx, sizeof(actx)); 730 explicit_bzero(&actx, sizeof(actx));
731 731
732 return r; 732 return r;
733} 733}
@@ -806,7 +806,7 @@ cms_EnvelopedData_init_bio(CMS_ContentInfo *cms)
806err: 806err:
807 ec->cipher = NULL; 807 ec->cipher = NULL;
808 if (ec->key) { 808 if (ec->key) {
809 OPENSSL_cleanse(ec->key, ec->keylen); 809 explicit_bzero(ec->key, ec->keylen);
810 free(ec->key); 810 free(ec->key);
811 ec->key = NULL; 811 ec->key = NULL;
812 ec->keylen = 0; 812 ec->keylen = 0;
diff --git a/src/lib/libcrypto/cms/cms_pwri.c b/src/lib/libcrypto/cms/cms_pwri.c
index 11509e3c11..7055ba5d3b 100644
--- a/src/lib/libcrypto/cms/cms_pwri.c
+++ b/src/lib/libcrypto/cms/cms_pwri.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_pwri.c,v 1.9 2015/05/15 11:00:14 jsg Exp $ */ 1/* $OpenBSD: cms_pwri.c,v 1.10 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -262,7 +262,7 @@ kek_unwrap_key(unsigned char *out, size_t *outlen, const unsigned char *in,
262 rv = 1; 262 rv = 1;
263 263
264err: 264err:
265 OPENSSL_cleanse(tmp, inlen); 265 explicit_bzero(tmp, inlen);
266 free(tmp); 266 free(tmp);
267 return rv; 267 return rv;
268} 268}
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c
index 8999eb292a..ce17e2659b 100644
--- a/src/lib/libcrypto/des/str2key.c
+++ b/src/lib/libcrypto/des/str2key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: str2key.c,v 1.9 2014/10/28 07:35:58 jsg Exp $ */ 1/* $OpenBSD: str2key.c,v 1.10 2015/09/10 15:56:25 jsing 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 *
@@ -95,7 +95,7 @@ void DES_string_to_key(const char *str, DES_cblock *key)
95 DES_set_key_unchecked(key,&ks); 95 DES_set_key_unchecked(key,&ks);
96#endif 96#endif
97 DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key); 97 DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key);
98 OPENSSL_cleanse(&ks,sizeof(ks)); 98 explicit_bzero(&ks,sizeof(ks));
99 DES_set_odd_parity(key); 99 DES_set_odd_parity(key);
100 } 100 }
101 101
@@ -168,7 +168,7 @@ void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
168 DES_set_key_unchecked(key2,&ks); 168 DES_set_key_unchecked(key2,&ks);
169#endif 169#endif
170 DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2); 170 DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2);
171 OPENSSL_cleanse(&ks,sizeof(ks)); 171 explicit_bzero(&ks,sizeof(ks));
172 DES_set_odd_parity(key1); 172 DES_set_odd_parity(key1);
173 DES_set_odd_parity(key2); 173 DES_set_odd_parity(key2);
174 } 174 }
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c
index 45192c3231..fa962e4d0f 100644
--- a/src/lib/libcrypto/ec/ec_key.c
+++ b/src/lib/libcrypto/ec/ec_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_key.c,v 1.11 2015/02/09 15:49:22 jsing Exp $ */ 1/* $OpenBSD: ec_key.c,v 1.12 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -122,7 +122,7 @@ EC_KEY_free(EC_KEY * r)
122 122
123 EC_EX_DATA_free_all_data(&r->method_data); 123 EC_EX_DATA_free_all_data(&r->method_data);
124 124
125 OPENSSL_cleanse((void *) r, sizeof(EC_KEY)); 125 explicit_bzero((void *) r, sizeof(EC_KEY));
126 126
127 free(r); 127 free(r);
128} 128}
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
index a12a2ffbb6..c28ab18fc0 100644
--- a/src/lib/libcrypto/ec/ec_lib.c
+++ b/src/lib/libcrypto/ec/ec_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_lib.c,v 1.18 2015/05/20 04:33:35 miod Exp $ */ 1/* $OpenBSD: ec_lib.c,v 1.19 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -152,10 +152,10 @@ EC_GROUP_clear_free(EC_GROUP * group)
152 BN_clear_free(&group->cofactor); 152 BN_clear_free(&group->cofactor);
153 153
154 if (group->seed) { 154 if (group->seed) {
155 OPENSSL_cleanse(group->seed, group->seed_len); 155 explicit_bzero(group->seed, group->seed_len);
156 free(group->seed); 156 free(group->seed);
157 } 157 }
158 OPENSSL_cleanse(group, sizeof *group); 158 explicit_bzero(group, sizeof *group);
159 free(group); 159 free(group);
160} 160}
161 161
@@ -754,7 +754,7 @@ EC_POINT_clear_free(EC_POINT * point)
754 point->meth->point_clear_finish(point); 754 point->meth->point_clear_finish(point);
755 else if (point->meth->point_finish != 0) 755 else if (point->meth->point_finish != 0)
756 point->meth->point_finish(point); 756 point->meth->point_finish(point);
757 OPENSSL_cleanse(point, sizeof *point); 757 explicit_bzero(point, sizeof *point);
758 free(point); 758 free(point);
759} 759}
760 760
diff --git a/src/lib/libcrypto/ec/ec_mult.c b/src/lib/libcrypto/ec/ec_mult.c
index 68f55cfcb3..e428ac586b 100644
--- a/src/lib/libcrypto/ec/ec_mult.c
+++ b/src/lib/libcrypto/ec/ec_mult.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_mult.c,v 1.18 2015/02/15 08:44:35 miod Exp $ */ 1/* $OpenBSD: ec_mult.c,v 1.19 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project. 3 * Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -173,11 +173,11 @@ ec_pre_comp_clear_free(void *pre_)
173 173
174 for (p = pre->points; *p != NULL; p++) { 174 for (p = pre->points; *p != NULL; p++) {
175 EC_POINT_clear_free(*p); 175 EC_POINT_clear_free(*p);
176 OPENSSL_cleanse(p, sizeof *p); 176 explicit_bzero(p, sizeof *p);
177 } 177 }
178 free(pre->points); 178 free(pre->points);
179 } 179 }
180 OPENSSL_cleanse(pre, sizeof *pre); 180 explicit_bzero(pre, sizeof *pre);
181 free(pre); 181 free(pre);
182} 182}
183 183
diff --git a/src/lib/libcrypto/ec/ecp_nistp224.c b/src/lib/libcrypto/ec/ecp_nistp224.c
index d29113045a..0976f24a9f 100644
--- a/src/lib/libcrypto/ec/ecp_nistp224.c
+++ b/src/lib/libcrypto/ec/ecp_nistp224.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp224.c,v 1.16 2015/02/08 22:25:03 miod Exp $ */ 1/* $OpenBSD: ecp_nistp224.c,v 1.17 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Written by Emilia Kasper (Google) for the OpenSSL project. 3 * Written by Emilia Kasper (Google) for the OpenSSL project.
4 */ 4 */
@@ -1239,7 +1239,7 @@ nistp224_pre_comp_clear_free(void *pre_)
1239 if (i > 0) 1239 if (i > 0)
1240 return; 1240 return;
1241 1241
1242 OPENSSL_cleanse(pre, sizeof *pre); 1242 explicit_bzero(pre, sizeof *pre);
1243 free(pre); 1243 free(pre);
1244} 1244}
1245 1245
diff --git a/src/lib/libcrypto/ec/ecp_nistp256.c b/src/lib/libcrypto/ec/ecp_nistp256.c
index 23a2131980..be1d2a5402 100644
--- a/src/lib/libcrypto/ec/ecp_nistp256.c
+++ b/src/lib/libcrypto/ec/ecp_nistp256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp256.c,v 1.15 2015/02/08 22:25:03 miod Exp $ */ 1/* $OpenBSD: ecp_nistp256.c,v 1.16 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Written by Adam Langley (Google) for the OpenSSL project 3 * Written by Adam Langley (Google) for the OpenSSL project
4 */ 4 */
@@ -1788,7 +1788,7 @@ nistp256_pre_comp_clear_free(void *pre_)
1788 if (i > 0) 1788 if (i > 0)
1789 return; 1789 return;
1790 1790
1791 OPENSSL_cleanse(pre, sizeof *pre); 1791 explicit_bzero(pre, sizeof *pre);
1792 free(pre); 1792 free(pre);
1793} 1793}
1794 1794
diff --git a/src/lib/libcrypto/ec/ecp_nistp521.c b/src/lib/libcrypto/ec/ecp_nistp521.c
index 6382091cf9..cfa13b41f8 100644
--- a/src/lib/libcrypto/ec/ecp_nistp521.c
+++ b/src/lib/libcrypto/ec/ecp_nistp521.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp521.c,v 1.16 2015/02/08 22:25:03 miod Exp $ */ 1/* $OpenBSD: ecp_nistp521.c,v 1.17 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Written by Adam Langley (Google) for the OpenSSL project 3 * Written by Adam Langley (Google) for the OpenSSL project
4 */ 4 */
@@ -1679,7 +1679,7 @@ nistp521_pre_comp_clear_free(void *pre_)
1679 if (i > 0) 1679 if (i > 0)
1680 return; 1680 return;
1681 1681
1682 OPENSSL_cleanse(pre, sizeof(*pre)); 1682 explicit_bzero(pre, sizeof(*pre));
1683 free(pre); 1683 free(pre);
1684} 1684}
1685 1685
diff --git a/src/lib/libcrypto/ecdh/ech_lib.c b/src/lib/libcrypto/ecdh/ech_lib.c
index 43c4f8ce31..58dddf638f 100644
--- a/src/lib/libcrypto/ecdh/ech_lib.c
+++ b/src/lib/libcrypto/ecdh/ech_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ech_lib.c,v 1.8 2015/02/07 13:19:15 doug Exp $ */ 1/* $OpenBSD: ech_lib.c,v 1.9 2015/09/10 15:56:25 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -180,7 +180,7 @@ void ecdh_data_free(void *data)
180 180
181 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDH, r, &r->ex_data); 181 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDH, r, &r->ex_data);
182 182
183 OPENSSL_cleanse((void *)r, sizeof(ECDH_DATA)); 183 explicit_bzero((void *)r, sizeof(ECDH_DATA));
184 184
185 free(r); 185 free(r);
186 } 186 }
diff --git a/src/lib/libcrypto/ecdsa/ecs_lib.c b/src/lib/libcrypto/ecdsa/ecs_lib.c
index dba888cb48..1ba788b4f0 100644
--- a/src/lib/libcrypto/ecdsa/ecs_lib.c
+++ b/src/lib/libcrypto/ecdsa/ecs_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecs_lib.c,v 1.9 2015/02/08 13:35:07 jsing Exp $ */ 1/* $OpenBSD: ecs_lib.c,v 1.10 2015/09/10 15:56:25 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -170,7 +170,7 @@ ecdsa_data_free(void *data)
170#endif 170#endif
171 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDSA, r, &r->ex_data); 171 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDSA, r, &r->ex_data);
172 172
173 OPENSSL_cleanse((void *)r, sizeof(ECDSA_DATA)); 173 explicit_bzero((void *)r, sizeof(ECDSA_DATA));
174 174
175 free(r); 175 free(r);
176} 176}
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
index e367faa967..1920c6d180 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.18 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: bio_enc.c,v 1.19 2015/09/10 15:56:25 jsing 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,7 +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 OPENSSL_cleanse(a->ptr, sizeof(BIO_ENC_CTX)); 138 explicit_bzero(a->ptr, sizeof(BIO_ENC_CTX));
139 free(a->ptr); 139 free(a->ptr);
140 a->ptr = NULL; 140 a->ptr = NULL;
141 a->init = 0; 141 a->init = 0;
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c
index 0a9455a5d2..a6d48085c3 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.28 2015/06/20 12:01:14 jsing Exp $ */ 1/* $OpenBSD: e_aes.c,v 1.29 2015/09/10 15:56:25 jsing 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 *
@@ -690,7 +690,7 @@ aes_gcm_cleanup(EVP_CIPHER_CTX *c)
690 690
691 if (gctx->iv != c->iv) 691 if (gctx->iv != c->iv)
692 free(gctx->iv); 692 free(gctx->iv);
693 OPENSSL_cleanse(gctx, sizeof(*gctx)); 693 explicit_bzero(gctx, sizeof(*gctx));
694 return 1; 694 return 1;
695} 695}
696 696
@@ -972,7 +972,7 @@ aes_gcm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
972 972
973 /* If tag mismatch wipe buffer */ 973 /* If tag mismatch wipe buffer */
974 if (memcmp(ctx->buf, in + len, EVP_GCM_TLS_TAG_LEN)) { 974 if (memcmp(ctx->buf, in + len, EVP_GCM_TLS_TAG_LEN)) {
975 OPENSSL_cleanse(out, len); 975 explicit_bzero(out, len);
976 goto err; 976 goto err;
977 } 977 }
978 rv = len; 978 rv = len;
@@ -1339,7 +1339,7 @@ aes_ccm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
1339 } 1339 }
1340 } 1340 }
1341 if (rv == -1) 1341 if (rv == -1)
1342 OPENSSL_cleanse(out, len); 1342 explicit_bzero(out, len);
1343 cctx->iv_set = 0; 1343 cctx->iv_set = 0;
1344 cctx->tag_set = 0; 1344 cctx->tag_set = 0;
1345 cctx->len_set = 0; 1345 cctx->len_set = 0;
@@ -1417,7 +1417,7 @@ aead_aes_gcm_cleanup(EVP_AEAD_CTX *ctx)
1417{ 1417{
1418 struct aead_aes_gcm_ctx *gcm_ctx = ctx->aead_state; 1418 struct aead_aes_gcm_ctx *gcm_ctx = ctx->aead_state;
1419 1419
1420 OPENSSL_cleanse(gcm_ctx, sizeof(*gcm_ctx)); 1420 explicit_bzero(gcm_ctx, sizeof(*gcm_ctx));
1421 free(gcm_ctx); 1421 free(gcm_ctx);
1422} 1422}
1423 1423
diff --git a/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c b/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c
index 7c23face34..c76c2b1c52 100644
--- a/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c
+++ b/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_aes_cbc_hmac_sha1.c,v 1.8 2014/07/12 20:37:07 miod Exp $ */ 1/* $OpenBSD: e_aes_cbc_hmac_sha1.c,v 1.9 2015/09/10 15:56:25 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2011-2013 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2011-2013 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -502,7 +502,7 @@ aesni_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
502 SHA1_Init(&key->tail); 502 SHA1_Init(&key->tail);
503 SHA1_Update(&key->tail, hmac_key, sizeof(hmac_key)); 503 SHA1_Update(&key->tail, hmac_key, sizeof(hmac_key));
504 504
505 OPENSSL_cleanse(hmac_key, sizeof(hmac_key)); 505 explicit_bzero(hmac_key, sizeof(hmac_key));
506 506
507 return 1; 507 return 1;
508 } 508 }
diff --git a/src/lib/libcrypto/evp/e_chacha20poly1305.c b/src/lib/libcrypto/evp/e_chacha20poly1305.c
index c003b0ba7f..9deb40b72a 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.9 2015/06/20 12:01:14 jsing Exp $ */ 1/* $OpenBSD: e_chacha20poly1305.c,v 1.10 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -71,7 +71,7 @@ aead_chacha20_poly1305_cleanup(EVP_AEAD_CTX *ctx)
71{ 71{
72 struct aead_chacha20_poly1305_ctx *c20_ctx = ctx->aead_state; 72 struct aead_chacha20_poly1305_ctx *c20_ctx = ctx->aead_state;
73 73
74 OPENSSL_cleanse(c20_ctx->key, sizeof(c20_ctx->key)); 74 explicit_bzero(c20_ctx->key, sizeof(c20_ctx->key));
75 free(c20_ctx); 75 free(c20_ctx);
76} 76}
77 77
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c
index 3ba4dbcdb9..454ad4e672 100644
--- a/src/lib/libcrypto/evp/e_idea.c
+++ b/src/lib/libcrypto/evp/e_idea.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_idea.c,v 1.9 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: e_idea.c,v 1.10 2015/09/10 15:56:25 jsing 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 *
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/opensslconf.h> 62#include <openssl/opensslconf.h>
62 63
@@ -115,7 +116,7 @@ idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
115 116
116 idea_set_encrypt_key(key, &tmp); 117 idea_set_encrypt_key(key, &tmp);
117 idea_set_decrypt_key(&tmp, ctx->cipher_data); 118 idea_set_decrypt_key(&tmp, ctx->cipher_data);
118 OPENSSL_cleanse((unsigned char *)&tmp, 119 explicit_bzero((unsigned char *)&tmp,
119 sizeof(IDEA_KEY_SCHEDULE)); 120 sizeof(IDEA_KEY_SCHEDULE));
120 } 121 }
121 return 1; 122 return 1;
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
index 42ccfceec9..99bf59e05f 100644
--- a/src/lib/libcrypto/evp/evp_enc.c
+++ b/src/lib/libcrypto/evp/evp_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_enc.c,v 1.26 2015/02/10 09:52:35 miod Exp $ */ 1/* $OpenBSD: evp_enc.c,v 1.27 2015/09/10 15:56:25 jsing 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 *
@@ -562,7 +562,7 @@ EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
562 return 0; 562 return 0;
563 /* Cleanse cipher context data */ 563 /* Cleanse cipher context data */
564 if (c->cipher_data) 564 if (c->cipher_data)
565 OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size); 565 explicit_bzero(c->cipher_data, c->cipher->ctx_size);
566 } 566 }
567 free(c->cipher_data); 567 free(c->cipher_data);
568#ifndef OPENSSL_NO_ENGINE 568#ifndef OPENSSL_NO_ENGINE
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c
index 0678536ccb..2c76743e42 100644
--- a/src/lib/libcrypto/evp/evp_key.c
+++ b/src/lib/libcrypto/evp/evp_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_key.c,v 1.22 2015/02/10 09:55:39 miod Exp $ */ 1/* $OpenBSD: evp_key.c,v 1.23 2015/09/10 15:56:25 jsing 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 *
@@ -116,7 +116,7 @@ EVP_read_pw_string_min(char *buf, int min, int len, const char *prompt,
116 } 116 }
117 ret = UI_process(ui); 117 ret = UI_process(ui);
118 UI_free(ui); 118 UI_free(ui);
119 OPENSSL_cleanse(buff, BUFSIZ); 119 explicit_bzero(buff, BUFSIZ);
120 return ret; 120 return ret;
121} 121}
122 122
@@ -201,6 +201,6 @@ EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
201 201
202err: 202err:
203 EVP_MD_CTX_cleanup(&c); 203 EVP_MD_CTX_cleanup(&c);
204 OPENSSL_cleanse(md_buf, sizeof md_buf); 204 explicit_bzero(md_buf, sizeof md_buf);
205 return rv; 205 return rv;
206} 206}
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c
index 112a69114c..626910fd7a 100644
--- a/src/lib/libcrypto/evp/p5_crpt.c
+++ b/src/lib/libcrypto/evp/p5_crpt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p5_crpt.c,v 1.15 2015/02/10 09:52:35 miod Exp $ */ 1/* $OpenBSD: p5_crpt.c,v 1.16 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -147,9 +147,9 @@ PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
147 EVP_CIPHER_iv_length(cipher)); 147 EVP_CIPHER_iv_length(cipher));
148 if (!EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de)) 148 if (!EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de))
149 goto err; 149 goto err;
150 OPENSSL_cleanse(md_tmp, EVP_MAX_MD_SIZE); 150 explicit_bzero(md_tmp, EVP_MAX_MD_SIZE);
151 OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH); 151 explicit_bzero(key, EVP_MAX_KEY_LENGTH);
152 OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH); 152 explicit_bzero(iv, EVP_MAX_IV_LENGTH);
153 rv = 1; 153 rv = 1;
154err: 154err:
155 EVP_MD_CTX_cleanup(&ctx); 155 EVP_MD_CTX_cleanup(&ctx);
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c
index afafb9551f..632c2c76ce 100644
--- a/src/lib/libcrypto/evp/p5_crpt2.c
+++ b/src/lib/libcrypto/evp/p5_crpt2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p5_crpt2.c,v 1.20 2015/02/14 15:49:51 miod Exp $ */ 1/* $OpenBSD: p5_crpt2.c,v 1.21 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -300,7 +300,7 @@ PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
300 rv = EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de); 300 rv = EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de);
301 301
302err: 302err:
303 OPENSSL_cleanse(key, keylen); 303 explicit_bzero(key, keylen);
304 PBKDF2PARAM_free(kdf); 304 PBKDF2PARAM_free(kdf);
305 return rv; 305 return rv;
306} 306}
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c
index aca83e74f6..002a6dea70 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.16 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: p_open.c,v 1.17 2015/09/10 15:56:25 jsing 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 *
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/opensslconf.h> 62#include <openssl/opensslconf.h>
62 63
@@ -109,7 +110,7 @@ EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
109 110
110err: 111err:
111 if (key != NULL) 112 if (key != NULL)
112 OPENSSL_cleanse(key, size); 113 explicit_bzero(key, size);
113 free(key); 114 free(key);
114 return (ret); 115 return (ret);
115} 116}
diff --git a/src/lib/libcrypto/gost/gost2814789.c b/src/lib/libcrypto/gost/gost2814789.c
index b1bef9eae3..e285413ed4 100644
--- a/src/lib/libcrypto/gost/gost2814789.c
+++ b/src/lib/libcrypto/gost/gost2814789.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gost2814789.c,v 1.4 2015/02/10 09:46:30 miod Exp $ */ 1/* $OpenBSD: gost2814789.c,v 1.5 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -464,7 +464,7 @@ GOST2814789IMIT(const unsigned char *d, size_t n, unsigned char *md, int nid,
464 Gost2814789_set_key(&c.cipher, key, 256); 464 Gost2814789_set_key(&c.cipher, key, 256);
465 GOST2814789IMIT_Update(&c, d, n); 465 GOST2814789IMIT_Update(&c, d, n);
466 GOST2814789IMIT_Final(md, &c); 466 GOST2814789IMIT_Final(md, &c);
467 OPENSSL_cleanse(&c, sizeof(c)); 467 explicit_bzero(&c, sizeof(c));
468 return (md); 468 return (md);
469} 469}
470 470
diff --git a/src/lib/libcrypto/gost/gostr341001_key.c b/src/lib/libcrypto/gost/gostr341001_key.c
index dbe360620a..894a189e3b 100644
--- a/src/lib/libcrypto/gost/gostr341001_key.c
+++ b/src/lib/libcrypto/gost/gostr341001_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gostr341001_key.c,v 1.5 2015/02/14 06:40:04 jsing Exp $ */ 1/* $OpenBSD: gostr341001_key.c,v 1.6 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -49,6 +49,8 @@
49 * ==================================================================== 49 * ====================================================================
50 */ 50 */
51 51
52#include <string.h>
53
52#include <openssl/opensslconf.h> 54#include <openssl/opensslconf.h>
53 55
54#ifndef OPENSSL_NO_GOST 56#ifndef OPENSSL_NO_GOST
@@ -103,7 +105,7 @@ GOST_KEY_free(GOST_KEY *r)
103 EC_POINT_free(r->pub_key); 105 EC_POINT_free(r->pub_key);
104 BN_clear_free(r->priv_key); 106 BN_clear_free(r->priv_key);
105 107
106 OPENSSL_cleanse((void *)r, sizeof(GOST_KEY)); 108 explicit_bzero((void *)r, sizeof(GOST_KEY));
107 free(r); 109 free(r);
108} 110}
109 111
diff --git a/src/lib/libcrypto/gost/gostr341194.c b/src/lib/libcrypto/gost/gostr341194.c
index 32c166aefa..2a462185aa 100644
--- a/src/lib/libcrypto/gost/gostr341194.c
+++ b/src/lib/libcrypto/gost/gostr341194.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gostr341194.c,v 1.4 2015/07/15 17:13:17 beck Exp $ */ 1/* $OpenBSD: gostr341194.c,v 1.5 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -267,7 +267,7 @@ GOSTR341194(const unsigned char *d, size_t n, unsigned char *md, int nid)
267 return 0; 267 return 0;
268 GOSTR341194_Update(&c, d, n); 268 GOSTR341194_Update(&c, d, n);
269 GOSTR341194_Final(md, &c); 269 GOSTR341194_Final(md, &c);
270 OPENSSL_cleanse(&c, sizeof(c)); 270 explicit_bzero(&c, sizeof(c));
271 return (md); 271 return (md);
272} 272}
273#endif 273#endif
diff --git a/src/lib/libcrypto/gost/streebog.c b/src/lib/libcrypto/gost/streebog.c
index 8060161d11..902472bd9e 100644
--- a/src/lib/libcrypto/gost/streebog.c
+++ b/src/lib/libcrypto/gost/streebog.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: streebog.c,v 1.4 2014/12/07 16:33:51 jsing Exp $ */ 1/* $OpenBSD: streebog.c,v 1.5 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -1455,7 +1455,7 @@ STREEBOG256(const unsigned char *d, size_t n, unsigned char *md)
1455 STREEBOG256_Init(&c); 1455 STREEBOG256_Init(&c);
1456 STREEBOG256_Update(&c, d, n); 1456 STREEBOG256_Update(&c, d, n);
1457 STREEBOG256_Final(md, &c); 1457 STREEBOG256_Final(md, &c);
1458 OPENSSL_cleanse(&c, sizeof(c)); 1458 explicit_bzero(&c, sizeof(c));
1459 return (md); 1459 return (md);
1460} 1460}
1461 1461
@@ -1470,7 +1470,7 @@ STREEBOG512(const unsigned char *d, size_t n, unsigned char *md)
1470 STREEBOG512_Init(&c); 1470 STREEBOG512_Init(&c);
1471 STREEBOG512_Update(&c, d, n); 1471 STREEBOG512_Update(&c, d, n);
1472 STREEBOG512_Final(md, &c); 1472 STREEBOG512_Final(md, &c);
1473 OPENSSL_cleanse(&c, sizeof(c)); 1473 explicit_bzero(&c, sizeof(c));
1474 return (md); 1474 return (md);
1475} 1475}
1476 1476
diff --git a/src/lib/libcrypto/hmac/hm_ameth.c b/src/lib/libcrypto/hmac/hm_ameth.c
index da3471c4fd..cfa0239705 100644
--- a/src/lib/libcrypto/hmac/hm_ameth.c
+++ b/src/lib/libcrypto/hmac/hm_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hm_ameth.c,v 1.9 2015/07/20 15:45:29 miod Exp $ */ 1/* $OpenBSD: hm_ameth.c,v 1.10 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2007. 3 * project 2007.
4 */ 4 */
@@ -83,7 +83,7 @@ hmac_key_free(EVP_PKEY *pkey)
83 83
84 if (os) { 84 if (os) {
85 if (os->data) 85 if (os->data)
86 OPENSSL_cleanse(os->data, os->length); 86 explicit_bzero(os->data, os->length);
87 ASN1_OCTET_STRING_free(os); 87 ASN1_OCTET_STRING_free(os);
88 } 88 }
89} 89}
diff --git a/src/lib/libcrypto/hmac/hm_pmeth.c b/src/lib/libcrypto/hmac/hm_pmeth.c
index 255f4ece8b..c5ac6c00c0 100644
--- a/src/lib/libcrypto/hmac/hm_pmeth.c
+++ b/src/lib/libcrypto/hmac/hm_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hm_pmeth.c,v 1.8 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: hm_pmeth.c,v 1.9 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2007. 3 * project 2007.
4 */ 4 */
@@ -124,7 +124,7 @@ pkey_hmac_cleanup(EVP_PKEY_CTX *ctx)
124 HMAC_CTX_cleanup(&hctx->ctx); 124 HMAC_CTX_cleanup(&hctx->ctx);
125 if (hctx->ktmp.data) { 125 if (hctx->ktmp.data) {
126 if (hctx->ktmp.length) 126 if (hctx->ktmp.length)
127 OPENSSL_cleanse(hctx->ktmp.data, hctx->ktmp.length); 127 explicit_bzero(hctx->ktmp.data, hctx->ktmp.length);
128 free(hctx->ktmp.data); 128 free(hctx->ktmp.data);
129 hctx->ktmp.data = NULL; 129 hctx->ktmp.data = NULL;
130 } 130 }
diff --git a/src/lib/libcrypto/md4/md4_one.c b/src/lib/libcrypto/md4/md4_one.c
index 144f131914..9577d6577b 100644
--- a/src/lib/libcrypto/md4/md4_one.c
+++ b/src/lib/libcrypto/md4/md4_one.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: md4_one.c,v 1.7 2015/09/10 15:03:58 jsing Exp $ */ 1/* $OpenBSD: md4_one.c,v 1.8 2015/09/10 15:56:25 jsing 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 *
@@ -71,7 +71,7 @@ unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md)
71 return NULL; 71 return NULL;
72 MD4_Update(&c,d,n); 72 MD4_Update(&c,d,n);
73 MD4_Final(md,&c); 73 MD4_Final(md,&c);
74 OPENSSL_cleanse(&c,sizeof(c)); 74 explicit_bzero(&c,sizeof(c));
75 return(md); 75 return(md);
76 } 76 }
77 77
diff --git a/src/lib/libcrypto/md5/md5_one.c b/src/lib/libcrypto/md5/md5_one.c
index f4cc56adb2..3fb05de30c 100644
--- a/src/lib/libcrypto/md5/md5_one.c
+++ b/src/lib/libcrypto/md5/md5_one.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: md5_one.c,v 1.9 2015/09/10 15:03:59 jsing Exp $ */ 1/* $OpenBSD: md5_one.c,v 1.10 2015/09/10 15:56:25 jsing 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 *
@@ -71,7 +71,7 @@ unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md)
71 return NULL; 71 return NULL;
72 MD5_Update(&c,d,n); 72 MD5_Update(&c,d,n);
73 MD5_Final(md,&c); 73 MD5_Final(md,&c);
74 OPENSSL_cleanse(&c,sizeof(c)); 74 explicit_bzero(&c,sizeof(c));
75 return(md); 75 return(md);
76 } 76 }
77 77
diff --git a/src/lib/libcrypto/modes/gcm128.c b/src/lib/libcrypto/modes/gcm128.c
index 4a72901a33..dd6d91e880 100644
--- a/src/lib/libcrypto/modes/gcm128.c
+++ b/src/lib/libcrypto/modes/gcm128.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gcm128.c,v 1.12 2015/02/10 09:46:30 miod Exp $ */ 1/* $OpenBSD: gcm128.c,v 1.13 2015/09/10 15:56:25 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2010 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2010 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -1533,7 +1533,7 @@ GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block)
1533void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx) 1533void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx)
1534{ 1534{
1535 if (ctx) { 1535 if (ctx) {
1536 OPENSSL_cleanse(ctx,sizeof(*ctx)); 1536 explicit_bzero(ctx,sizeof(*ctx));
1537 free(ctx); 1537 free(ctx);
1538 } 1538 }
1539} 1539}
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
index 6fe72ce742..191e3b5b10 100644
--- a/src/lib/libcrypto/pem/pem_info.c
+++ b/src/lib/libcrypto/pem/pem_info.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_info.c,v 1.20 2015/02/10 09:52:35 miod Exp $ */ 1/* $OpenBSD: pem_info.c,v 1.21 2015/09/10 15:56:25 jsing 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 *
@@ -400,7 +400,7 @@ PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
400 ret = 1; 400 ret = 1;
401 401
402err: 402err:
403 OPENSSL_cleanse((char *)&ctx, sizeof(ctx)); 403 explicit_bzero((char *)&ctx, sizeof(ctx));
404 OPENSSL_cleanse(buf, PEM_BUFSIZE); 404 explicit_bzero(buf, PEM_BUFSIZE);
405 return (ret); 405 return (ret);
406} 406}
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
index 6f8759a9ee..852b0eaf86 100644
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ b/src/lib/libcrypto/pem/pem_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_lib.c,v 1.41 2015/07/19 18:29:31 miod Exp $ */ 1/* $OpenBSD: pem_lib.c,v 1.42 2015/09/10 15:56:25 jsing 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 *
@@ -403,7 +403,7 @@ PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x,
403 goto err; 403 goto err;
404 404
405 if (kstr == (unsigned char *)buf) 405 if (kstr == (unsigned char *)buf)
406 OPENSSL_cleanse(buf, PEM_BUFSIZE); 406 explicit_bzero(buf, PEM_BUFSIZE);
407 407
408 if (strlen(objstr) + 23 + 2 * enc->iv_len + 13 > sizeof buf) { 408 if (strlen(objstr) + 23 + 2 * enc->iv_len + 13 > sizeof buf) {
409 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO, 409 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,
@@ -434,12 +434,12 @@ PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x,
434 if (i <= 0) 434 if (i <= 0)
435 ret = 0; 435 ret = 0;
436err: 436err:
437 OPENSSL_cleanse(key, sizeof(key)); 437 explicit_bzero(key, sizeof(key));
438 OPENSSL_cleanse(iv, sizeof(iv)); 438 explicit_bzero(iv, sizeof(iv));
439 OPENSSL_cleanse((char *)&ctx, sizeof(ctx)); 439 explicit_bzero((char *)&ctx, sizeof(ctx));
440 OPENSSL_cleanse(buf, PEM_BUFSIZE); 440 explicit_bzero(buf, PEM_BUFSIZE);
441 if (data != NULL) { 441 if (data != NULL) {
442 OPENSSL_cleanse(data, (unsigned int)dsize); 442 explicit_bzero(data, (unsigned int)dsize);
443 free(data); 443 free(data);
444 } 444 }
445 return (ret); 445 return (ret);
@@ -480,8 +480,8 @@ PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
480 if (o) 480 if (o)
481 o = EVP_DecryptFinal_ex(&ctx, &(data[i]), &j); 481 o = EVP_DecryptFinal_ex(&ctx, &(data[i]), &j);
482 EVP_CIPHER_CTX_cleanup(&ctx); 482 EVP_CIPHER_CTX_cleanup(&ctx);
483 OPENSSL_cleanse((char *)buf, sizeof(buf)); 483 explicit_bzero((char *)buf, sizeof(buf));
484 OPENSSL_cleanse((char *)key, sizeof(key)); 484 explicit_bzero((char *)key, sizeof(key));
485 if (!o) { 485 if (!o) {
486 PEMerr(PEM_F_PEM_DO_HEADER, PEM_R_BAD_DECRYPT); 486 PEMerr(PEM_F_PEM_DO_HEADER, PEM_R_BAD_DECRYPT);
487 return (0); 487 return (0);
@@ -640,7 +640,7 @@ PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
640 EVP_EncodeFinal(&ctx, buf, &outl); 640 EVP_EncodeFinal(&ctx, buf, &outl);
641 if ((outl > 0) && (BIO_write(bp, (char *)buf, outl) != outl)) 641 if ((outl > 0) && (BIO_write(bp, (char *)buf, outl) != outl))
642 goto err; 642 goto err;
643 OPENSSL_cleanse(buf, PEM_BUFSIZE * 8); 643 explicit_bzero(buf, PEM_BUFSIZE * 8);
644 free(buf); 644 free(buf);
645 buf = NULL; 645 buf = NULL;
646 if ((BIO_write(bp, "-----END ", 9) != 9) || 646 if ((BIO_write(bp, "-----END ", 9) != 9) ||
@@ -651,7 +651,7 @@ PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
651 651
652err: 652err:
653 if (buf) { 653 if (buf) {
654 OPENSSL_cleanse(buf, PEM_BUFSIZE * 8); 654 explicit_bzero(buf, PEM_BUFSIZE * 8);
655 free(buf); 655 free(buf);
656 } 656 }
657 PEMerr(PEM_F_PEM_WRITE_BIO, reason); 657 PEMerr(PEM_F_PEM_WRITE_BIO, reason);
diff --git a/src/lib/libcrypto/pem/pem_pk8.c b/src/lib/libcrypto/pem/pem_pk8.c
index 5b0fcc236b..d02dec1546 100644
--- a/src/lib/libcrypto/pem/pem_pk8.c
+++ b/src/lib/libcrypto/pem/pem_pk8.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_pk8.c,v 1.9 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: pem_pk8.c,v 1.10 2015/09/10 15:56:25 jsing 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 *
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/buffer.h> 62#include <openssl/buffer.h>
62#include <openssl/err.h> 63#include <openssl/err.h>
@@ -135,7 +136,7 @@ do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
135 } 136 }
136 p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf); 137 p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf);
137 if (kstr == buf) 138 if (kstr == buf)
138 OPENSSL_cleanse(buf, klen); 139 explicit_bzero(buf, klen);
139 PKCS8_PRIV_KEY_INFO_free(p8inf); 140 PKCS8_PRIV_KEY_INFO_free(p8inf);
140 if (isder) 141 if (isder)
141 ret = i2d_PKCS8_bio(bp, p8); 142 ret = i2d_PKCS8_bio(bp, p8);
diff --git a/src/lib/libcrypto/pem/pem_pkey.c b/src/lib/libcrypto/pem/pem_pkey.c
index e9c0a8b1c9..afb476f818 100644
--- a/src/lib/libcrypto/pem/pem_pkey.c
+++ b/src/lib/libcrypto/pem/pem_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_pkey.c,v 1.20 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: pem_pkey.c,v 1.21 2015/09/10 15:56:25 jsing 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 *
@@ -144,7 +144,7 @@ p8err:
144 PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY, ERR_R_ASN1_LIB); 144 PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY, ERR_R_ASN1_LIB);
145err: 145err:
146 free(nm); 146 free(nm);
147 OPENSSL_cleanse(data, len); 147 explicit_bzero(data, len);
148 free(data); 148 free(data);
149 return (ret); 149 return (ret);
150} 150}
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
index 08837bd7f7..96687eb77f 100644
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ b/src/lib/libcrypto/pem/pem_seal.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_seal.c,v 1.21 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: pem_seal.c,v 1.22 2015/09/10 15:56:25 jsing 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 *
@@ -117,7 +117,7 @@ PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
117 117
118err: 118err:
119 free(s); 119 free(s);
120 OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH); 120 explicit_bzero(key, EVP_MAX_KEY_LENGTH);
121 return (ret); 121 return (ret);
122} 122}
123 123
diff --git a/src/lib/libcrypto/pem/pvkfmt.c b/src/lib/libcrypto/pem/pvkfmt.c
index 025381bcc0..f5a9de39fc 100644
--- a/src/lib/libcrypto/pem/pvkfmt.c
+++ b/src/lib/libcrypto/pem/pvkfmt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pvkfmt.c,v 1.13 2015/05/15 11:00:14 jsg Exp $ */ 1/* $OpenBSD: pvkfmt.c,v 1.14 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2005. 3 * project 2005.
4 */ 4 */
@@ -765,7 +765,7 @@ do_PVK_body(const unsigned char **in, unsigned int saltlen,
765 if (!EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, 765 if (!EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf,
766 NULL)) 766 NULL))
767 goto err; 767 goto err;
768 OPENSSL_cleanse(keybuf, 20); 768 explicit_bzero(keybuf, 20);
769 if (!EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen)) 769 if (!EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen))
770 goto err; 770 goto err;
771 if (!EVP_DecryptFinal_ex(&cctx, q + enctmplen, 771 if (!EVP_DecryptFinal_ex(&cctx, q + enctmplen,
@@ -777,7 +777,7 @@ do_PVK_body(const unsigned char **in, unsigned int saltlen,
777 goto err; 777 goto err;
778 } 778 }
779 } else 779 } else
780 OPENSSL_cleanse(keybuf, 20); 780 explicit_bzero(keybuf, 20);
781 p = enctmp; 781 p = enctmp;
782 } 782 }
783 783
@@ -823,7 +823,7 @@ b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u)
823 823
824err: 824err:
825 if (buf) { 825 if (buf) {
826 OPENSSL_cleanse(buf, buflen); 826 explicit_bzero(buf, buflen);
827 free(buf); 827 free(buf);
828 } 828 }
829 return ret; 829 return ret;
@@ -894,7 +894,7 @@ i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel, pem_password_cb *cb,
894 p = salt + PVK_SALTLEN + 8; 894 p = salt + PVK_SALTLEN + 8;
895 if (!EVP_EncryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, NULL)) 895 if (!EVP_EncryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, NULL))
896 goto error; 896 goto error;
897 OPENSSL_cleanse(keybuf, 20); 897 explicit_bzero(keybuf, 20);
898 if (!EVP_DecryptUpdate(&cctx, p, &enctmplen, p, pklen - 8)) 898 if (!EVP_DecryptUpdate(&cctx, p, &enctmplen, p, pklen - 8))
899 goto error; 899 goto error;
900 if (!EVP_DecryptFinal_ex(&cctx, p + enctmplen, &enctmplen)) 900 if (!EVP_DecryptFinal_ex(&cctx, p + enctmplen, &enctmplen))
diff --git a/src/lib/libcrypto/pkcs12/p12_crpt.c b/src/lib/libcrypto/pkcs12/p12_crpt.c
index 288c93c49f..0f215d2fe2 100644
--- a/src/lib/libcrypto/pkcs12/p12_crpt.c
+++ b/src/lib/libcrypto/pkcs12/p12_crpt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_crpt.c,v 1.11 2014/07/11 08:44:49 jsing Exp $ */ 1/* $OpenBSD: p12_crpt.c,v 1.12 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/err.h> 62#include <openssl/err.h>
62#include <openssl/pkcs12.h> 63#include <openssl/pkcs12.h>
@@ -111,7 +112,7 @@ PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
111 } 112 }
112 PBEPARAM_free(pbe); 113 PBEPARAM_free(pbe);
113 ret = EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, en_de); 114 ret = EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, en_de);
114 OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH); 115 explicit_bzero(key, EVP_MAX_KEY_LENGTH);
115 OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH); 116 explicit_bzero(iv, EVP_MAX_IV_LENGTH);
116 return ret; 117 return ret;
117} 118}
diff --git a/src/lib/libcrypto/pkcs12/p12_decr.c b/src/lib/libcrypto/pkcs12/p12_decr.c
index 4cccf43d3f..00195f0a98 100644
--- a/src/lib/libcrypto/pkcs12/p12_decr.c
+++ b/src/lib/libcrypto/pkcs12/p12_decr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_decr.c,v 1.15 2015/05/15 11:00:14 jsg Exp $ */ 1/* $OpenBSD: p12_decr.c,v 1.16 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/err.h> 62#include <openssl/err.h>
62#include <openssl/pkcs12.h> 63#include <openssl/pkcs12.h>
@@ -137,7 +138,7 @@ PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,
137 p = out; 138 p = out;
138 ret = ASN1_item_d2i(NULL, &p, outlen, it); 139 ret = ASN1_item_d2i(NULL, &p, outlen, it);
139 if (zbuf) 140 if (zbuf)
140 OPENSSL_cleanse(out, outlen); 141 explicit_bzero(out, outlen);
141 if (!ret) 142 if (!ret)
142 PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I, 143 PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I,
143 PKCS12_R_DECODE_ERROR); 144 PKCS12_R_DECODE_ERROR);
@@ -176,7 +177,7 @@ PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *it,
176 goto err; 177 goto err;
177 } 178 }
178 if (zbuf) 179 if (zbuf)
179 OPENSSL_cleanse(in, inlen); 180 explicit_bzero(in, inlen);
180 free(in); 181 free(in);
181 return oct; 182 return oct;
182 183
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c
index 0b3547a6fb..38f8a8194c 100644
--- a/src/lib/libcrypto/pkcs12/p12_key.c
+++ b/src/lib/libcrypto/pkcs12/p12_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_key.c,v 1.22 2015/02/07 13:19:15 doug Exp $ */ 1/* $OpenBSD: p12_key.c,v 1.23 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -89,7 +89,7 @@ PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
89 if (ret <= 0) 89 if (ret <= 0)
90 return 0; 90 return 0;
91 if (unipass) { 91 if (unipass) {
92 OPENSSL_cleanse(unipass, uniplen); 92 explicit_bzero(unipass, uniplen);
93 free(unipass); 93 free(unipass);
94 } 94 }
95 return ret; 95 return ret;
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
index 24bcebef61..7755c3c30e 100644
--- a/src/lib/libcrypto/pkcs7/pk7_doit.c
+++ b/src/lib/libcrypto/pkcs7/pk7_doit.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_doit.c,v 1.36 2015/07/29 14:58:34 jsing Exp $ */ 1/* $OpenBSD: pk7_doit.c,v 1.37 2015/09/10 15:56:25 jsing 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 *
@@ -233,7 +233,7 @@ pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen, PKCS7_RECIP_INFO *ri,
233 ret = 1; 233 ret = 1;
234 234
235 if (*pek) { 235 if (*pek) {
236 OPENSSL_cleanse(*pek, *peklen); 236 explicit_bzero(*pek, *peklen);
237 free(*pek); 237 free(*pek);
238 } 238 }
239 239
@@ -371,7 +371,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
371 if (pkcs7_encode_rinfo(ri, key, keylen) <= 0) 371 if (pkcs7_encode_rinfo(ri, key, keylen) <= 0)
372 goto err; 372 goto err;
373 } 373 }
374 OPENSSL_cleanse(key, keylen); 374 explicit_bzero(key, keylen);
375 375
376 if (out == NULL) 376 if (out == NULL)
377 out = btmp; 377 out = btmp;
@@ -588,7 +588,7 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
588 */ 588 */
589 if (!EVP_CIPHER_CTX_set_key_length(evp_ctx, eklen)) { 589 if (!EVP_CIPHER_CTX_set_key_length(evp_ctx, eklen)) {
590 /* Use random key as MMA defence */ 590 /* Use random key as MMA defence */
591 OPENSSL_cleanse(ek, eklen); 591 explicit_bzero(ek, eklen);
592 free(ek); 592 free(ek);
593 ek = tkey; 593 ek = tkey;
594 eklen = tkeylen; 594 eklen = tkeylen;
@@ -601,12 +601,12 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
601 goto err; 601 goto err;
602 602
603 if (ek) { 603 if (ek) {
604 OPENSSL_cleanse(ek, eklen); 604 explicit_bzero(ek, eklen);
605 free(ek); 605 free(ek);
606 ek = NULL; 606 ek = NULL;
607 } 607 }
608 if (tkey) { 608 if (tkey) {
609 OPENSSL_cleanse(tkey, tkeylen); 609 explicit_bzero(tkey, tkeylen);
610 free(tkey); 610 free(tkey);
611 tkey = NULL; 611 tkey = NULL;
612 } 612 }
@@ -635,11 +635,11 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
635 if (0) { 635 if (0) {
636err: 636err:
637 if (ek) { 637 if (ek) {
638 OPENSSL_cleanse(ek, eklen); 638 explicit_bzero(ek, eklen);
639 free(ek); 639 free(ek);
640 } 640 }
641 if (tkey) { 641 if (tkey) {
642 OPENSSL_cleanse(tkey, tkeylen); 642 explicit_bzero(tkey, tkeylen);
643 free(tkey); 643 free(tkey);
644 } 644 }
645 if (out != NULL) 645 if (out != NULL)
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c
index 6948a83634..72c065c48d 100644
--- a/src/lib/libcrypto/rand/randfile.c
+++ b/src/lib/libcrypto/rand/randfile.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: randfile.c,v 1.41 2015/07/18 22:46:42 beck Exp $ */ 1/* $OpenBSD: randfile.c,v 1.42 2015/09/10 15:56:25 jsing 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 *
@@ -130,7 +130,7 @@ RAND_write_file(const char *file)
130 } 130 }
131 131
132 fclose(out); 132 fclose(out);
133 OPENSSL_cleanse(buf, BUFSIZE); 133 explicit_bzero(buf, BUFSIZE);
134 return ret; 134 return ret;
135} 135}
136 136
diff --git a/src/lib/libcrypto/ripemd/rmd_one.c b/src/lib/libcrypto/ripemd/rmd_one.c
index 84b13d5312..0d372f32f7 100644
--- a/src/lib/libcrypto/ripemd/rmd_one.c
+++ b/src/lib/libcrypto/ripemd/rmd_one.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rmd_one.c,v 1.8 2015/09/10 15:03:59 jsing Exp $ */ 1/* $OpenBSD: rmd_one.c,v 1.9 2015/09/10 15:56:25 jsing 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 *
@@ -72,7 +72,7 @@ unsigned char *RIPEMD160(const unsigned char *d, size_t n,
72 return NULL; 72 return NULL;
73 RIPEMD160_Update(&c,d,n); 73 RIPEMD160_Update(&c,d,n);
74 RIPEMD160_Final(md,&c); 74 RIPEMD160_Final(md,&c);
75 OPENSSL_cleanse(&c,sizeof(c)); 75 explicit_bzero(&c,sizeof(c));
76 return(md); 76 return(md);
77 } 77 }
78 78
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c
index 940964cac3..76863e7220 100644
--- a/src/lib/libcrypto/rsa/rsa_eay.c
+++ b/src/lib/libcrypto/rsa/rsa_eay.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_eay.c,v 1.39 2015/06/13 08:38:10 doug Exp $ */ 1/* $OpenBSD: rsa_eay.c,v 1.40 2015/09/10 15:56:25 jsing 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 *
@@ -110,6 +110,7 @@
110 */ 110 */
111 111
112#include <stdio.h> 112#include <stdio.h>
113#include <string.h>
113 114
114#include <openssl/opensslconf.h> 115#include <openssl/opensslconf.h>
115 116
@@ -242,7 +243,7 @@ err:
242 BN_CTX_free(ctx); 243 BN_CTX_free(ctx);
243 } 244 }
244 if (buf != NULL) { 245 if (buf != NULL) {
245 OPENSSL_cleanse(buf, num); 246 explicit_bzero(buf, num);
246 free(buf); 247 free(buf);
247 } 248 }
248 return r; 249 return r;
@@ -472,7 +473,7 @@ err:
472 BN_CTX_free(ctx); 473 BN_CTX_free(ctx);
473 } 474 }
474 if (buf != NULL) { 475 if (buf != NULL) {
475 OPENSSL_cleanse(buf, num); 476 explicit_bzero(buf, num);
476 free(buf); 477 free(buf);
477 } 478 }
478 return r; 479 return r;
@@ -607,7 +608,7 @@ err:
607 BN_CTX_free(ctx); 608 BN_CTX_free(ctx);
608 } 609 }
609 if (buf != NULL) { 610 if (buf != NULL) {
610 OPENSSL_cleanse(buf, num); 611 explicit_bzero(buf, num);
611 free(buf); 612 free(buf);
612 } 613 }
613 return r; 614 return r;
@@ -712,7 +713,7 @@ err:
712 BN_CTX_free(ctx); 713 BN_CTX_free(ctx);
713 } 714 }
714 if (buf != NULL) { 715 if (buf != NULL) {
715 OPENSSL_cleanse(buf, num); 716 explicit_bzero(buf, num);
716 free(buf); 717 free(buf);
717 } 718 }
718 return r; 719 return r;
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c
index 3a07a7af4a..0a4f37a3da 100644
--- a/src/lib/libcrypto/rsa/rsa_saos.c
+++ b/src/lib/libcrypto/rsa/rsa_saos.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_saos.c,v 1.17 2015/07/19 18:29:31 miod Exp $ */ 1/* $OpenBSD: rsa_saos.c,v 1.18 2015/09/10 15:56:25 jsing 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 *
@@ -97,7 +97,7 @@ RSA_sign_ASN1_OCTET_STRING(int type, const unsigned char *m, unsigned int m_len,
97 else 97 else
98 *siglen = i; 98 *siglen = i;
99 99
100 OPENSSL_cleanse(s, (unsigned int)j + 1); 100 explicit_bzero(s, (unsigned int)j + 1);
101 free(s); 101 free(s);
102 return ret; 102 return ret;
103} 103}
@@ -142,7 +142,7 @@ RSA_verify_ASN1_OCTET_STRING(int dtype, const unsigned char *m,
142err: 142err:
143 M_ASN1_OCTET_STRING_free(sig); 143 M_ASN1_OCTET_STRING_free(sig);
144 if (s != NULL) { 144 if (s != NULL) {
145 OPENSSL_cleanse(s, (unsigned int)siglen); 145 explicit_bzero(s, (unsigned int)siglen);
146 free(s); 146 free(s);
147 } 147 }
148 return ret; 148 return ret;
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c
index db63c5f038..7be08f544b 100644
--- a/src/lib/libcrypto/rsa/rsa_sign.c
+++ b/src/lib/libcrypto/rsa/rsa_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_sign.c,v 1.24 2015/07/19 18:29:31 miod Exp $ */ 1/* $OpenBSD: rsa_sign.c,v 1.25 2015/09/10 15:56:25 jsing 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 *
@@ -137,7 +137,7 @@ RSA_sign(int type, const unsigned char *m, unsigned int m_len,
137 *siglen = i; 137 *siglen = i;
138 138
139 if (type != NID_md5_sha1) { 139 if (type != NID_md5_sha1) {
140 OPENSSL_cleanse(tmps, (unsigned int)j + 1); 140 explicit_bzero(tmps, (unsigned int)j + 1);
141 free(tmps); 141 free(tmps);
142 } 142 }
143 return (ret); 143 return (ret);
@@ -237,7 +237,7 @@ err:
237 if (sig != NULL) 237 if (sig != NULL)
238 X509_SIG_free(sig); 238 X509_SIG_free(sig);
239 if (s != NULL) { 239 if (s != NULL) {
240 OPENSSL_cleanse(s, (unsigned int)siglen); 240 explicit_bzero(s, (unsigned int)siglen);
241 free(s); 241 free(s);
242 } 242 }
243 return ret; 243 return ret;
diff --git a/src/lib/libcrypto/sha/sha1_one.c b/src/lib/libcrypto/sha/sha1_one.c
index f6b5e4bacf..91602ee503 100644
--- a/src/lib/libcrypto/sha/sha1_one.c
+++ b/src/lib/libcrypto/sha/sha1_one.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha1_one.c,v 1.11 2014/07/10 22:45:58 jsing Exp $ */ 1/* $OpenBSD: sha1_one.c,v 1.12 2015/09/10 15:56:26 jsing 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 *
@@ -75,7 +75,7 @@ unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md)
75 return NULL; 75 return NULL;
76 SHA1_Update(&c,d,n); 76 SHA1_Update(&c,d,n);
77 SHA1_Final(md,&c); 77 SHA1_Final(md,&c);
78 OPENSSL_cleanse(&c,sizeof(c)); 78 explicit_bzero(&c,sizeof(c));
79 return(md); 79 return(md);
80 } 80 }
81#endif 81#endif
diff --git a/src/lib/libcrypto/sha/sha256.c b/src/lib/libcrypto/sha/sha256.c
index c5ab56852f..d584660369 100644
--- a/src/lib/libcrypto/sha/sha256.c
+++ b/src/lib/libcrypto/sha/sha256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha256.c,v 1.8 2014/08/18 19:11:48 bcook Exp $ */ 1/* $OpenBSD: sha256.c,v 1.9 2015/09/10 15:56:26 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2004 The OpenSSL Project. All rights reserved 3 * Copyright (c) 2004 The OpenSSL Project. All rights reserved
4 * according to the OpenSSL license [found in ../../LICENSE]. 4 * according to the OpenSSL license [found in ../../LICENSE].
@@ -49,7 +49,7 @@ unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md)
49 SHA224_Init(&c); 49 SHA224_Init(&c);
50 SHA256_Update(&c,d,n); 50 SHA256_Update(&c,d,n);
51 SHA256_Final(md,&c); 51 SHA256_Final(md,&c);
52 OPENSSL_cleanse(&c,sizeof(c)); 52 explicit_bzero(&c,sizeof(c));
53 return(md); 53 return(md);
54 } 54 }
55 55
@@ -62,7 +62,7 @@ unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md)
62 SHA256_Init(&c); 62 SHA256_Init(&c);
63 SHA256_Update(&c,d,n); 63 SHA256_Update(&c,d,n);
64 SHA256_Final(md,&c); 64 SHA256_Final(md,&c);
65 OPENSSL_cleanse(&c,sizeof(c)); 65 explicit_bzero(&c,sizeof(c));
66 return(md); 66 return(md);
67 } 67 }
68 68
diff --git a/src/lib/libcrypto/sha/sha512.c b/src/lib/libcrypto/sha/sha512.c
index ad72b7e6f1..7a55c0acc9 100644
--- a/src/lib/libcrypto/sha/sha512.c
+++ b/src/lib/libcrypto/sha/sha512.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha512.c,v 1.13 2014/07/11 08:44:49 jsing Exp $ */ 1/* $OpenBSD: sha512.c,v 1.14 2015/09/10 15:56:26 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2004 The OpenSSL Project. All rights reserved 3 * Copyright (c) 2004 The OpenSSL Project. All rights reserved
4 * according to the OpenSSL license [found in ../../LICENSE]. 4 * according to the OpenSSL license [found in ../../LICENSE].
@@ -248,7 +248,7 @@ unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md)
248 SHA384_Init(&c); 248 SHA384_Init(&c);
249 SHA512_Update(&c,d,n); 249 SHA512_Update(&c,d,n);
250 SHA512_Final(md,&c); 250 SHA512_Final(md,&c);
251 OPENSSL_cleanse(&c,sizeof(c)); 251 explicit_bzero(&c,sizeof(c));
252 return(md); 252 return(md);
253 } 253 }
254 254
@@ -261,7 +261,7 @@ unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md)
261 SHA512_Init(&c); 261 SHA512_Init(&c);
262 SHA512_Update(&c,d,n); 262 SHA512_Update(&c,d,n);
263 SHA512_Final(md,&c); 263 SHA512_Final(md,&c);
264 OPENSSL_cleanse(&c,sizeof(c)); 264 explicit_bzero(&c,sizeof(c));
265 return(md); 265 return(md);
266 } 266 }
267 267
diff --git a/src/lib/libcrypto/sha/sha_one.c b/src/lib/libcrypto/sha/sha_one.c
index 1d3fc35f05..ad04021eb1 100644
--- a/src/lib/libcrypto/sha/sha_one.c
+++ b/src/lib/libcrypto/sha/sha_one.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha_one.c,v 1.8 2014/07/10 22:45:58 jsing Exp $ */ 1/* $OpenBSD: sha_one.c,v 1.9 2015/09/10 15:56:26 jsing 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 *
@@ -75,7 +75,7 @@ unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md)
75 return NULL; 75 return NULL;
76 SHA_Update(&c,d,n); 76 SHA_Update(&c,d,n);
77 SHA_Final(md,&c); 77 SHA_Final(md,&c);
78 OPENSSL_cleanse(&c,sizeof(c)); 78 explicit_bzero(&c,sizeof(c));
79 return(md); 79 return(md);
80 } 80 }
81#endif 81#endif
diff --git a/src/lib/libcrypto/ui/ui_openssl.c b/src/lib/libcrypto/ui/ui_openssl.c
index b3d2971a02..9562c2c937 100644
--- a/src/lib/libcrypto/ui/ui_openssl.c
+++ b/src/lib/libcrypto/ui/ui_openssl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ui_openssl.c,v 1.24 2015/07/16 02:46:49 guenther Exp $ */ 1/* $OpenBSD: ui_openssl.c,v 1.25 2015/09/10 15:56:26 jsing Exp $ */
2/* Written by Richard Levitte (richard@levitte.org) and others 2/* Written by Richard Levitte (richard@levitte.org) and others
3 * for the OpenSSL project 2001. 3 * for the OpenSSL project 2001.
4 */ 4 */
@@ -286,7 +286,7 @@ error:
286 if (ps >= 1) 286 if (ps >= 1)
287 popsig(); 287 popsig();
288 288
289 OPENSSL_cleanse(result, BUFSIZ); 289 explicit_bzero(result, BUFSIZ);
290 return ok; 290 return ok;
291} 291}
292 292
diff --git a/src/lib/libcrypto/ui/ui_util.c b/src/lib/libcrypto/ui/ui_util.c
index e5cee913b2..d1040c9826 100644
--- a/src/lib/libcrypto/ui/ui_util.c
+++ b/src/lib/libcrypto/ui/ui_util.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ui_util.c,v 1.9 2014/06/12 15:49:31 deraadt Exp $ */ 1/* $OpenBSD: ui_util.c,v 1.10 2015/09/10 15:56:26 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -67,7 +67,7 @@ UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify)
67 67
68 ret = UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length, 68 ret = UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length,
69 prompt, verify); 69 prompt, verify);
70 OPENSSL_cleanse(buff, BUFSIZ); 70 explicit_bzero(buff, BUFSIZ);
71 return (ret); 71 return (ret);
72} 72}
73 73
diff --git a/src/lib/libssl/d1_clnt.c b/src/lib/libssl/d1_clnt.c
index 23d6b372c9..2b736b9243 100644
--- a/src/lib/libssl/d1_clnt.c
+++ b/src/lib/libssl/d1_clnt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_clnt.c,v 1.48 2015/09/02 17:59:15 jsing Exp $ */ 1/* $OpenBSD: d1_clnt.c,v 1.49 2015/09/10 15:56:26 jsing Exp $ */
2/* 2/*
3 * DTLS implementation written by Nagendra Modadugu 3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -731,7 +731,7 @@ dtls1_send_client_key_exchange(SSL *s)
731 s->method->ssl3_enc->generate_master_secret(s, 731 s->method->ssl3_enc->generate_master_secret(s,
732 s->session->master_key, 732 s->session->master_key,
733 tmp_buf, sizeof tmp_buf); 733 tmp_buf, sizeof tmp_buf);
734 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); 734 explicit_bzero(tmp_buf, sizeof tmp_buf);
735 } else if (alg_k & SSL_kDHE) { 735 } else if (alg_k & SSL_kDHE) {
736 DH *dh_srvr, *dh_clnt; 736 DH *dh_srvr, *dh_clnt;
737 737
diff --git a/src/lib/libssl/d1_lib.c b/src/lib/libssl/d1_lib.c
index b269efe469..e7eca4a8cd 100644
--- a/src/lib/libssl/d1_lib.c
+++ b/src/lib/libssl/d1_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_lib.c,v 1.29 2015/07/19 20:32:18 doug Exp $ */ 1/* $OpenBSD: d1_lib.c,v 1.30 2015/09/10 15:56:26 jsing Exp $ */
2/* 2/*
3 * DTLS implementation written by Nagendra Modadugu 3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -203,7 +203,7 @@ dtls1_free(SSL *s)
203 pqueue_free(s->d1->sent_messages); 203 pqueue_free(s->d1->sent_messages);
204 pqueue_free(s->d1->buffered_app_data.q); 204 pqueue_free(s->d1->buffered_app_data.q);
205 205
206 OPENSSL_cleanse(s->d1, sizeof *s->d1); 206 explicit_bzero(s->d1, sizeof *s->d1);
207 free(s->d1); 207 free(s->d1);
208 s->d1 = NULL; 208 s->d1 = NULL;
209} 209}
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c
index 1d1a0c77f0..e4ce8163ac 100644
--- a/src/lib/libssl/s3_clnt.c
+++ b/src/lib/libssl/s3_clnt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_clnt.c,v 1.125 2015/09/02 17:59:15 jsing Exp $ */ 1/* $OpenBSD: s3_clnt.c,v 1.126 2015/09/10 15:56:26 jsing 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 *
@@ -1933,7 +1933,7 @@ ssl3_send_client_key_exchange(SSL *s)
1933 s->session->master_key_length = 1933 s->session->master_key_length =
1934 s->method->ssl3_enc->generate_master_secret( 1934 s->method->ssl3_enc->generate_master_secret(
1935 s, s->session->master_key, tmp_buf, sizeof tmp_buf); 1935 s, s->session->master_key, tmp_buf, sizeof tmp_buf);
1936 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); 1936 explicit_bzero(tmp_buf, sizeof tmp_buf);
1937 } else if (alg_k & SSL_kDHE) { 1937 } else if (alg_k & SSL_kDHE) {
1938 DH *dh_srvr, *dh_clnt; 1938 DH *dh_srvr, *dh_clnt;
1939 1939
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c
index 42396a21e9..4e6b123698 100644
--- a/src/lib/libssl/s3_lib.c
+++ b/src/lib/libssl/s3_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_lib.c,v 1.100 2015/08/27 06:21:15 doug Exp $ */ 1/* $OpenBSD: s3_lib.c,v 1.101 2015/09/10 15:56:26 jsing 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 *
@@ -2066,7 +2066,7 @@ ssl3_free(SSL *s)
2066 ssl3_free_digest_list(s); 2066 ssl3_free_digest_list(s);
2067 free(s->s3->alpn_selected); 2067 free(s->s3->alpn_selected);
2068 2068
2069 OPENSSL_cleanse(s->s3, sizeof *s->s3); 2069 explicit_bzero(s->s3, sizeof *s->s3);
2070 free(s->s3); 2070 free(s->s3);
2071 s->s3 = NULL; 2071 s->s3 = NULL;
2072} 2072}
diff --git a/src/lib/libssl/s3_srvr.c b/src/lib/libssl/s3_srvr.c
index 3f9f6720fa..b2c4f8e0d2 100644
--- a/src/lib/libssl/s3_srvr.c
+++ b/src/lib/libssl/s3_srvr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_srvr.c,v 1.115 2015/09/01 13:38:27 jsing Exp $ */ 1/* $OpenBSD: s3_srvr.c,v 1.116 2015/09/10 15:56:26 jsing 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 *
@@ -1725,7 +1725,7 @@ ssl3_get_client_key_exchange(SSL *s)
1725 s->method->ssl3_enc->generate_master_secret(s, 1725 s->method->ssl3_enc->generate_master_secret(s,
1726 s->session->master_key, 1726 s->session->master_key,
1727 p, i); 1727 p, i);
1728 OPENSSL_cleanse(p, i); 1728 explicit_bzero(p, i);
1729 } else if (alg_k & SSL_kDHE) { 1729 } else if (alg_k & SSL_kDHE) {
1730 if (2 > n) 1730 if (2 > n)
1731 goto truncated; 1731 goto truncated;
@@ -1776,7 +1776,7 @@ ssl3_get_client_key_exchange(SSL *s)
1776 s->session->master_key_length = 1776 s->session->master_key_length =
1777 s->method->ssl3_enc->generate_master_secret( 1777 s->method->ssl3_enc->generate_master_secret(
1778 s, s->session->master_key, p, i); 1778 s, s->session->master_key, p, i);
1779 OPENSSL_cleanse(p, i); 1779 explicit_bzero(p, i);
1780 } else 1780 } else
1781 1781
1782 if (alg_k & (SSL_kECDHE|SSL_kECDHr|SSL_kECDHe)) { 1782 if (alg_k & (SSL_kECDHE|SSL_kECDHr|SSL_kECDHe)) {
@@ -1920,7 +1920,7 @@ ssl3_get_client_key_exchange(SSL *s)
1920 s->session->master_key_length = s->method->ssl3_enc-> \ 1920 s->session->master_key_length = s->method->ssl3_enc-> \
1921 generate_master_secret(s, s->session->master_key, p, i); 1921 generate_master_secret(s, s->session->master_key, p, i);
1922 1922
1923 OPENSSL_cleanse(p, i); 1923 explicit_bzero(p, i);
1924 return (ret); 1924 return (ret);
1925 } else 1925 } else
1926 if (alg_k & SSL_kGOST) { 1926 if (alg_k & SSL_kGOST) {
diff --git a/src/lib/libssl/src/crypto/aes/aes_wrap.c b/src/lib/libssl/src/crypto/aes/aes_wrap.c
index 4479473e6b..ac2f83a993 100644
--- a/src/lib/libssl/src/crypto/aes/aes_wrap.c
+++ b/src/lib/libssl/src/crypto/aes/aes_wrap.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: aes_wrap.c,v 1.9 2014/07/11 08:44:47 jsing Exp $ */ 1/* $OpenBSD: aes_wrap.c,v 1.10 2015/09/10 15:56:24 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -126,7 +126,7 @@ AES_unwrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out,
126 if (!iv) 126 if (!iv)
127 iv = default_iv; 127 iv = default_iv;
128 if (memcmp(A, iv, 8)) { 128 if (memcmp(A, iv, 8)) {
129 OPENSSL_cleanse(out, inlen); 129 explicit_bzero(out, inlen);
130 return 0; 130 return 0;
131 } 131 }
132 return inlen; 132 return inlen;
diff --git a/src/lib/libssl/src/crypto/asn1/a_sign.c b/src/lib/libssl/src/crypto/asn1/a_sign.c
index d9385312a7..195daa3b9f 100644
--- a/src/lib/libssl/src/crypto/asn1/a_sign.c
+++ b/src/lib/libssl/src/crypto/asn1/a_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_sign.c,v 1.20 2015/07/19 18:29:31 miod Exp $ */ 1/* $OpenBSD: a_sign.c,v 1.21 2015/09/10 15:56:24 jsing 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 *
@@ -112,6 +112,7 @@
112#include <sys/types.h> 112#include <sys/types.h>
113 113
114#include <stdio.h> 114#include <stdio.h>
115#include <string.h>
115#include <time.h> 116#include <time.h>
116 117
117#include <openssl/bn.h> 118#include <openssl/bn.h>
@@ -229,11 +230,11 @@ ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
229err: 230err:
230 EVP_MD_CTX_cleanup(ctx); 231 EVP_MD_CTX_cleanup(ctx);
231 if (buf_in != NULL) { 232 if (buf_in != NULL) {
232 OPENSSL_cleanse((char *)buf_in, inl); 233 explicit_bzero((char *)buf_in, inl);
233 free(buf_in); 234 free(buf_in);
234 } 235 }
235 if (buf_out != NULL) { 236 if (buf_out != NULL) {
236 OPENSSL_cleanse((char *)buf_out, outll); 237 explicit_bzero((char *)buf_out, outll);
237 free(buf_out); 238 free(buf_out);
238 } 239 }
239 return (outl); 240 return (outl);
diff --git a/src/lib/libssl/src/crypto/asn1/a_verify.c b/src/lib/libssl/src/crypto/asn1/a_verify.c
index 3fc79b78f6..12b76501e0 100644
--- a/src/lib/libssl/src/crypto/asn1/a_verify.c
+++ b/src/lib/libssl/src/crypto/asn1/a_verify.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_verify.c,v 1.21 2015/01/28 04:14:31 beck Exp $ */ 1/* $OpenBSD: a_verify.c,v 1.22 2015/09/10 15:56:24 jsing 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 *
@@ -59,6 +59,7 @@
59#include <sys/types.h> 59#include <sys/types.h>
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include <string.h>
62#include <time.h> 63#include <time.h>
63 64
64#include <openssl/bn.h> 65#include <openssl/bn.h>
@@ -152,7 +153,7 @@ ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
152 goto err; 153 goto err;
153 } 154 }
154 155
155 OPENSSL_cleanse(buf_in, (unsigned int)inl); 156 explicit_bzero(buf_in, (unsigned int)inl);
156 free(buf_in); 157 free(buf_in);
157 158
158 if (EVP_DigestVerifyFinal(&ctx, signature->data, 159 if (EVP_DigestVerifyFinal(&ctx, signature->data,
diff --git a/src/lib/libssl/src/crypto/asn1/n_pkey.c b/src/lib/libssl/src/crypto/asn1/n_pkey.c
index d3a7431356..491f988e92 100644
--- a/src/lib/libssl/src/crypto/asn1/n_pkey.c
+++ b/src/lib/libssl/src/crypto/asn1/n_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: n_pkey.c,v 1.26 2015/03/19 14:00:22 tedu Exp $ */ 1/* $OpenBSD: n_pkey.c,v 1.27 2015/09/10 15:56:24 jsing 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 *
@@ -277,7 +277,7 @@ i2d_RSA_NET(const RSA *a, unsigned char **pp,
277 i2d_NETSCAPE_PKEY(pkey, &zz); 277 i2d_NETSCAPE_PKEY(pkey, &zz);
278 278
279 /* Wipe the private key encoding */ 279 /* Wipe the private key encoding */
280 OPENSSL_cleanse(pkey->private_key->data, rsalen); 280 explicit_bzero(pkey->private_key->data, rsalen);
281 281
282 if (cb == NULL) 282 if (cb == NULL)
283 cb = EVP_read_pw_string; 283 cb = EVP_read_pw_string;
@@ -297,7 +297,7 @@ i2d_RSA_NET(const RSA *a, unsigned char **pp,
297 297
298 if (!EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, buf, i,1, key, NULL)) 298 if (!EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, buf, i,1, key, NULL))
299 goto err; 299 goto err;
300 OPENSSL_cleanse(buf, sizeof(buf)); 300 explicit_bzero(buf, sizeof(buf));
301 301
302 /* Encrypt private key in place */ 302 /* Encrypt private key in place */
303 zz = enckey->enckey->digest->data; 303 zz = enckey->enckey->digest->data;
@@ -394,7 +394,7 @@ d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
394 394
395 if (!EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, buf, i,1, key, NULL)) 395 if (!EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, buf, i,1, key, NULL))
396 goto err; 396 goto err;
397 OPENSSL_cleanse(buf, sizeof(buf)); 397 explicit_bzero(buf, sizeof(buf));
398 398
399 if (!EVP_DecryptInit_ex(&ctx, EVP_rc4(), NULL, key, NULL)) 399 if (!EVP_DecryptInit_ex(&ctx, EVP_rc4(), NULL, key, NULL))
400 goto err; 400 goto err;
diff --git a/src/lib/libssl/src/crypto/asn1/p8_pkey.c b/src/lib/libssl/src/crypto/asn1/p8_pkey.c
index 2f7a469673..71d579456a 100644
--- a/src/lib/libssl/src/crypto/asn1/p8_pkey.c
+++ b/src/lib/libssl/src/crypto/asn1/p8_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p8_pkey.c,v 1.16 2015/07/16 18:21:57 miod Exp $ */ 1/* $OpenBSD: p8_pkey.c,v 1.17 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/asn1t.h> 62#include <openssl/asn1t.h>
62#include <openssl/x509.h> 63#include <openssl/x509.h>
@@ -71,7 +72,7 @@ pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
71 if (key->pkey != NULL && 72 if (key->pkey != NULL &&
72 key->pkey->type == V_ASN1_OCTET_STRING && 73 key->pkey->type == V_ASN1_OCTET_STRING &&
73 key->pkey->value.octet_string != NULL) 74 key->pkey->value.octet_string != NULL)
74 OPENSSL_cleanse(key->pkey->value.octet_string->data, 75 explicit_bzero(key->pkey->value.octet_string->data,
75 key->pkey->value.octet_string->length); 76 key->pkey->value.octet_string->length);
76 } 77 }
77 return 1; 78 return 1;
diff --git a/src/lib/libssl/src/crypto/bn/bn_exp.c b/src/lib/libssl/src/crypto/bn/bn_exp.c
index 4a28c2c605..c4ca36d136 100644
--- a/src/lib/libssl/src/crypto/bn/bn_exp.c
+++ b/src/lib/libssl/src/crypto/bn/bn_exp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_exp.c,v 1.22 2015/03/21 08:05:20 doug Exp $ */ 1/* $OpenBSD: bn_exp.c,v 1.23 2015/09/10 15:56:25 jsing 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 *
@@ -825,7 +825,7 @@ err:
825 if ((in_mont == NULL) && (mont != NULL)) 825 if ((in_mont == NULL) && (mont != NULL))
826 BN_MONT_CTX_free(mont); 826 BN_MONT_CTX_free(mont);
827 if (powerbuf != NULL) { 827 if (powerbuf != NULL) {
828 OPENSSL_cleanse(powerbuf, powerbufLen); 828 explicit_bzero(powerbuf, powerbufLen);
829 free(powerbufFree); 829 free(powerbufFree);
830 } 830 }
831 BN_CTX_end(ctx); 831 BN_CTX_end(ctx);
diff --git a/src/lib/libssl/src/crypto/bn/bn_lib.c b/src/lib/libssl/src/crypto/bn/bn_lib.c
index d0cb49cd1e..7cc76c1e85 100644
--- a/src/lib/libssl/src/crypto/bn/bn_lib.c
+++ b/src/lib/libssl/src/crypto/bn/bn_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_lib.c,v 1.33 2014/07/12 16:03:36 miod Exp $ */ 1/* $OpenBSD: bn_lib.c,v 1.34 2015/09/10 15:56:25 jsing 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 *
@@ -221,11 +221,11 @@ BN_clear_free(BIGNUM *a)
221 return; 221 return;
222 bn_check_top(a); 222 bn_check_top(a);
223 if (a->d != NULL && !(BN_get_flags(a, BN_FLG_STATIC_DATA))) { 223 if (a->d != NULL && !(BN_get_flags(a, BN_FLG_STATIC_DATA))) {
224 OPENSSL_cleanse(a->d, a->dmax * sizeof(a->d[0])); 224 explicit_bzero(a->d, a->dmax * sizeof(a->d[0]));
225 free(a->d); 225 free(a->d);
226 } 226 }
227 i = BN_get_flags(a, BN_FLG_MALLOCED); 227 i = BN_get_flags(a, BN_FLG_MALLOCED);
228 OPENSSL_cleanse(a, sizeof(BIGNUM)); 228 explicit_bzero(a, sizeof(BIGNUM));
229 if (i) 229 if (i)
230 free(a); 230 free(a);
231} 231}
@@ -395,7 +395,7 @@ bn_expand2(BIGNUM *b, int words)
395 if (!a) 395 if (!a)
396 return NULL; 396 return NULL;
397 if (b->d) { 397 if (b->d) {
398 OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0])); 398 explicit_bzero(b->d, b->dmax * sizeof(b->d[0]));
399 free(b->d); 399 free(b->d);
400 } 400 }
401 b->d = a; 401 b->d = a;
diff --git a/src/lib/libssl/src/crypto/bn/bn_rand.c b/src/lib/libssl/src/crypto/bn/bn_rand.c
index ac5c5eb308..783f6c22f8 100644
--- a/src/lib/libssl/src/crypto/bn/bn_rand.c
+++ b/src/lib/libssl/src/crypto/bn/bn_rand.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_rand.c,v 1.17 2015/02/19 06:10:29 jsing Exp $ */ 1/* $OpenBSD: bn_rand.c,v 1.18 2015/09/10 15:56:25 jsing 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 *
@@ -111,6 +111,7 @@
111 111
112#include <stdio.h> 112#include <stdio.h>
113#include <stdlib.h> 113#include <stdlib.h>
114#include <string.h>
114#include <time.h> 115#include <time.h>
115 116
116#include <openssl/err.h> 117#include <openssl/err.h>
@@ -186,7 +187,7 @@ bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
186 187
187err: 188err:
188 if (buf != NULL) { 189 if (buf != NULL) {
189 OPENSSL_cleanse(buf, bytes); 190 explicit_bzero(buf, bytes);
190 free(buf); 191 free(buf);
191 } 192 }
192 bn_check_top(rnd); 193 bn_check_top(rnd);
diff --git a/src/lib/libssl/src/crypto/cmac/cmac.c b/src/lib/libssl/src/crypto/cmac/cmac.c
index 18635b942a..d01ae0f3ae 100644
--- a/src/lib/libssl/src/crypto/cmac/cmac.c
+++ b/src/lib/libssl/src/crypto/cmac/cmac.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cmac.c,v 1.9 2014/07/12 14:58:32 miod Exp $ */ 1/* $OpenBSD: cmac.c,v 1.10 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -107,10 +107,10 @@ void
107CMAC_CTX_cleanup(CMAC_CTX *ctx) 107CMAC_CTX_cleanup(CMAC_CTX *ctx)
108{ 108{
109 EVP_CIPHER_CTX_cleanup(&ctx->cctx); 109 EVP_CIPHER_CTX_cleanup(&ctx->cctx);
110 OPENSSL_cleanse(ctx->tbl, EVP_MAX_BLOCK_LENGTH); 110 explicit_bzero(ctx->tbl, EVP_MAX_BLOCK_LENGTH);
111 OPENSSL_cleanse(ctx->k1, EVP_MAX_BLOCK_LENGTH); 111 explicit_bzero(ctx->k1, EVP_MAX_BLOCK_LENGTH);
112 OPENSSL_cleanse(ctx->k2, EVP_MAX_BLOCK_LENGTH); 112 explicit_bzero(ctx->k2, EVP_MAX_BLOCK_LENGTH);
113 OPENSSL_cleanse(ctx->last_block, EVP_MAX_BLOCK_LENGTH); 113 explicit_bzero(ctx->last_block, EVP_MAX_BLOCK_LENGTH);
114 ctx->nlast_block = -1; 114 ctx->nlast_block = -1;
115} 115}
116 116
@@ -183,7 +183,7 @@ CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen,
183 return 0; 183 return 0;
184 make_kn(ctx->k1, ctx->tbl, bl); 184 make_kn(ctx->k1, ctx->tbl, bl);
185 make_kn(ctx->k2, ctx->k1, bl); 185 make_kn(ctx->k2, ctx->k1, bl);
186 OPENSSL_cleanse(ctx->tbl, bl); 186 explicit_bzero(ctx->tbl, bl);
187 /* Reset context again ready for first data block */ 187 /* Reset context again ready for first data block */
188 if (!EVP_EncryptInit_ex(&ctx->cctx, NULL, NULL, NULL, zero_iv)) 188 if (!EVP_EncryptInit_ex(&ctx->cctx, NULL, NULL, NULL, zero_iv))
189 return 0; 189 return 0;
@@ -260,7 +260,7 @@ CMAC_Final(CMAC_CTX *ctx, unsigned char *out, size_t *poutlen)
260 out[i] = ctx->last_block[i] ^ ctx->k2[i]; 260 out[i] = ctx->last_block[i] ^ ctx->k2[i];
261 } 261 }
262 if (!EVP_Cipher(&ctx->cctx, out, out, bl)) { 262 if (!EVP_Cipher(&ctx->cctx, out, out, bl)) {
263 OPENSSL_cleanse(out, bl); 263 explicit_bzero(out, bl);
264 return 0; 264 return 0;
265 } 265 }
266 return 1; 266 return 1;
diff --git a/src/lib/libssl/src/crypto/cms/cms_asn1.c b/src/lib/libssl/src/crypto/cms/cms_asn1.c
index 02a594575d..e450259832 100644
--- a/src/lib/libssl/src/crypto/cms/cms_asn1.c
+++ b/src/lib/libssl/src/crypto/cms/cms_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_asn1.c,v 1.6 2015/07/25 15:22:10 jsing Exp $ */ 1/* $OpenBSD: cms_asn1.c,v 1.7 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -888,13 +888,13 @@ cms_ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
888 } else if (ri->type == CMS_RECIPINFO_KEK) { 888 } else if (ri->type == CMS_RECIPINFO_KEK) {
889 CMS_KEKRecipientInfo *kekri = ri->d.kekri; 889 CMS_KEKRecipientInfo *kekri = ri->d.kekri;
890 if (kekri->key) { 890 if (kekri->key) {
891 OPENSSL_cleanse(kekri->key, kekri->keylen); 891 explicit_bzero(kekri->key, kekri->keylen);
892 free(kekri->key); 892 free(kekri->key);
893 } 893 }
894 } else if (ri->type == CMS_RECIPINFO_PASS) { 894 } else if (ri->type == CMS_RECIPINFO_PASS) {
895 CMS_PasswordRecipientInfo *pwri = ri->d.pwri; 895 CMS_PasswordRecipientInfo *pwri = ri->d.pwri;
896 if (pwri->pass) { 896 if (pwri->pass) {
897 OPENSSL_cleanse(pwri->pass, pwri->passlen); 897 explicit_bzero(pwri->pass, pwri->passlen);
898 free(pwri->pass); 898 free(pwri->pass);
899 } 899 }
900 } 900 }
diff --git a/src/lib/libssl/src/crypto/cms/cms_enc.c b/src/lib/libssl/src/crypto/cms/cms_enc.c
index f97e4d5f34..c967a18a3c 100644
--- a/src/lib/libssl/src/crypto/cms/cms_enc.c
+++ b/src/lib/libssl/src/crypto/cms/cms_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_enc.c,v 1.6 2014/10/22 13:02:04 jsing Exp $ */ 1/* $OpenBSD: cms_enc.c,v 1.7 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -164,7 +164,7 @@ cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
164 goto err; 164 goto err;
165 } else { 165 } else {
166 /* Use random key */ 166 /* Use random key */
167 OPENSSL_cleanse(ec->key, ec->keylen); 167 explicit_bzero(ec->key, ec->keylen);
168 free(ec->key); 168 free(ec->key);
169 ec->key = tkey; 169 ec->key = tkey;
170 ec->keylen = tkeylen; 170 ec->keylen = tkeylen;
@@ -197,12 +197,12 @@ cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
197 197
198err: 198err:
199 if (ec->key && !keep_key) { 199 if (ec->key && !keep_key) {
200 OPENSSL_cleanse(ec->key, ec->keylen); 200 explicit_bzero(ec->key, ec->keylen);
201 free(ec->key); 201 free(ec->key);
202 ec->key = NULL; 202 ec->key = NULL;
203 } 203 }
204 if (tkey) { 204 if (tkey) {
205 OPENSSL_cleanse(tkey, tkeylen); 205 explicit_bzero(tkey, tkeylen);
206 free(tkey); 206 free(tkey);
207 } 207 }
208 if (ok) 208 if (ok)
diff --git a/src/lib/libssl/src/crypto/cms/cms_env.c b/src/lib/libssl/src/crypto/cms/cms_env.c
index 63b24b6374..e483c4539f 100644
--- a/src/lib/libssl/src/crypto/cms/cms_env.c
+++ b/src/lib/libssl/src/crypto/cms/cms_env.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_env.c,v 1.8 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: cms_env.c,v 1.9 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -406,7 +406,7 @@ cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri)
406 ret = 1; 406 ret = 1;
407 407
408 if (ec->key) { 408 if (ec->key) {
409 OPENSSL_cleanse(ec->key, ec->keylen); 409 explicit_bzero(ec->key, ec->keylen);
410 free(ec->key); 410 free(ec->key);
411 } 411 }
412 412
@@ -654,7 +654,7 @@ cms_RecipientInfo_kekri_encrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri)
654err: 654err:
655 if (!r && wkey) 655 if (!r && wkey)
656 free(wkey); 656 free(wkey);
657 OPENSSL_cleanse(&actx, sizeof(actx)); 657 explicit_bzero(&actx, sizeof(actx));
658 658
659 return r; 659 return r;
660} 660}
@@ -727,7 +727,7 @@ cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri)
727err: 727err:
728 if (!r && ukey) 728 if (!r && ukey)
729 free(ukey); 729 free(ukey);
730 OPENSSL_cleanse(&actx, sizeof(actx)); 730 explicit_bzero(&actx, sizeof(actx));
731 731
732 return r; 732 return r;
733} 733}
@@ -806,7 +806,7 @@ cms_EnvelopedData_init_bio(CMS_ContentInfo *cms)
806err: 806err:
807 ec->cipher = NULL; 807 ec->cipher = NULL;
808 if (ec->key) { 808 if (ec->key) {
809 OPENSSL_cleanse(ec->key, ec->keylen); 809 explicit_bzero(ec->key, ec->keylen);
810 free(ec->key); 810 free(ec->key);
811 ec->key = NULL; 811 ec->key = NULL;
812 ec->keylen = 0; 812 ec->keylen = 0;
diff --git a/src/lib/libssl/src/crypto/cms/cms_pwri.c b/src/lib/libssl/src/crypto/cms/cms_pwri.c
index 11509e3c11..7055ba5d3b 100644
--- a/src/lib/libssl/src/crypto/cms/cms_pwri.c
+++ b/src/lib/libssl/src/crypto/cms/cms_pwri.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_pwri.c,v 1.9 2015/05/15 11:00:14 jsg Exp $ */ 1/* $OpenBSD: cms_pwri.c,v 1.10 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project. 3 * project.
4 */ 4 */
@@ -262,7 +262,7 @@ kek_unwrap_key(unsigned char *out, size_t *outlen, const unsigned char *in,
262 rv = 1; 262 rv = 1;
263 263
264err: 264err:
265 OPENSSL_cleanse(tmp, inlen); 265 explicit_bzero(tmp, inlen);
266 free(tmp); 266 free(tmp);
267 return rv; 267 return rv;
268} 268}
diff --git a/src/lib/libssl/src/crypto/des/str2key.c b/src/lib/libssl/src/crypto/des/str2key.c
index 8999eb292a..ce17e2659b 100644
--- a/src/lib/libssl/src/crypto/des/str2key.c
+++ b/src/lib/libssl/src/crypto/des/str2key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: str2key.c,v 1.9 2014/10/28 07:35:58 jsg Exp $ */ 1/* $OpenBSD: str2key.c,v 1.10 2015/09/10 15:56:25 jsing 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 *
@@ -95,7 +95,7 @@ void DES_string_to_key(const char *str, DES_cblock *key)
95 DES_set_key_unchecked(key,&ks); 95 DES_set_key_unchecked(key,&ks);
96#endif 96#endif
97 DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key); 97 DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key);
98 OPENSSL_cleanse(&ks,sizeof(ks)); 98 explicit_bzero(&ks,sizeof(ks));
99 DES_set_odd_parity(key); 99 DES_set_odd_parity(key);
100 } 100 }
101 101
@@ -168,7 +168,7 @@ void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
168 DES_set_key_unchecked(key2,&ks); 168 DES_set_key_unchecked(key2,&ks);
169#endif 169#endif
170 DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2); 170 DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2);
171 OPENSSL_cleanse(&ks,sizeof(ks)); 171 explicit_bzero(&ks,sizeof(ks));
172 DES_set_odd_parity(key1); 172 DES_set_odd_parity(key1);
173 DES_set_odd_parity(key2); 173 DES_set_odd_parity(key2);
174 } 174 }
diff --git a/src/lib/libssl/src/crypto/ec/ec_key.c b/src/lib/libssl/src/crypto/ec/ec_key.c
index 45192c3231..fa962e4d0f 100644
--- a/src/lib/libssl/src/crypto/ec/ec_key.c
+++ b/src/lib/libssl/src/crypto/ec/ec_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_key.c,v 1.11 2015/02/09 15:49:22 jsing Exp $ */ 1/* $OpenBSD: ec_key.c,v 1.12 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -122,7 +122,7 @@ EC_KEY_free(EC_KEY * r)
122 122
123 EC_EX_DATA_free_all_data(&r->method_data); 123 EC_EX_DATA_free_all_data(&r->method_data);
124 124
125 OPENSSL_cleanse((void *) r, sizeof(EC_KEY)); 125 explicit_bzero((void *) r, sizeof(EC_KEY));
126 126
127 free(r); 127 free(r);
128} 128}
diff --git a/src/lib/libssl/src/crypto/ec/ec_lib.c b/src/lib/libssl/src/crypto/ec/ec_lib.c
index a12a2ffbb6..c28ab18fc0 100644
--- a/src/lib/libssl/src/crypto/ec/ec_lib.c
+++ b/src/lib/libssl/src/crypto/ec/ec_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_lib.c,v 1.18 2015/05/20 04:33:35 miod Exp $ */ 1/* $OpenBSD: ec_lib.c,v 1.19 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -152,10 +152,10 @@ EC_GROUP_clear_free(EC_GROUP * group)
152 BN_clear_free(&group->cofactor); 152 BN_clear_free(&group->cofactor);
153 153
154 if (group->seed) { 154 if (group->seed) {
155 OPENSSL_cleanse(group->seed, group->seed_len); 155 explicit_bzero(group->seed, group->seed_len);
156 free(group->seed); 156 free(group->seed);
157 } 157 }
158 OPENSSL_cleanse(group, sizeof *group); 158 explicit_bzero(group, sizeof *group);
159 free(group); 159 free(group);
160} 160}
161 161
@@ -754,7 +754,7 @@ EC_POINT_clear_free(EC_POINT * point)
754 point->meth->point_clear_finish(point); 754 point->meth->point_clear_finish(point);
755 else if (point->meth->point_finish != 0) 755 else if (point->meth->point_finish != 0)
756 point->meth->point_finish(point); 756 point->meth->point_finish(point);
757 OPENSSL_cleanse(point, sizeof *point); 757 explicit_bzero(point, sizeof *point);
758 free(point); 758 free(point);
759} 759}
760 760
diff --git a/src/lib/libssl/src/crypto/ec/ec_mult.c b/src/lib/libssl/src/crypto/ec/ec_mult.c
index 68f55cfcb3..e428ac586b 100644
--- a/src/lib/libssl/src/crypto/ec/ec_mult.c
+++ b/src/lib/libssl/src/crypto/ec/ec_mult.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_mult.c,v 1.18 2015/02/15 08:44:35 miod Exp $ */ 1/* $OpenBSD: ec_mult.c,v 1.19 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project. 3 * Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -173,11 +173,11 @@ ec_pre_comp_clear_free(void *pre_)
173 173
174 for (p = pre->points; *p != NULL; p++) { 174 for (p = pre->points; *p != NULL; p++) {
175 EC_POINT_clear_free(*p); 175 EC_POINT_clear_free(*p);
176 OPENSSL_cleanse(p, sizeof *p); 176 explicit_bzero(p, sizeof *p);
177 } 177 }
178 free(pre->points); 178 free(pre->points);
179 } 179 }
180 OPENSSL_cleanse(pre, sizeof *pre); 180 explicit_bzero(pre, sizeof *pre);
181 free(pre); 181 free(pre);
182} 182}
183 183
diff --git a/src/lib/libssl/src/crypto/ec/ecp_nistp224.c b/src/lib/libssl/src/crypto/ec/ecp_nistp224.c
index d29113045a..0976f24a9f 100644
--- a/src/lib/libssl/src/crypto/ec/ecp_nistp224.c
+++ b/src/lib/libssl/src/crypto/ec/ecp_nistp224.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp224.c,v 1.16 2015/02/08 22:25:03 miod Exp $ */ 1/* $OpenBSD: ecp_nistp224.c,v 1.17 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Written by Emilia Kasper (Google) for the OpenSSL project. 3 * Written by Emilia Kasper (Google) for the OpenSSL project.
4 */ 4 */
@@ -1239,7 +1239,7 @@ nistp224_pre_comp_clear_free(void *pre_)
1239 if (i > 0) 1239 if (i > 0)
1240 return; 1240 return;
1241 1241
1242 OPENSSL_cleanse(pre, sizeof *pre); 1242 explicit_bzero(pre, sizeof *pre);
1243 free(pre); 1243 free(pre);
1244} 1244}
1245 1245
diff --git a/src/lib/libssl/src/crypto/ec/ecp_nistp256.c b/src/lib/libssl/src/crypto/ec/ecp_nistp256.c
index 23a2131980..be1d2a5402 100644
--- a/src/lib/libssl/src/crypto/ec/ecp_nistp256.c
+++ b/src/lib/libssl/src/crypto/ec/ecp_nistp256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp256.c,v 1.15 2015/02/08 22:25:03 miod Exp $ */ 1/* $OpenBSD: ecp_nistp256.c,v 1.16 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Written by Adam Langley (Google) for the OpenSSL project 3 * Written by Adam Langley (Google) for the OpenSSL project
4 */ 4 */
@@ -1788,7 +1788,7 @@ nistp256_pre_comp_clear_free(void *pre_)
1788 if (i > 0) 1788 if (i > 0)
1789 return; 1789 return;
1790 1790
1791 OPENSSL_cleanse(pre, sizeof *pre); 1791 explicit_bzero(pre, sizeof *pre);
1792 free(pre); 1792 free(pre);
1793} 1793}
1794 1794
diff --git a/src/lib/libssl/src/crypto/ec/ecp_nistp521.c b/src/lib/libssl/src/crypto/ec/ecp_nistp521.c
index 6382091cf9..cfa13b41f8 100644
--- a/src/lib/libssl/src/crypto/ec/ecp_nistp521.c
+++ b/src/lib/libssl/src/crypto/ec/ecp_nistp521.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nistp521.c,v 1.16 2015/02/08 22:25:03 miod Exp $ */ 1/* $OpenBSD: ecp_nistp521.c,v 1.17 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Written by Adam Langley (Google) for the OpenSSL project 3 * Written by Adam Langley (Google) for the OpenSSL project
4 */ 4 */
@@ -1679,7 +1679,7 @@ nistp521_pre_comp_clear_free(void *pre_)
1679 if (i > 0) 1679 if (i > 0)
1680 return; 1680 return;
1681 1681
1682 OPENSSL_cleanse(pre, sizeof(*pre)); 1682 explicit_bzero(pre, sizeof(*pre));
1683 free(pre); 1683 free(pre);
1684} 1684}
1685 1685
diff --git a/src/lib/libssl/src/crypto/ecdh/ech_lib.c b/src/lib/libssl/src/crypto/ecdh/ech_lib.c
index 43c4f8ce31..58dddf638f 100644
--- a/src/lib/libssl/src/crypto/ecdh/ech_lib.c
+++ b/src/lib/libssl/src/crypto/ecdh/ech_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ech_lib.c,v 1.8 2015/02/07 13:19:15 doug Exp $ */ 1/* $OpenBSD: ech_lib.c,v 1.9 2015/09/10 15:56:25 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -180,7 +180,7 @@ void ecdh_data_free(void *data)
180 180
181 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDH, r, &r->ex_data); 181 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDH, r, &r->ex_data);
182 182
183 OPENSSL_cleanse((void *)r, sizeof(ECDH_DATA)); 183 explicit_bzero((void *)r, sizeof(ECDH_DATA));
184 184
185 free(r); 185 free(r);
186 } 186 }
diff --git a/src/lib/libssl/src/crypto/ecdsa/ecs_lib.c b/src/lib/libssl/src/crypto/ecdsa/ecs_lib.c
index dba888cb48..1ba788b4f0 100644
--- a/src/lib/libssl/src/crypto/ecdsa/ecs_lib.c
+++ b/src/lib/libssl/src/crypto/ecdsa/ecs_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecs_lib.c,v 1.9 2015/02/08 13:35:07 jsing Exp $ */ 1/* $OpenBSD: ecs_lib.c,v 1.10 2015/09/10 15:56:25 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -170,7 +170,7 @@ ecdsa_data_free(void *data)
170#endif 170#endif
171 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDSA, r, &r->ex_data); 171 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDSA, r, &r->ex_data);
172 172
173 OPENSSL_cleanse((void *)r, sizeof(ECDSA_DATA)); 173 explicit_bzero((void *)r, sizeof(ECDSA_DATA));
174 174
175 free(r); 175 free(r);
176} 176}
diff --git a/src/lib/libssl/src/crypto/evp/bio_enc.c b/src/lib/libssl/src/crypto/evp/bio_enc.c
index e367faa967..1920c6d180 100644
--- a/src/lib/libssl/src/crypto/evp/bio_enc.c
+++ b/src/lib/libssl/src/crypto/evp/bio_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_enc.c,v 1.18 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: bio_enc.c,v 1.19 2015/09/10 15:56:25 jsing 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,7 +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 OPENSSL_cleanse(a->ptr, sizeof(BIO_ENC_CTX)); 138 explicit_bzero(a->ptr, sizeof(BIO_ENC_CTX));
139 free(a->ptr); 139 free(a->ptr);
140 a->ptr = NULL; 140 a->ptr = NULL;
141 a->init = 0; 141 a->init = 0;
diff --git a/src/lib/libssl/src/crypto/evp/e_aes.c b/src/lib/libssl/src/crypto/evp/e_aes.c
index 0a9455a5d2..a6d48085c3 100644
--- a/src/lib/libssl/src/crypto/evp/e_aes.c
+++ b/src/lib/libssl/src/crypto/evp/e_aes.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_aes.c,v 1.28 2015/06/20 12:01:14 jsing Exp $ */ 1/* $OpenBSD: e_aes.c,v 1.29 2015/09/10 15:56:25 jsing 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 *
@@ -690,7 +690,7 @@ aes_gcm_cleanup(EVP_CIPHER_CTX *c)
690 690
691 if (gctx->iv != c->iv) 691 if (gctx->iv != c->iv)
692 free(gctx->iv); 692 free(gctx->iv);
693 OPENSSL_cleanse(gctx, sizeof(*gctx)); 693 explicit_bzero(gctx, sizeof(*gctx));
694 return 1; 694 return 1;
695} 695}
696 696
@@ -972,7 +972,7 @@ aes_gcm_tls_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
972 972
973 /* If tag mismatch wipe buffer */ 973 /* If tag mismatch wipe buffer */
974 if (memcmp(ctx->buf, in + len, EVP_GCM_TLS_TAG_LEN)) { 974 if (memcmp(ctx->buf, in + len, EVP_GCM_TLS_TAG_LEN)) {
975 OPENSSL_cleanse(out, len); 975 explicit_bzero(out, len);
976 goto err; 976 goto err;
977 } 977 }
978 rv = len; 978 rv = len;
@@ -1339,7 +1339,7 @@ aes_ccm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
1339 } 1339 }
1340 } 1340 }
1341 if (rv == -1) 1341 if (rv == -1)
1342 OPENSSL_cleanse(out, len); 1342 explicit_bzero(out, len);
1343 cctx->iv_set = 0; 1343 cctx->iv_set = 0;
1344 cctx->tag_set = 0; 1344 cctx->tag_set = 0;
1345 cctx->len_set = 0; 1345 cctx->len_set = 0;
@@ -1417,7 +1417,7 @@ aead_aes_gcm_cleanup(EVP_AEAD_CTX *ctx)
1417{ 1417{
1418 struct aead_aes_gcm_ctx *gcm_ctx = ctx->aead_state; 1418 struct aead_aes_gcm_ctx *gcm_ctx = ctx->aead_state;
1419 1419
1420 OPENSSL_cleanse(gcm_ctx, sizeof(*gcm_ctx)); 1420 explicit_bzero(gcm_ctx, sizeof(*gcm_ctx));
1421 free(gcm_ctx); 1421 free(gcm_ctx);
1422} 1422}
1423 1423
diff --git a/src/lib/libssl/src/crypto/evp/e_aes_cbc_hmac_sha1.c b/src/lib/libssl/src/crypto/evp/e_aes_cbc_hmac_sha1.c
index 7c23face34..c76c2b1c52 100644
--- a/src/lib/libssl/src/crypto/evp/e_aes_cbc_hmac_sha1.c
+++ b/src/lib/libssl/src/crypto/evp/e_aes_cbc_hmac_sha1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_aes_cbc_hmac_sha1.c,v 1.8 2014/07/12 20:37:07 miod Exp $ */ 1/* $OpenBSD: e_aes_cbc_hmac_sha1.c,v 1.9 2015/09/10 15:56:25 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2011-2013 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2011-2013 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -502,7 +502,7 @@ aesni_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
502 SHA1_Init(&key->tail); 502 SHA1_Init(&key->tail);
503 SHA1_Update(&key->tail, hmac_key, sizeof(hmac_key)); 503 SHA1_Update(&key->tail, hmac_key, sizeof(hmac_key));
504 504
505 OPENSSL_cleanse(hmac_key, sizeof(hmac_key)); 505 explicit_bzero(hmac_key, sizeof(hmac_key));
506 506
507 return 1; 507 return 1;
508 } 508 }
diff --git a/src/lib/libssl/src/crypto/evp/e_chacha20poly1305.c b/src/lib/libssl/src/crypto/evp/e_chacha20poly1305.c
index c003b0ba7f..9deb40b72a 100644
--- a/src/lib/libssl/src/crypto/evp/e_chacha20poly1305.c
+++ b/src/lib/libssl/src/crypto/evp/e_chacha20poly1305.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_chacha20poly1305.c,v 1.9 2015/06/20 12:01:14 jsing Exp $ */ 1/* $OpenBSD: e_chacha20poly1305.c,v 1.10 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014, Google Inc. 3 * Copyright (c) 2014, Google Inc.
4 * 4 *
@@ -71,7 +71,7 @@ aead_chacha20_poly1305_cleanup(EVP_AEAD_CTX *ctx)
71{ 71{
72 struct aead_chacha20_poly1305_ctx *c20_ctx = ctx->aead_state; 72 struct aead_chacha20_poly1305_ctx *c20_ctx = ctx->aead_state;
73 73
74 OPENSSL_cleanse(c20_ctx->key, sizeof(c20_ctx->key)); 74 explicit_bzero(c20_ctx->key, sizeof(c20_ctx->key));
75 free(c20_ctx); 75 free(c20_ctx);
76} 76}
77 77
diff --git a/src/lib/libssl/src/crypto/evp/e_idea.c b/src/lib/libssl/src/crypto/evp/e_idea.c
index 3ba4dbcdb9..454ad4e672 100644
--- a/src/lib/libssl/src/crypto/evp/e_idea.c
+++ b/src/lib/libssl/src/crypto/evp/e_idea.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: e_idea.c,v 1.9 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: e_idea.c,v 1.10 2015/09/10 15:56:25 jsing 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 *
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/opensslconf.h> 62#include <openssl/opensslconf.h>
62 63
@@ -115,7 +116,7 @@ idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
115 116
116 idea_set_encrypt_key(key, &tmp); 117 idea_set_encrypt_key(key, &tmp);
117 idea_set_decrypt_key(&tmp, ctx->cipher_data); 118 idea_set_decrypt_key(&tmp, ctx->cipher_data);
118 OPENSSL_cleanse((unsigned char *)&tmp, 119 explicit_bzero((unsigned char *)&tmp,
119 sizeof(IDEA_KEY_SCHEDULE)); 120 sizeof(IDEA_KEY_SCHEDULE));
120 } 121 }
121 return 1; 122 return 1;
diff --git a/src/lib/libssl/src/crypto/evp/evp_enc.c b/src/lib/libssl/src/crypto/evp/evp_enc.c
index 42ccfceec9..99bf59e05f 100644
--- a/src/lib/libssl/src/crypto/evp/evp_enc.c
+++ b/src/lib/libssl/src/crypto/evp/evp_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_enc.c,v 1.26 2015/02/10 09:52:35 miod Exp $ */ 1/* $OpenBSD: evp_enc.c,v 1.27 2015/09/10 15:56:25 jsing 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 *
@@ -562,7 +562,7 @@ EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
562 return 0; 562 return 0;
563 /* Cleanse cipher context data */ 563 /* Cleanse cipher context data */
564 if (c->cipher_data) 564 if (c->cipher_data)
565 OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size); 565 explicit_bzero(c->cipher_data, c->cipher->ctx_size);
566 } 566 }
567 free(c->cipher_data); 567 free(c->cipher_data);
568#ifndef OPENSSL_NO_ENGINE 568#ifndef OPENSSL_NO_ENGINE
diff --git a/src/lib/libssl/src/crypto/evp/evp_key.c b/src/lib/libssl/src/crypto/evp/evp_key.c
index 0678536ccb..2c76743e42 100644
--- a/src/lib/libssl/src/crypto/evp/evp_key.c
+++ b/src/lib/libssl/src/crypto/evp/evp_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_key.c,v 1.22 2015/02/10 09:55:39 miod Exp $ */ 1/* $OpenBSD: evp_key.c,v 1.23 2015/09/10 15:56:25 jsing 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 *
@@ -116,7 +116,7 @@ EVP_read_pw_string_min(char *buf, int min, int len, const char *prompt,
116 } 116 }
117 ret = UI_process(ui); 117 ret = UI_process(ui);
118 UI_free(ui); 118 UI_free(ui);
119 OPENSSL_cleanse(buff, BUFSIZ); 119 explicit_bzero(buff, BUFSIZ);
120 return ret; 120 return ret;
121} 121}
122 122
@@ -201,6 +201,6 @@ EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md,
201 201
202err: 202err:
203 EVP_MD_CTX_cleanup(&c); 203 EVP_MD_CTX_cleanup(&c);
204 OPENSSL_cleanse(md_buf, sizeof md_buf); 204 explicit_bzero(md_buf, sizeof md_buf);
205 return rv; 205 return rv;
206} 206}
diff --git a/src/lib/libssl/src/crypto/evp/p5_crpt.c b/src/lib/libssl/src/crypto/evp/p5_crpt.c
index 112a69114c..626910fd7a 100644
--- a/src/lib/libssl/src/crypto/evp/p5_crpt.c
+++ b/src/lib/libssl/src/crypto/evp/p5_crpt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p5_crpt.c,v 1.15 2015/02/10 09:52:35 miod Exp $ */ 1/* $OpenBSD: p5_crpt.c,v 1.16 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -147,9 +147,9 @@ PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
147 EVP_CIPHER_iv_length(cipher)); 147 EVP_CIPHER_iv_length(cipher));
148 if (!EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de)) 148 if (!EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de))
149 goto err; 149 goto err;
150 OPENSSL_cleanse(md_tmp, EVP_MAX_MD_SIZE); 150 explicit_bzero(md_tmp, EVP_MAX_MD_SIZE);
151 OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH); 151 explicit_bzero(key, EVP_MAX_KEY_LENGTH);
152 OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH); 152 explicit_bzero(iv, EVP_MAX_IV_LENGTH);
153 rv = 1; 153 rv = 1;
154err: 154err:
155 EVP_MD_CTX_cleanup(&ctx); 155 EVP_MD_CTX_cleanup(&ctx);
diff --git a/src/lib/libssl/src/crypto/evp/p5_crpt2.c b/src/lib/libssl/src/crypto/evp/p5_crpt2.c
index afafb9551f..632c2c76ce 100644
--- a/src/lib/libssl/src/crypto/evp/p5_crpt2.c
+++ b/src/lib/libssl/src/crypto/evp/p5_crpt2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p5_crpt2.c,v 1.20 2015/02/14 15:49:51 miod Exp $ */ 1/* $OpenBSD: p5_crpt2.c,v 1.21 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -300,7 +300,7 @@ PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
300 rv = EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de); 300 rv = EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de);
301 301
302err: 302err:
303 OPENSSL_cleanse(key, keylen); 303 explicit_bzero(key, keylen);
304 PBKDF2PARAM_free(kdf); 304 PBKDF2PARAM_free(kdf);
305 return rv; 305 return rv;
306} 306}
diff --git a/src/lib/libssl/src/crypto/evp/p_open.c b/src/lib/libssl/src/crypto/evp/p_open.c
index aca83e74f6..002a6dea70 100644
--- a/src/lib/libssl/src/crypto/evp/p_open.c
+++ b/src/lib/libssl/src/crypto/evp/p_open.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_open.c,v 1.16 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: p_open.c,v 1.17 2015/09/10 15:56:25 jsing 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 *
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/opensslconf.h> 62#include <openssl/opensslconf.h>
62 63
@@ -109,7 +110,7 @@ EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
109 110
110err: 111err:
111 if (key != NULL) 112 if (key != NULL)
112 OPENSSL_cleanse(key, size); 113 explicit_bzero(key, size);
113 free(key); 114 free(key);
114 return (ret); 115 return (ret);
115} 116}
diff --git a/src/lib/libssl/src/crypto/gost/gost2814789.c b/src/lib/libssl/src/crypto/gost/gost2814789.c
index b1bef9eae3..e285413ed4 100644
--- a/src/lib/libssl/src/crypto/gost/gost2814789.c
+++ b/src/lib/libssl/src/crypto/gost/gost2814789.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gost2814789.c,v 1.4 2015/02/10 09:46:30 miod Exp $ */ 1/* $OpenBSD: gost2814789.c,v 1.5 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -464,7 +464,7 @@ GOST2814789IMIT(const unsigned char *d, size_t n, unsigned char *md, int nid,
464 Gost2814789_set_key(&c.cipher, key, 256); 464 Gost2814789_set_key(&c.cipher, key, 256);
465 GOST2814789IMIT_Update(&c, d, n); 465 GOST2814789IMIT_Update(&c, d, n);
466 GOST2814789IMIT_Final(md, &c); 466 GOST2814789IMIT_Final(md, &c);
467 OPENSSL_cleanse(&c, sizeof(c)); 467 explicit_bzero(&c, sizeof(c));
468 return (md); 468 return (md);
469} 469}
470 470
diff --git a/src/lib/libssl/src/crypto/gost/gostr341001_key.c b/src/lib/libssl/src/crypto/gost/gostr341001_key.c
index dbe360620a..894a189e3b 100644
--- a/src/lib/libssl/src/crypto/gost/gostr341001_key.c
+++ b/src/lib/libssl/src/crypto/gost/gostr341001_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gostr341001_key.c,v 1.5 2015/02/14 06:40:04 jsing Exp $ */ 1/* $OpenBSD: gostr341001_key.c,v 1.6 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -49,6 +49,8 @@
49 * ==================================================================== 49 * ====================================================================
50 */ 50 */
51 51
52#include <string.h>
53
52#include <openssl/opensslconf.h> 54#include <openssl/opensslconf.h>
53 55
54#ifndef OPENSSL_NO_GOST 56#ifndef OPENSSL_NO_GOST
@@ -103,7 +105,7 @@ GOST_KEY_free(GOST_KEY *r)
103 EC_POINT_free(r->pub_key); 105 EC_POINT_free(r->pub_key);
104 BN_clear_free(r->priv_key); 106 BN_clear_free(r->priv_key);
105 107
106 OPENSSL_cleanse((void *)r, sizeof(GOST_KEY)); 108 explicit_bzero((void *)r, sizeof(GOST_KEY));
107 free(r); 109 free(r);
108} 110}
109 111
diff --git a/src/lib/libssl/src/crypto/gost/gostr341194.c b/src/lib/libssl/src/crypto/gost/gostr341194.c
index 32c166aefa..2a462185aa 100644
--- a/src/lib/libssl/src/crypto/gost/gostr341194.c
+++ b/src/lib/libssl/src/crypto/gost/gostr341194.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gostr341194.c,v 1.4 2015/07/15 17:13:17 beck Exp $ */ 1/* $OpenBSD: gostr341194.c,v 1.5 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -267,7 +267,7 @@ GOSTR341194(const unsigned char *d, size_t n, unsigned char *md, int nid)
267 return 0; 267 return 0;
268 GOSTR341194_Update(&c, d, n); 268 GOSTR341194_Update(&c, d, n);
269 GOSTR341194_Final(md, &c); 269 GOSTR341194_Final(md, &c);
270 OPENSSL_cleanse(&c, sizeof(c)); 270 explicit_bzero(&c, sizeof(c));
271 return (md); 271 return (md);
272} 272}
273#endif 273#endif
diff --git a/src/lib/libssl/src/crypto/gost/streebog.c b/src/lib/libssl/src/crypto/gost/streebog.c
index 8060161d11..902472bd9e 100644
--- a/src/lib/libssl/src/crypto/gost/streebog.c
+++ b/src/lib/libssl/src/crypto/gost/streebog.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: streebog.c,v 1.4 2014/12/07 16:33:51 jsing Exp $ */ 1/* $OpenBSD: streebog.c,v 1.5 2015/09/10 15:56:25 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -1455,7 +1455,7 @@ STREEBOG256(const unsigned char *d, size_t n, unsigned char *md)
1455 STREEBOG256_Init(&c); 1455 STREEBOG256_Init(&c);
1456 STREEBOG256_Update(&c, d, n); 1456 STREEBOG256_Update(&c, d, n);
1457 STREEBOG256_Final(md, &c); 1457 STREEBOG256_Final(md, &c);
1458 OPENSSL_cleanse(&c, sizeof(c)); 1458 explicit_bzero(&c, sizeof(c));
1459 return (md); 1459 return (md);
1460} 1460}
1461 1461
@@ -1470,7 +1470,7 @@ STREEBOG512(const unsigned char *d, size_t n, unsigned char *md)
1470 STREEBOG512_Init(&c); 1470 STREEBOG512_Init(&c);
1471 STREEBOG512_Update(&c, d, n); 1471 STREEBOG512_Update(&c, d, n);
1472 STREEBOG512_Final(md, &c); 1472 STREEBOG512_Final(md, &c);
1473 OPENSSL_cleanse(&c, sizeof(c)); 1473 explicit_bzero(&c, sizeof(c));
1474 return (md); 1474 return (md);
1475} 1475}
1476 1476
diff --git a/src/lib/libssl/src/crypto/hmac/hm_ameth.c b/src/lib/libssl/src/crypto/hmac/hm_ameth.c
index da3471c4fd..cfa0239705 100644
--- a/src/lib/libssl/src/crypto/hmac/hm_ameth.c
+++ b/src/lib/libssl/src/crypto/hmac/hm_ameth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hm_ameth.c,v 1.9 2015/07/20 15:45:29 miod Exp $ */ 1/* $OpenBSD: hm_ameth.c,v 1.10 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2007. 3 * project 2007.
4 */ 4 */
@@ -83,7 +83,7 @@ hmac_key_free(EVP_PKEY *pkey)
83 83
84 if (os) { 84 if (os) {
85 if (os->data) 85 if (os->data)
86 OPENSSL_cleanse(os->data, os->length); 86 explicit_bzero(os->data, os->length);
87 ASN1_OCTET_STRING_free(os); 87 ASN1_OCTET_STRING_free(os);
88 } 88 }
89} 89}
diff --git a/src/lib/libssl/src/crypto/hmac/hm_pmeth.c b/src/lib/libssl/src/crypto/hmac/hm_pmeth.c
index 255f4ece8b..c5ac6c00c0 100644
--- a/src/lib/libssl/src/crypto/hmac/hm_pmeth.c
+++ b/src/lib/libssl/src/crypto/hmac/hm_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hm_pmeth.c,v 1.8 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: hm_pmeth.c,v 1.9 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2007. 3 * project 2007.
4 */ 4 */
@@ -124,7 +124,7 @@ pkey_hmac_cleanup(EVP_PKEY_CTX *ctx)
124 HMAC_CTX_cleanup(&hctx->ctx); 124 HMAC_CTX_cleanup(&hctx->ctx);
125 if (hctx->ktmp.data) { 125 if (hctx->ktmp.data) {
126 if (hctx->ktmp.length) 126 if (hctx->ktmp.length)
127 OPENSSL_cleanse(hctx->ktmp.data, hctx->ktmp.length); 127 explicit_bzero(hctx->ktmp.data, hctx->ktmp.length);
128 free(hctx->ktmp.data); 128 free(hctx->ktmp.data);
129 hctx->ktmp.data = NULL; 129 hctx->ktmp.data = NULL;
130 } 130 }
diff --git a/src/lib/libssl/src/crypto/md4/md4_one.c b/src/lib/libssl/src/crypto/md4/md4_one.c
index 144f131914..9577d6577b 100644
--- a/src/lib/libssl/src/crypto/md4/md4_one.c
+++ b/src/lib/libssl/src/crypto/md4/md4_one.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: md4_one.c,v 1.7 2015/09/10 15:03:58 jsing Exp $ */ 1/* $OpenBSD: md4_one.c,v 1.8 2015/09/10 15:56:25 jsing 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 *
@@ -71,7 +71,7 @@ unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md)
71 return NULL; 71 return NULL;
72 MD4_Update(&c,d,n); 72 MD4_Update(&c,d,n);
73 MD4_Final(md,&c); 73 MD4_Final(md,&c);
74 OPENSSL_cleanse(&c,sizeof(c)); 74 explicit_bzero(&c,sizeof(c));
75 return(md); 75 return(md);
76 } 76 }
77 77
diff --git a/src/lib/libssl/src/crypto/md5/md5_one.c b/src/lib/libssl/src/crypto/md5/md5_one.c
index f4cc56adb2..3fb05de30c 100644
--- a/src/lib/libssl/src/crypto/md5/md5_one.c
+++ b/src/lib/libssl/src/crypto/md5/md5_one.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: md5_one.c,v 1.9 2015/09/10 15:03:59 jsing Exp $ */ 1/* $OpenBSD: md5_one.c,v 1.10 2015/09/10 15:56:25 jsing 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 *
@@ -71,7 +71,7 @@ unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md)
71 return NULL; 71 return NULL;
72 MD5_Update(&c,d,n); 72 MD5_Update(&c,d,n);
73 MD5_Final(md,&c); 73 MD5_Final(md,&c);
74 OPENSSL_cleanse(&c,sizeof(c)); 74 explicit_bzero(&c,sizeof(c));
75 return(md); 75 return(md);
76 } 76 }
77 77
diff --git a/src/lib/libssl/src/crypto/modes/gcm128.c b/src/lib/libssl/src/crypto/modes/gcm128.c
index 4a72901a33..dd6d91e880 100644
--- a/src/lib/libssl/src/crypto/modes/gcm128.c
+++ b/src/lib/libssl/src/crypto/modes/gcm128.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: gcm128.c,v 1.12 2015/02/10 09:46:30 miod Exp $ */ 1/* $OpenBSD: gcm128.c,v 1.13 2015/09/10 15:56:25 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2010 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2010 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -1533,7 +1533,7 @@ GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block)
1533void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx) 1533void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx)
1534{ 1534{
1535 if (ctx) { 1535 if (ctx) {
1536 OPENSSL_cleanse(ctx,sizeof(*ctx)); 1536 explicit_bzero(ctx,sizeof(*ctx));
1537 free(ctx); 1537 free(ctx);
1538 } 1538 }
1539} 1539}
diff --git a/src/lib/libssl/src/crypto/pem/pem_info.c b/src/lib/libssl/src/crypto/pem/pem_info.c
index 6fe72ce742..191e3b5b10 100644
--- a/src/lib/libssl/src/crypto/pem/pem_info.c
+++ b/src/lib/libssl/src/crypto/pem/pem_info.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_info.c,v 1.20 2015/02/10 09:52:35 miod Exp $ */ 1/* $OpenBSD: pem_info.c,v 1.21 2015/09/10 15:56:25 jsing 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 *
@@ -400,7 +400,7 @@ PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
400 ret = 1; 400 ret = 1;
401 401
402err: 402err:
403 OPENSSL_cleanse((char *)&ctx, sizeof(ctx)); 403 explicit_bzero((char *)&ctx, sizeof(ctx));
404 OPENSSL_cleanse(buf, PEM_BUFSIZE); 404 explicit_bzero(buf, PEM_BUFSIZE);
405 return (ret); 405 return (ret);
406} 406}
diff --git a/src/lib/libssl/src/crypto/pem/pem_lib.c b/src/lib/libssl/src/crypto/pem/pem_lib.c
index 6f8759a9ee..852b0eaf86 100644
--- a/src/lib/libssl/src/crypto/pem/pem_lib.c
+++ b/src/lib/libssl/src/crypto/pem/pem_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_lib.c,v 1.41 2015/07/19 18:29:31 miod Exp $ */ 1/* $OpenBSD: pem_lib.c,v 1.42 2015/09/10 15:56:25 jsing 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 *
@@ -403,7 +403,7 @@ PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x,
403 goto err; 403 goto err;
404 404
405 if (kstr == (unsigned char *)buf) 405 if (kstr == (unsigned char *)buf)
406 OPENSSL_cleanse(buf, PEM_BUFSIZE); 406 explicit_bzero(buf, PEM_BUFSIZE);
407 407
408 if (strlen(objstr) + 23 + 2 * enc->iv_len + 13 > sizeof buf) { 408 if (strlen(objstr) + 23 + 2 * enc->iv_len + 13 > sizeof buf) {
409 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO, 409 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,
@@ -434,12 +434,12 @@ PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x,
434 if (i <= 0) 434 if (i <= 0)
435 ret = 0; 435 ret = 0;
436err: 436err:
437 OPENSSL_cleanse(key, sizeof(key)); 437 explicit_bzero(key, sizeof(key));
438 OPENSSL_cleanse(iv, sizeof(iv)); 438 explicit_bzero(iv, sizeof(iv));
439 OPENSSL_cleanse((char *)&ctx, sizeof(ctx)); 439 explicit_bzero((char *)&ctx, sizeof(ctx));
440 OPENSSL_cleanse(buf, PEM_BUFSIZE); 440 explicit_bzero(buf, PEM_BUFSIZE);
441 if (data != NULL) { 441 if (data != NULL) {
442 OPENSSL_cleanse(data, (unsigned int)dsize); 442 explicit_bzero(data, (unsigned int)dsize);
443 free(data); 443 free(data);
444 } 444 }
445 return (ret); 445 return (ret);
@@ -480,8 +480,8 @@ PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen,
480 if (o) 480 if (o)
481 o = EVP_DecryptFinal_ex(&ctx, &(data[i]), &j); 481 o = EVP_DecryptFinal_ex(&ctx, &(data[i]), &j);
482 EVP_CIPHER_CTX_cleanup(&ctx); 482 EVP_CIPHER_CTX_cleanup(&ctx);
483 OPENSSL_cleanse((char *)buf, sizeof(buf)); 483 explicit_bzero((char *)buf, sizeof(buf));
484 OPENSSL_cleanse((char *)key, sizeof(key)); 484 explicit_bzero((char *)key, sizeof(key));
485 if (!o) { 485 if (!o) {
486 PEMerr(PEM_F_PEM_DO_HEADER, PEM_R_BAD_DECRYPT); 486 PEMerr(PEM_F_PEM_DO_HEADER, PEM_R_BAD_DECRYPT);
487 return (0); 487 return (0);
@@ -640,7 +640,7 @@ PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
640 EVP_EncodeFinal(&ctx, buf, &outl); 640 EVP_EncodeFinal(&ctx, buf, &outl);
641 if ((outl > 0) && (BIO_write(bp, (char *)buf, outl) != outl)) 641 if ((outl > 0) && (BIO_write(bp, (char *)buf, outl) != outl))
642 goto err; 642 goto err;
643 OPENSSL_cleanse(buf, PEM_BUFSIZE * 8); 643 explicit_bzero(buf, PEM_BUFSIZE * 8);
644 free(buf); 644 free(buf);
645 buf = NULL; 645 buf = NULL;
646 if ((BIO_write(bp, "-----END ", 9) != 9) || 646 if ((BIO_write(bp, "-----END ", 9) != 9) ||
@@ -651,7 +651,7 @@ PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
651 651
652err: 652err:
653 if (buf) { 653 if (buf) {
654 OPENSSL_cleanse(buf, PEM_BUFSIZE * 8); 654 explicit_bzero(buf, PEM_BUFSIZE * 8);
655 free(buf); 655 free(buf);
656 } 656 }
657 PEMerr(PEM_F_PEM_WRITE_BIO, reason); 657 PEMerr(PEM_F_PEM_WRITE_BIO, reason);
diff --git a/src/lib/libssl/src/crypto/pem/pem_pk8.c b/src/lib/libssl/src/crypto/pem/pem_pk8.c
index 5b0fcc236b..d02dec1546 100644
--- a/src/lib/libssl/src/crypto/pem/pem_pk8.c
+++ b/src/lib/libssl/src/crypto/pem/pem_pk8.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_pk8.c,v 1.9 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: pem_pk8.c,v 1.10 2015/09/10 15:56:25 jsing 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 *
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/buffer.h> 62#include <openssl/buffer.h>
62#include <openssl/err.h> 63#include <openssl/err.h>
@@ -135,7 +136,7 @@ do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
135 } 136 }
136 p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf); 137 p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf);
137 if (kstr == buf) 138 if (kstr == buf)
138 OPENSSL_cleanse(buf, klen); 139 explicit_bzero(buf, klen);
139 PKCS8_PRIV_KEY_INFO_free(p8inf); 140 PKCS8_PRIV_KEY_INFO_free(p8inf);
140 if (isder) 141 if (isder)
141 ret = i2d_PKCS8_bio(bp, p8); 142 ret = i2d_PKCS8_bio(bp, p8);
diff --git a/src/lib/libssl/src/crypto/pem/pem_pkey.c b/src/lib/libssl/src/crypto/pem/pem_pkey.c
index e9c0a8b1c9..afb476f818 100644
--- a/src/lib/libssl/src/crypto/pem/pem_pkey.c
+++ b/src/lib/libssl/src/crypto/pem/pem_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_pkey.c,v 1.20 2015/02/11 03:19:37 doug Exp $ */ 1/* $OpenBSD: pem_pkey.c,v 1.21 2015/09/10 15:56:25 jsing 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 *
@@ -144,7 +144,7 @@ p8err:
144 PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY, ERR_R_ASN1_LIB); 144 PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY, ERR_R_ASN1_LIB);
145err: 145err:
146 free(nm); 146 free(nm);
147 OPENSSL_cleanse(data, len); 147 explicit_bzero(data, len);
148 free(data); 148 free(data);
149 return (ret); 149 return (ret);
150} 150}
diff --git a/src/lib/libssl/src/crypto/pem/pem_seal.c b/src/lib/libssl/src/crypto/pem/pem_seal.c
index 08837bd7f7..96687eb77f 100644
--- a/src/lib/libssl/src/crypto/pem/pem_seal.c
+++ b/src/lib/libssl/src/crypto/pem/pem_seal.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_seal.c,v 1.21 2014/10/18 17:20:40 jsing Exp $ */ 1/* $OpenBSD: pem_seal.c,v 1.22 2015/09/10 15:56:25 jsing 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 *
@@ -117,7 +117,7 @@ PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
117 117
118err: 118err:
119 free(s); 119 free(s);
120 OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH); 120 explicit_bzero(key, EVP_MAX_KEY_LENGTH);
121 return (ret); 121 return (ret);
122} 122}
123 123
diff --git a/src/lib/libssl/src/crypto/pem/pvkfmt.c b/src/lib/libssl/src/crypto/pem/pvkfmt.c
index 025381bcc0..f5a9de39fc 100644
--- a/src/lib/libssl/src/crypto/pem/pvkfmt.c
+++ b/src/lib/libssl/src/crypto/pem/pvkfmt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pvkfmt.c,v 1.13 2015/05/15 11:00:14 jsg Exp $ */ 1/* $OpenBSD: pvkfmt.c,v 1.14 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2005. 3 * project 2005.
4 */ 4 */
@@ -765,7 +765,7 @@ do_PVK_body(const unsigned char **in, unsigned int saltlen,
765 if (!EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, 765 if (!EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf,
766 NULL)) 766 NULL))
767 goto err; 767 goto err;
768 OPENSSL_cleanse(keybuf, 20); 768 explicit_bzero(keybuf, 20);
769 if (!EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen)) 769 if (!EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen))
770 goto err; 770 goto err;
771 if (!EVP_DecryptFinal_ex(&cctx, q + enctmplen, 771 if (!EVP_DecryptFinal_ex(&cctx, q + enctmplen,
@@ -777,7 +777,7 @@ do_PVK_body(const unsigned char **in, unsigned int saltlen,
777 goto err; 777 goto err;
778 } 778 }
779 } else 779 } else
780 OPENSSL_cleanse(keybuf, 20); 780 explicit_bzero(keybuf, 20);
781 p = enctmp; 781 p = enctmp;
782 } 782 }
783 783
@@ -823,7 +823,7 @@ b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u)
823 823
824err: 824err:
825 if (buf) { 825 if (buf) {
826 OPENSSL_cleanse(buf, buflen); 826 explicit_bzero(buf, buflen);
827 free(buf); 827 free(buf);
828 } 828 }
829 return ret; 829 return ret;
@@ -894,7 +894,7 @@ i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel, pem_password_cb *cb,
894 p = salt + PVK_SALTLEN + 8; 894 p = salt + PVK_SALTLEN + 8;
895 if (!EVP_EncryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, NULL)) 895 if (!EVP_EncryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, NULL))
896 goto error; 896 goto error;
897 OPENSSL_cleanse(keybuf, 20); 897 explicit_bzero(keybuf, 20);
898 if (!EVP_DecryptUpdate(&cctx, p, &enctmplen, p, pklen - 8)) 898 if (!EVP_DecryptUpdate(&cctx, p, &enctmplen, p, pklen - 8))
899 goto error; 899 goto error;
900 if (!EVP_DecryptFinal_ex(&cctx, p + enctmplen, &enctmplen)) 900 if (!EVP_DecryptFinal_ex(&cctx, p + enctmplen, &enctmplen))
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_crpt.c b/src/lib/libssl/src/crypto/pkcs12/p12_crpt.c
index 288c93c49f..0f215d2fe2 100644
--- a/src/lib/libssl/src/crypto/pkcs12/p12_crpt.c
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_crpt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_crpt.c,v 1.11 2014/07/11 08:44:49 jsing Exp $ */ 1/* $OpenBSD: p12_crpt.c,v 1.12 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/err.h> 62#include <openssl/err.h>
62#include <openssl/pkcs12.h> 63#include <openssl/pkcs12.h>
@@ -111,7 +112,7 @@ PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
111 } 112 }
112 PBEPARAM_free(pbe); 113 PBEPARAM_free(pbe);
113 ret = EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, en_de); 114 ret = EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, en_de);
114 OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH); 115 explicit_bzero(key, EVP_MAX_KEY_LENGTH);
115 OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH); 116 explicit_bzero(iv, EVP_MAX_IV_LENGTH);
116 return ret; 117 return ret;
117} 118}
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_decr.c b/src/lib/libssl/src/crypto/pkcs12/p12_decr.c
index 4cccf43d3f..00195f0a98 100644
--- a/src/lib/libssl/src/crypto/pkcs12/p12_decr.c
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_decr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_decr.c,v 1.15 2015/05/15 11:00:14 jsg Exp $ */ 1/* $OpenBSD: p12_decr.c,v 1.16 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -57,6 +57,7 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h>
60 61
61#include <openssl/err.h> 62#include <openssl/err.h>
62#include <openssl/pkcs12.h> 63#include <openssl/pkcs12.h>
@@ -137,7 +138,7 @@ PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,
137 p = out; 138 p = out;
138 ret = ASN1_item_d2i(NULL, &p, outlen, it); 139 ret = ASN1_item_d2i(NULL, &p, outlen, it);
139 if (zbuf) 140 if (zbuf)
140 OPENSSL_cleanse(out, outlen); 141 explicit_bzero(out, outlen);
141 if (!ret) 142 if (!ret)
142 PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I, 143 PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I,
143 PKCS12_R_DECODE_ERROR); 144 PKCS12_R_DECODE_ERROR);
@@ -176,7 +177,7 @@ PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *it,
176 goto err; 177 goto err;
177 } 178 }
178 if (zbuf) 179 if (zbuf)
179 OPENSSL_cleanse(in, inlen); 180 explicit_bzero(in, inlen);
180 free(in); 181 free(in);
181 return oct; 182 return oct;
182 183
diff --git a/src/lib/libssl/src/crypto/pkcs12/p12_key.c b/src/lib/libssl/src/crypto/pkcs12/p12_key.c
index 0b3547a6fb..38f8a8194c 100644
--- a/src/lib/libssl/src/crypto/pkcs12/p12_key.c
+++ b/src/lib/libssl/src/crypto/pkcs12/p12_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p12_key.c,v 1.22 2015/02/07 13:19:15 doug Exp $ */ 1/* $OpenBSD: p12_key.c,v 1.23 2015/09/10 15:56:25 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 1999. 3 * project 1999.
4 */ 4 */
@@ -89,7 +89,7 @@ PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
89 if (ret <= 0) 89 if (ret <= 0)
90 return 0; 90 return 0;
91 if (unipass) { 91 if (unipass) {
92 OPENSSL_cleanse(unipass, uniplen); 92 explicit_bzero(unipass, uniplen);
93 free(unipass); 93 free(unipass);
94 } 94 }
95 return ret; 95 return ret;
diff --git a/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c b/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c
index 24bcebef61..7755c3c30e 100644
--- a/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c
+++ b/src/lib/libssl/src/crypto/pkcs7/pk7_doit.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_doit.c,v 1.36 2015/07/29 14:58:34 jsing Exp $ */ 1/* $OpenBSD: pk7_doit.c,v 1.37 2015/09/10 15:56:25 jsing 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 *
@@ -233,7 +233,7 @@ pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen, PKCS7_RECIP_INFO *ri,
233 ret = 1; 233 ret = 1;
234 234
235 if (*pek) { 235 if (*pek) {
236 OPENSSL_cleanse(*pek, *peklen); 236 explicit_bzero(*pek, *peklen);
237 free(*pek); 237 free(*pek);
238 } 238 }
239 239
@@ -371,7 +371,7 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio)
371 if (pkcs7_encode_rinfo(ri, key, keylen) <= 0) 371 if (pkcs7_encode_rinfo(ri, key, keylen) <= 0)
372 goto err; 372 goto err;
373 } 373 }
374 OPENSSL_cleanse(key, keylen); 374 explicit_bzero(key, keylen);
375 375
376 if (out == NULL) 376 if (out == NULL)
377 out = btmp; 377 out = btmp;
@@ -588,7 +588,7 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
588 */ 588 */
589 if (!EVP_CIPHER_CTX_set_key_length(evp_ctx, eklen)) { 589 if (!EVP_CIPHER_CTX_set_key_length(evp_ctx, eklen)) {
590 /* Use random key as MMA defence */ 590 /* Use random key as MMA defence */
591 OPENSSL_cleanse(ek, eklen); 591 explicit_bzero(ek, eklen);
592 free(ek); 592 free(ek);
593 ek = tkey; 593 ek = tkey;
594 eklen = tkeylen; 594 eklen = tkeylen;
@@ -601,12 +601,12 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
601 goto err; 601 goto err;
602 602
603 if (ek) { 603 if (ek) {
604 OPENSSL_cleanse(ek, eklen); 604 explicit_bzero(ek, eklen);
605 free(ek); 605 free(ek);
606 ek = NULL; 606 ek = NULL;
607 } 607 }
608 if (tkey) { 608 if (tkey) {
609 OPENSSL_cleanse(tkey, tkeylen); 609 explicit_bzero(tkey, tkeylen);
610 free(tkey); 610 free(tkey);
611 tkey = NULL; 611 tkey = NULL;
612 } 612 }
@@ -635,11 +635,11 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
635 if (0) { 635 if (0) {
636err: 636err:
637 if (ek) { 637 if (ek) {
638 OPENSSL_cleanse(ek, eklen); 638 explicit_bzero(ek, eklen);
639 free(ek); 639 free(ek);
640 } 640 }
641 if (tkey) { 641 if (tkey) {
642 OPENSSL_cleanse(tkey, tkeylen); 642 explicit_bzero(tkey, tkeylen);
643 free(tkey); 643 free(tkey);
644 } 644 }
645 if (out != NULL) 645 if (out != NULL)
diff --git a/src/lib/libssl/src/crypto/rand/randfile.c b/src/lib/libssl/src/crypto/rand/randfile.c
index 6948a83634..72c065c48d 100644
--- a/src/lib/libssl/src/crypto/rand/randfile.c
+++ b/src/lib/libssl/src/crypto/rand/randfile.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: randfile.c,v 1.41 2015/07/18 22:46:42 beck Exp $ */ 1/* $OpenBSD: randfile.c,v 1.42 2015/09/10 15:56:25 jsing 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 *
@@ -130,7 +130,7 @@ RAND_write_file(const char *file)
130 } 130 }
131 131
132 fclose(out); 132 fclose(out);
133 OPENSSL_cleanse(buf, BUFSIZE); 133 explicit_bzero(buf, BUFSIZE);
134 return ret; 134 return ret;
135} 135}
136 136
diff --git a/src/lib/libssl/src/crypto/ripemd/rmd_one.c b/src/lib/libssl/src/crypto/ripemd/rmd_one.c
index 84b13d5312..0d372f32f7 100644
--- a/src/lib/libssl/src/crypto/ripemd/rmd_one.c
+++ b/src/lib/libssl/src/crypto/ripemd/rmd_one.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rmd_one.c,v 1.8 2015/09/10 15:03:59 jsing Exp $ */ 1/* $OpenBSD: rmd_one.c,v 1.9 2015/09/10 15:56:25 jsing 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 *
@@ -72,7 +72,7 @@ unsigned char *RIPEMD160(const unsigned char *d, size_t n,
72 return NULL; 72 return NULL;
73 RIPEMD160_Update(&c,d,n); 73 RIPEMD160_Update(&c,d,n);
74 RIPEMD160_Final(md,&c); 74 RIPEMD160_Final(md,&c);
75 OPENSSL_cleanse(&c,sizeof(c)); 75 explicit_bzero(&c,sizeof(c));
76 return(md); 76 return(md);
77 } 77 }
78 78
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_eay.c b/src/lib/libssl/src/crypto/rsa/rsa_eay.c
index 940964cac3..76863e7220 100644
--- a/src/lib/libssl/src/crypto/rsa/rsa_eay.c
+++ b/src/lib/libssl/src/crypto/rsa/rsa_eay.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_eay.c,v 1.39 2015/06/13 08:38:10 doug Exp $ */ 1/* $OpenBSD: rsa_eay.c,v 1.40 2015/09/10 15:56:25 jsing 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 *
@@ -110,6 +110,7 @@
110 */ 110 */
111 111
112#include <stdio.h> 112#include <stdio.h>
113#include <string.h>
113 114
114#include <openssl/opensslconf.h> 115#include <openssl/opensslconf.h>
115 116
@@ -242,7 +243,7 @@ err:
242 BN_CTX_free(ctx); 243 BN_CTX_free(ctx);
243 } 244 }
244 if (buf != NULL) { 245 if (buf != NULL) {
245 OPENSSL_cleanse(buf, num); 246 explicit_bzero(buf, num);
246 free(buf); 247 free(buf);
247 } 248 }
248 return r; 249 return r;
@@ -472,7 +473,7 @@ err:
472 BN_CTX_free(ctx); 473 BN_CTX_free(ctx);
473 } 474 }
474 if (buf != NULL) { 475 if (buf != NULL) {
475 OPENSSL_cleanse(buf, num); 476 explicit_bzero(buf, num);
476 free(buf); 477 free(buf);
477 } 478 }
478 return r; 479 return r;
@@ -607,7 +608,7 @@ err:
607 BN_CTX_free(ctx); 608 BN_CTX_free(ctx);
608 } 609 }
609 if (buf != NULL) { 610 if (buf != NULL) {
610 OPENSSL_cleanse(buf, num); 611 explicit_bzero(buf, num);
611 free(buf); 612 free(buf);
612 } 613 }
613 return r; 614 return r;
@@ -712,7 +713,7 @@ err:
712 BN_CTX_free(ctx); 713 BN_CTX_free(ctx);
713 } 714 }
714 if (buf != NULL) { 715 if (buf != NULL) {
715 OPENSSL_cleanse(buf, num); 716 explicit_bzero(buf, num);
716 free(buf); 717 free(buf);
717 } 718 }
718 return r; 719 return r;
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_saos.c b/src/lib/libssl/src/crypto/rsa/rsa_saos.c
index 3a07a7af4a..0a4f37a3da 100644
--- a/src/lib/libssl/src/crypto/rsa/rsa_saos.c
+++ b/src/lib/libssl/src/crypto/rsa/rsa_saos.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_saos.c,v 1.17 2015/07/19 18:29:31 miod Exp $ */ 1/* $OpenBSD: rsa_saos.c,v 1.18 2015/09/10 15:56:25 jsing 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 *
@@ -97,7 +97,7 @@ RSA_sign_ASN1_OCTET_STRING(int type, const unsigned char *m, unsigned int m_len,
97 else 97 else
98 *siglen = i; 98 *siglen = i;
99 99
100 OPENSSL_cleanse(s, (unsigned int)j + 1); 100 explicit_bzero(s, (unsigned int)j + 1);
101 free(s); 101 free(s);
102 return ret; 102 return ret;
103} 103}
@@ -142,7 +142,7 @@ RSA_verify_ASN1_OCTET_STRING(int dtype, const unsigned char *m,
142err: 142err:
143 M_ASN1_OCTET_STRING_free(sig); 143 M_ASN1_OCTET_STRING_free(sig);
144 if (s != NULL) { 144 if (s != NULL) {
145 OPENSSL_cleanse(s, (unsigned int)siglen); 145 explicit_bzero(s, (unsigned int)siglen);
146 free(s); 146 free(s);
147 } 147 }
148 return ret; 148 return ret;
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_sign.c b/src/lib/libssl/src/crypto/rsa/rsa_sign.c
index db63c5f038..7be08f544b 100644
--- a/src/lib/libssl/src/crypto/rsa/rsa_sign.c
+++ b/src/lib/libssl/src/crypto/rsa/rsa_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_sign.c,v 1.24 2015/07/19 18:29:31 miod Exp $ */ 1/* $OpenBSD: rsa_sign.c,v 1.25 2015/09/10 15:56:25 jsing 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 *
@@ -137,7 +137,7 @@ RSA_sign(int type, const unsigned char *m, unsigned int m_len,
137 *siglen = i; 137 *siglen = i;
138 138
139 if (type != NID_md5_sha1) { 139 if (type != NID_md5_sha1) {
140 OPENSSL_cleanse(tmps, (unsigned int)j + 1); 140 explicit_bzero(tmps, (unsigned int)j + 1);
141 free(tmps); 141 free(tmps);
142 } 142 }
143 return (ret); 143 return (ret);
@@ -237,7 +237,7 @@ err:
237 if (sig != NULL) 237 if (sig != NULL)
238 X509_SIG_free(sig); 238 X509_SIG_free(sig);
239 if (s != NULL) { 239 if (s != NULL) {
240 OPENSSL_cleanse(s, (unsigned int)siglen); 240 explicit_bzero(s, (unsigned int)siglen);
241 free(s); 241 free(s);
242 } 242 }
243 return ret; 243 return ret;
diff --git a/src/lib/libssl/src/crypto/sha/sha1_one.c b/src/lib/libssl/src/crypto/sha/sha1_one.c
index f6b5e4bacf..91602ee503 100644
--- a/src/lib/libssl/src/crypto/sha/sha1_one.c
+++ b/src/lib/libssl/src/crypto/sha/sha1_one.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha1_one.c,v 1.11 2014/07/10 22:45:58 jsing Exp $ */ 1/* $OpenBSD: sha1_one.c,v 1.12 2015/09/10 15:56:26 jsing 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 *
@@ -75,7 +75,7 @@ unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md)
75 return NULL; 75 return NULL;
76 SHA1_Update(&c,d,n); 76 SHA1_Update(&c,d,n);
77 SHA1_Final(md,&c); 77 SHA1_Final(md,&c);
78 OPENSSL_cleanse(&c,sizeof(c)); 78 explicit_bzero(&c,sizeof(c));
79 return(md); 79 return(md);
80 } 80 }
81#endif 81#endif
diff --git a/src/lib/libssl/src/crypto/sha/sha256.c b/src/lib/libssl/src/crypto/sha/sha256.c
index c5ab56852f..d584660369 100644
--- a/src/lib/libssl/src/crypto/sha/sha256.c
+++ b/src/lib/libssl/src/crypto/sha/sha256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha256.c,v 1.8 2014/08/18 19:11:48 bcook Exp $ */ 1/* $OpenBSD: sha256.c,v 1.9 2015/09/10 15:56:26 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2004 The OpenSSL Project. All rights reserved 3 * Copyright (c) 2004 The OpenSSL Project. All rights reserved
4 * according to the OpenSSL license [found in ../../LICENSE]. 4 * according to the OpenSSL license [found in ../../LICENSE].
@@ -49,7 +49,7 @@ unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md)
49 SHA224_Init(&c); 49 SHA224_Init(&c);
50 SHA256_Update(&c,d,n); 50 SHA256_Update(&c,d,n);
51 SHA256_Final(md,&c); 51 SHA256_Final(md,&c);
52 OPENSSL_cleanse(&c,sizeof(c)); 52 explicit_bzero(&c,sizeof(c));
53 return(md); 53 return(md);
54 } 54 }
55 55
@@ -62,7 +62,7 @@ unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md)
62 SHA256_Init(&c); 62 SHA256_Init(&c);
63 SHA256_Update(&c,d,n); 63 SHA256_Update(&c,d,n);
64 SHA256_Final(md,&c); 64 SHA256_Final(md,&c);
65 OPENSSL_cleanse(&c,sizeof(c)); 65 explicit_bzero(&c,sizeof(c));
66 return(md); 66 return(md);
67 } 67 }
68 68
diff --git a/src/lib/libssl/src/crypto/sha/sha512.c b/src/lib/libssl/src/crypto/sha/sha512.c
index ad72b7e6f1..7a55c0acc9 100644
--- a/src/lib/libssl/src/crypto/sha/sha512.c
+++ b/src/lib/libssl/src/crypto/sha/sha512.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha512.c,v 1.13 2014/07/11 08:44:49 jsing Exp $ */ 1/* $OpenBSD: sha512.c,v 1.14 2015/09/10 15:56:26 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2004 The OpenSSL Project. All rights reserved 3 * Copyright (c) 2004 The OpenSSL Project. All rights reserved
4 * according to the OpenSSL license [found in ../../LICENSE]. 4 * according to the OpenSSL license [found in ../../LICENSE].
@@ -248,7 +248,7 @@ unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md)
248 SHA384_Init(&c); 248 SHA384_Init(&c);
249 SHA512_Update(&c,d,n); 249 SHA512_Update(&c,d,n);
250 SHA512_Final(md,&c); 250 SHA512_Final(md,&c);
251 OPENSSL_cleanse(&c,sizeof(c)); 251 explicit_bzero(&c,sizeof(c));
252 return(md); 252 return(md);
253 } 253 }
254 254
@@ -261,7 +261,7 @@ unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md)
261 SHA512_Init(&c); 261 SHA512_Init(&c);
262 SHA512_Update(&c,d,n); 262 SHA512_Update(&c,d,n);
263 SHA512_Final(md,&c); 263 SHA512_Final(md,&c);
264 OPENSSL_cleanse(&c,sizeof(c)); 264 explicit_bzero(&c,sizeof(c));
265 return(md); 265 return(md);
266 } 266 }
267 267
diff --git a/src/lib/libssl/src/crypto/sha/sha_one.c b/src/lib/libssl/src/crypto/sha/sha_one.c
index 1d3fc35f05..ad04021eb1 100644
--- a/src/lib/libssl/src/crypto/sha/sha_one.c
+++ b/src/lib/libssl/src/crypto/sha/sha_one.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha_one.c,v 1.8 2014/07/10 22:45:58 jsing Exp $ */ 1/* $OpenBSD: sha_one.c,v 1.9 2015/09/10 15:56:26 jsing 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 *
@@ -75,7 +75,7 @@ unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md)
75 return NULL; 75 return NULL;
76 SHA_Update(&c,d,n); 76 SHA_Update(&c,d,n);
77 SHA_Final(md,&c); 77 SHA_Final(md,&c);
78 OPENSSL_cleanse(&c,sizeof(c)); 78 explicit_bzero(&c,sizeof(c));
79 return(md); 79 return(md);
80 } 80 }
81#endif 81#endif
diff --git a/src/lib/libssl/src/crypto/ui/ui_openssl.c b/src/lib/libssl/src/crypto/ui/ui_openssl.c
index b3d2971a02..9562c2c937 100644
--- a/src/lib/libssl/src/crypto/ui/ui_openssl.c
+++ b/src/lib/libssl/src/crypto/ui/ui_openssl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ui_openssl.c,v 1.24 2015/07/16 02:46:49 guenther Exp $ */ 1/* $OpenBSD: ui_openssl.c,v 1.25 2015/09/10 15:56:26 jsing Exp $ */
2/* Written by Richard Levitte (richard@levitte.org) and others 2/* Written by Richard Levitte (richard@levitte.org) and others
3 * for the OpenSSL project 2001. 3 * for the OpenSSL project 2001.
4 */ 4 */
@@ -286,7 +286,7 @@ error:
286 if (ps >= 1) 286 if (ps >= 1)
287 popsig(); 287 popsig();
288 288
289 OPENSSL_cleanse(result, BUFSIZ); 289 explicit_bzero(result, BUFSIZ);
290 return ok; 290 return ok;
291} 291}
292 292
diff --git a/src/lib/libssl/src/crypto/ui/ui_util.c b/src/lib/libssl/src/crypto/ui/ui_util.c
index e5cee913b2..d1040c9826 100644
--- a/src/lib/libssl/src/crypto/ui/ui_util.c
+++ b/src/lib/libssl/src/crypto/ui/ui_util.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ui_util.c,v 1.9 2014/06/12 15:49:31 deraadt Exp $ */ 1/* $OpenBSD: ui_util.c,v 1.10 2015/09/10 15:56:26 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -67,7 +67,7 @@ UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify)
67 67
68 ret = UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length, 68 ret = UI_UTIL_read_pw(buf, buff, (length > BUFSIZ) ? BUFSIZ : length,
69 prompt, verify); 69 prompt, verify);
70 OPENSSL_cleanse(buff, BUFSIZ); 70 explicit_bzero(buff, BUFSIZ);
71 return (ret); 71 return (ret);
72} 72}
73 73
diff --git a/src/lib/libssl/src/ssl/d1_clnt.c b/src/lib/libssl/src/ssl/d1_clnt.c
index 23d6b372c9..2b736b9243 100644
--- a/src/lib/libssl/src/ssl/d1_clnt.c
+++ b/src/lib/libssl/src/ssl/d1_clnt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_clnt.c,v 1.48 2015/09/02 17:59:15 jsing Exp $ */ 1/* $OpenBSD: d1_clnt.c,v 1.49 2015/09/10 15:56:26 jsing Exp $ */
2/* 2/*
3 * DTLS implementation written by Nagendra Modadugu 3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -731,7 +731,7 @@ dtls1_send_client_key_exchange(SSL *s)
731 s->method->ssl3_enc->generate_master_secret(s, 731 s->method->ssl3_enc->generate_master_secret(s,
732 s->session->master_key, 732 s->session->master_key,
733 tmp_buf, sizeof tmp_buf); 733 tmp_buf, sizeof tmp_buf);
734 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); 734 explicit_bzero(tmp_buf, sizeof tmp_buf);
735 } else if (alg_k & SSL_kDHE) { 735 } else if (alg_k & SSL_kDHE) {
736 DH *dh_srvr, *dh_clnt; 736 DH *dh_srvr, *dh_clnt;
737 737
diff --git a/src/lib/libssl/src/ssl/d1_lib.c b/src/lib/libssl/src/ssl/d1_lib.c
index b269efe469..e7eca4a8cd 100644
--- a/src/lib/libssl/src/ssl/d1_lib.c
+++ b/src/lib/libssl/src/ssl/d1_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: d1_lib.c,v 1.29 2015/07/19 20:32:18 doug Exp $ */ 1/* $OpenBSD: d1_lib.c,v 1.30 2015/09/10 15:56:26 jsing Exp $ */
2/* 2/*
3 * DTLS implementation written by Nagendra Modadugu 3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. 4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
@@ -203,7 +203,7 @@ dtls1_free(SSL *s)
203 pqueue_free(s->d1->sent_messages); 203 pqueue_free(s->d1->sent_messages);
204 pqueue_free(s->d1->buffered_app_data.q); 204 pqueue_free(s->d1->buffered_app_data.q);
205 205
206 OPENSSL_cleanse(s->d1, sizeof *s->d1); 206 explicit_bzero(s->d1, sizeof *s->d1);
207 free(s->d1); 207 free(s->d1);
208 s->d1 = NULL; 208 s->d1 = NULL;
209} 209}
diff --git a/src/lib/libssl/src/ssl/s3_clnt.c b/src/lib/libssl/src/ssl/s3_clnt.c
index 1d1a0c77f0..e4ce8163ac 100644
--- a/src/lib/libssl/src/ssl/s3_clnt.c
+++ b/src/lib/libssl/src/ssl/s3_clnt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_clnt.c,v 1.125 2015/09/02 17:59:15 jsing Exp $ */ 1/* $OpenBSD: s3_clnt.c,v 1.126 2015/09/10 15:56:26 jsing 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 *
@@ -1933,7 +1933,7 @@ ssl3_send_client_key_exchange(SSL *s)
1933 s->session->master_key_length = 1933 s->session->master_key_length =
1934 s->method->ssl3_enc->generate_master_secret( 1934 s->method->ssl3_enc->generate_master_secret(
1935 s, s->session->master_key, tmp_buf, sizeof tmp_buf); 1935 s, s->session->master_key, tmp_buf, sizeof tmp_buf);
1936 OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); 1936 explicit_bzero(tmp_buf, sizeof tmp_buf);
1937 } else if (alg_k & SSL_kDHE) { 1937 } else if (alg_k & SSL_kDHE) {
1938 DH *dh_srvr, *dh_clnt; 1938 DH *dh_srvr, *dh_clnt;
1939 1939
diff --git a/src/lib/libssl/src/ssl/s3_enc.c b/src/lib/libssl/src/ssl/s3_enc.c
index bfa719df5f..515072a99e 100644
--- a/src/lib/libssl/src/ssl/s3_enc.c
+++ b/src/lib/libssl/src/ssl/s3_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_enc.c,v 1.61 2015/07/19 20:32:18 doug Exp $ */ 1/* $OpenBSD: s3_enc.c,v 1.62 2015/09/10 15:56:26 jsing 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 *
@@ -209,7 +209,7 @@ ssl3_generate_key_block(SSL *s, unsigned char *km, int num)
209 209
210 km += MD5_DIGEST_LENGTH; 210 km += MD5_DIGEST_LENGTH;
211 } 211 }
212 OPENSSL_cleanse(smd, SHA_DIGEST_LENGTH); 212 explicit_bzero(smd, SHA_DIGEST_LENGTH);
213 EVP_MD_CTX_cleanup(&m5); 213 EVP_MD_CTX_cleanup(&m5);
214 EVP_MD_CTX_cleanup(&s1); 214 EVP_MD_CTX_cleanup(&s1);
215 return 1; 215 return 1;
@@ -392,7 +392,7 @@ void
392ssl3_cleanup_key_block(SSL *s) 392ssl3_cleanup_key_block(SSL *s)
393{ 393{
394 if (s->s3->tmp.key_block != NULL) { 394 if (s->s3->tmp.key_block != NULL) {
395 OPENSSL_cleanse(s->s3->tmp.key_block, 395 explicit_bzero(s->s3->tmp.key_block,
396 s->s3->tmp.key_block_length); 396 s->s3->tmp.key_block_length);
397 free(s->s3->tmp.key_block); 397 free(s->s3->tmp.key_block);
398 s->s3->tmp.key_block = NULL; 398 s->s3->tmp.key_block = NULL;
diff --git a/src/lib/libssl/src/ssl/s3_lib.c b/src/lib/libssl/src/ssl/s3_lib.c
index 42396a21e9..4e6b123698 100644
--- a/src/lib/libssl/src/ssl/s3_lib.c
+++ b/src/lib/libssl/src/ssl/s3_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_lib.c,v 1.100 2015/08/27 06:21:15 doug Exp $ */ 1/* $OpenBSD: s3_lib.c,v 1.101 2015/09/10 15:56:26 jsing 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 *
@@ -2066,7 +2066,7 @@ ssl3_free(SSL *s)
2066 ssl3_free_digest_list(s); 2066 ssl3_free_digest_list(s);
2067 free(s->s3->alpn_selected); 2067 free(s->s3->alpn_selected);
2068 2068
2069 OPENSSL_cleanse(s->s3, sizeof *s->s3); 2069 explicit_bzero(s->s3, sizeof *s->s3);
2070 free(s->s3); 2070 free(s->s3);
2071 s->s3 = NULL; 2071 s->s3 = NULL;
2072} 2072}
diff --git a/src/lib/libssl/src/ssl/s3_srvr.c b/src/lib/libssl/src/ssl/s3_srvr.c
index 3f9f6720fa..b2c4f8e0d2 100644
--- a/src/lib/libssl/src/ssl/s3_srvr.c
+++ b/src/lib/libssl/src/ssl/s3_srvr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: s3_srvr.c,v 1.115 2015/09/01 13:38:27 jsing Exp $ */ 1/* $OpenBSD: s3_srvr.c,v 1.116 2015/09/10 15:56:26 jsing 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 *
@@ -1725,7 +1725,7 @@ ssl3_get_client_key_exchange(SSL *s)
1725 s->method->ssl3_enc->generate_master_secret(s, 1725 s->method->ssl3_enc->generate_master_secret(s,
1726 s->session->master_key, 1726 s->session->master_key,
1727 p, i); 1727 p, i);
1728 OPENSSL_cleanse(p, i); 1728 explicit_bzero(p, i);
1729 } else if (alg_k & SSL_kDHE) { 1729 } else if (alg_k & SSL_kDHE) {
1730 if (2 > n) 1730 if (2 > n)
1731 goto truncated; 1731 goto truncated;
@@ -1776,7 +1776,7 @@ ssl3_get_client_key_exchange(SSL *s)
1776 s->session->master_key_length = 1776 s->session->master_key_length =
1777 s->method->ssl3_enc->generate_master_secret( 1777 s->method->ssl3_enc->generate_master_secret(
1778 s, s->session->master_key, p, i); 1778 s, s->session->master_key, p, i);
1779 OPENSSL_cleanse(p, i); 1779 explicit_bzero(p, i);
1780 } else 1780 } else
1781 1781
1782 if (alg_k & (SSL_kECDHE|SSL_kECDHr|SSL_kECDHe)) { 1782 if (alg_k & (SSL_kECDHE|SSL_kECDHr|SSL_kECDHe)) {
@@ -1920,7 +1920,7 @@ ssl3_get_client_key_exchange(SSL *s)
1920 s->session->master_key_length = s->method->ssl3_enc-> \ 1920 s->session->master_key_length = s->method->ssl3_enc-> \
1921 generate_master_secret(s, s->session->master_key, p, i); 1921 generate_master_secret(s, s->session->master_key, p, i);
1922 1922
1923 OPENSSL_cleanse(p, i); 1923 explicit_bzero(p, i);
1924 return (ret); 1924 return (ret);
1925 } else 1925 } else
1926 if (alg_k & SSL_kGOST) { 1926 if (alg_k & SSL_kGOST) {
diff --git a/src/lib/libssl/src/ssl/ssl_sess.c b/src/lib/libssl/src/ssl/ssl_sess.c
index a688b9ef41..5d18c8a0b4 100644
--- a/src/lib/libssl/src/ssl/ssl_sess.c
+++ b/src/lib/libssl/src/ssl/ssl_sess.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_sess.c,v 1.46 2015/08/27 06:21:15 doug Exp $ */ 1/* $OpenBSD: ssl_sess.c,v 1.47 2015/09/10 15:56:26 jsing 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 *
@@ -694,8 +694,8 @@ SSL_SESSION_free(SSL_SESSION *ss)
694 694
695 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data); 695 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
696 696
697 OPENSSL_cleanse(ss->master_key, sizeof ss->master_key); 697 explicit_bzero(ss->master_key, sizeof ss->master_key);
698 OPENSSL_cleanse(ss->session_id, sizeof ss->session_id); 698 explicit_bzero(ss->session_id, sizeof ss->session_id);
699 if (ss->sess_cert != NULL) 699 if (ss->sess_cert != NULL)
700 ssl_sess_cert_free(ss->sess_cert); 700 ssl_sess_cert_free(ss->sess_cert);
701 if (ss->peer != NULL) 701 if (ss->peer != NULL)
@@ -708,7 +708,7 @@ SSL_SESSION_free(SSL_SESSION *ss)
708 free(ss->tlsext_ecpointformatlist); 708 free(ss->tlsext_ecpointformatlist);
709 ss->tlsext_ellipticcurvelist_length = 0; 709 ss->tlsext_ellipticcurvelist_length = 0;
710 free(ss->tlsext_ellipticcurvelist); 710 free(ss->tlsext_ellipticcurvelist);
711 OPENSSL_cleanse(ss, sizeof(*ss)); 711 explicit_bzero(ss, sizeof(*ss));
712 free(ss); 712 free(ss);
713} 713}
714 714
diff --git a/src/lib/libssl/src/ssl/t1_enc.c b/src/lib/libssl/src/ssl/t1_enc.c
index a3a5d4dd7d..5d2b8eaf89 100644
--- a/src/lib/libssl/src/ssl/t1_enc.c
+++ b/src/lib/libssl/src/ssl/t1_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t1_enc.c,v 1.80 2015/08/27 14:16:57 jsing Exp $ */ 1/* $OpenBSD: t1_enc.c,v 1.81 2015/09/10 15:56:26 jsing 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 *
@@ -226,7 +226,7 @@ err:
226 EVP_PKEY_free(mac_key); 226 EVP_PKEY_free(mac_key);
227 EVP_MD_CTX_cleanup(&ctx); 227 EVP_MD_CTX_cleanup(&ctx);
228 EVP_MD_CTX_cleanup(&ctx_tmp); 228 EVP_MD_CTX_cleanup(&ctx_tmp);
229 OPENSSL_cleanse(A1, sizeof(A1)); 229 explicit_bzero(A1, sizeof(A1));
230 return ret; 230 return ret;
231} 231}
232 232
@@ -659,7 +659,7 @@ tls1_setup_key_block(SSL *s)
659 659
660err: 660err:
661 if (tmp_block) { 661 if (tmp_block) {
662 OPENSSL_cleanse(tmp_block, key_block_len); 662 explicit_bzero(tmp_block, key_block_len);
663 free(tmp_block); 663 free(tmp_block);
664 } 664 }
665 return (ret); 665 return (ret);
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c
index a688b9ef41..5d18c8a0b4 100644
--- a/src/lib/libssl/ssl_sess.c
+++ b/src/lib/libssl/ssl_sess.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_sess.c,v 1.46 2015/08/27 06:21:15 doug Exp $ */ 1/* $OpenBSD: ssl_sess.c,v 1.47 2015/09/10 15:56:26 jsing 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 *
@@ -694,8 +694,8 @@ SSL_SESSION_free(SSL_SESSION *ss)
694 694
695 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data); 695 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
696 696
697 OPENSSL_cleanse(ss->master_key, sizeof ss->master_key); 697 explicit_bzero(ss->master_key, sizeof ss->master_key);
698 OPENSSL_cleanse(ss->session_id, sizeof ss->session_id); 698 explicit_bzero(ss->session_id, sizeof ss->session_id);
699 if (ss->sess_cert != NULL) 699 if (ss->sess_cert != NULL)
700 ssl_sess_cert_free(ss->sess_cert); 700 ssl_sess_cert_free(ss->sess_cert);
701 if (ss->peer != NULL) 701 if (ss->peer != NULL)
@@ -708,7 +708,7 @@ SSL_SESSION_free(SSL_SESSION *ss)
708 free(ss->tlsext_ecpointformatlist); 708 free(ss->tlsext_ecpointformatlist);
709 ss->tlsext_ellipticcurvelist_length = 0; 709 ss->tlsext_ellipticcurvelist_length = 0;
710 free(ss->tlsext_ellipticcurvelist); 710 free(ss->tlsext_ellipticcurvelist);
711 OPENSSL_cleanse(ss, sizeof(*ss)); 711 explicit_bzero(ss, sizeof(*ss));
712 free(ss); 712 free(ss);
713} 713}
714 714
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c
index a3a5d4dd7d..5d2b8eaf89 100644
--- a/src/lib/libssl/t1_enc.c
+++ b/src/lib/libssl/t1_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t1_enc.c,v 1.80 2015/08/27 14:16:57 jsing Exp $ */ 1/* $OpenBSD: t1_enc.c,v 1.81 2015/09/10 15:56:26 jsing 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 *
@@ -226,7 +226,7 @@ err:
226 EVP_PKEY_free(mac_key); 226 EVP_PKEY_free(mac_key);
227 EVP_MD_CTX_cleanup(&ctx); 227 EVP_MD_CTX_cleanup(&ctx);
228 EVP_MD_CTX_cleanup(&ctx_tmp); 228 EVP_MD_CTX_cleanup(&ctx_tmp);
229 OPENSSL_cleanse(A1, sizeof(A1)); 229 explicit_bzero(A1, sizeof(A1));
230 return ret; 230 return ret;
231} 231}
232 232
@@ -659,7 +659,7 @@ tls1_setup_key_block(SSL *s)
659 659
660err: 660err:
661 if (tmp_block) { 661 if (tmp_block) {
662 OPENSSL_cleanse(tmp_block, key_block_len); 662 explicit_bzero(tmp_block, key_block_len);
663 free(tmp_block); 663 free(tmp_block);
664 } 664 }
665 return (ret); 665 return (ret);