summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pem/pem_lib.c
diff options
context:
space:
mode:
authorderaadt <>2017-05-02 03:59:45 +0000
committerderaadt <>2017-05-02 03:59:45 +0000
commit2b561cb0e87f2ee535e8c64907883cd275ad3fec (patch)
treebb9d050c5c2984047e6475e087694d6764f24157 /src/lib/libcrypto/pem/pem_lib.c
parent024e2580a5280d4df3724dab76ce52e14fe2060c (diff)
downloadopenbsd-2b561cb0e87f2ee535e8c64907883cd275ad3fec.tar.gz
openbsd-2b561cb0e87f2ee535e8c64907883cd275ad3fec.tar.bz2
openbsd-2b561cb0e87f2ee535e8c64907883cd275ad3fec.zip
use freezero() instead of memset/explicit_bzero + free. Substantially
reduces conditional logic (-218, +82). MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH cache alignment calculation bn/bn_exp.c wasn'tt quite right. Two other tricky bits with ASN1_STRING_FLAG_NDEF and BN_FLG_STATIC_DATA where the condition cannot be collapsed completely. Passes regress. ok beck
Diffstat (limited to 'src/lib/libcrypto/pem/pem_lib.c')
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
index b2c72e1d76..0f7c36d21c 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.44 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: pem_lib.c,v 1.45 2017/05/02 03:59:44 deraadt Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -425,10 +425,7 @@ err:
425 explicit_bzero(iv, sizeof(iv)); 425 explicit_bzero(iv, sizeof(iv));
426 explicit_bzero((char *)&ctx, sizeof(ctx)); 426 explicit_bzero((char *)&ctx, sizeof(ctx));
427 explicit_bzero(buf, PEM_BUFSIZE); 427 explicit_bzero(buf, PEM_BUFSIZE);
428 if (data != NULL) { 428 freezero(data, (unsigned int)dsize);
429 explicit_bzero(data, (unsigned int)dsize);
430 free(data);
431 }
432 return (ret); 429 return (ret);
433} 430}
434 431
@@ -626,8 +623,7 @@ PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
626 EVP_EncodeFinal(&ctx, buf, &outl); 623 EVP_EncodeFinal(&ctx, buf, &outl);
627 if ((outl > 0) && (BIO_write(bp, (char *)buf, outl) != outl)) 624 if ((outl > 0) && (BIO_write(bp, (char *)buf, outl) != outl))
628 goto err; 625 goto err;
629 explicit_bzero(buf, PEM_BUFSIZE * 8); 626 freezero(buf, PEM_BUFSIZE * 8);
630 free(buf);
631 buf = NULL; 627 buf = NULL;
632 if ((BIO_write(bp, "-----END ", 9) != 9) || 628 if ((BIO_write(bp, "-----END ", 9) != 9) ||
633 (BIO_write(bp, name, nlen) != nlen) || 629 (BIO_write(bp, name, nlen) != nlen) ||
@@ -636,10 +632,7 @@ PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
636 return (i + outl); 632 return (i + outl);
637 633
638err: 634err:
639 if (buf) { 635 freezero(buf, PEM_BUFSIZE * 8);
640 explicit_bzero(buf, PEM_BUFSIZE * 8);
641 free(buf);
642 }
643 PEMerror(reason); 636 PEMerror(reason);
644 return (0); 637 return (0);
645} 638}