diff --git a/lib/libmd/md4c.c b/lib/libmd/md4c.c index a30027b1fb45..4cb136814019 100644 --- a/lib/libmd/md4c.c +++ b/lib/libmd/md4c.c @@ -183,7 +183,7 @@ MD4_CTX *context; /* context */ /* Zeroize sensitive information. */ - memset ((POINTER)context, 0, sizeof (*context)); + explicit_bzero(context, sizeof(*context)); } /* MD4 basic transformation. Transforms state based on block. diff --git a/lib/libmd/md5c.c b/lib/libmd/md5c.c index a2c71b6a6960..fc852b913464 100644 --- a/lib/libmd/md5c.c +++ b/lib/libmd/md5c.c @@ -220,7 +220,7 @@ MD5Final (unsigned char digest[16], MD5_CTX *context) Encode (digest, context->state, 16); /* Zeroize sensitive information. */ - memset ((void *)context, 0, sizeof (*context)); + explicit_bzero(context, sizeof(*context)); } /* MD5 basic transformation. Transforms state based on block. */ diff --git a/lib/libmd/mdX.3 b/lib/libmd/mdX.3 index daa5c36176cf..9440c286b212 100644 --- a/lib/libmd/mdX.3 +++ b/lib/libmd/mdX.3 @@ -8,7 +8,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 26, 2016 +.Dd July 20, 2018 .Dt MDX 3 .Os .Sh NAME @@ -78,7 +78,9 @@ initialize it with run over the data with .Fn MDXUpdate , and finally extract the result using -.Fn MDXFinal . +.Fn MDXFinal , +which will also erase the +.Vt MDX_CTX . .Pp The .Fn MDXPad diff --git a/lib/libmd/ripemd.3 b/lib/libmd/ripemd.3 index 8e868b88e8da..e4c5fa4a41c8 100644 --- a/lib/libmd/ripemd.3 +++ b/lib/libmd/ripemd.3 @@ -9,7 +9,7 @@ .\" From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp .\" $FreeBSD$ .\" -.Dd April 26, 2016 +.Dd July 20, 2018 .Dt RIPEMD 3 .Os .Sh NAME @@ -65,7 +65,9 @@ initialize it with run over the data with .Fn RIPEMD160_Update , and finally extract the result using -.Fn RIPEMD160_Final . +.Fn RIPEMD160_Final , +which will also erase the +.Vt RIPEMD160_CTX . .Pp The .Fn RIPEMD160_End diff --git a/lib/libmd/rmd160c.c b/lib/libmd/rmd160c.c index 5a3b78325728..a8a4ced70b0a 100644 --- a/lib/libmd/rmd160c.c +++ b/lib/libmd/rmd160c.c @@ -523,10 +523,8 @@ RIPEMD160_CTX *c; l=c->D; l2c(l,cp); l=c->E; l2c(l,cp); - /* clear stuff, ripemd160_block may be leaving some stuff on the stack - * but I'm not worried :-) */ - c->num=0; -/* memset((char *)&c,0,sizeof(c));*/ + /* Clear the context state */ + explicit_bzero(&c, sizeof(c)); } #ifdef undef diff --git a/lib/libmd/sha.3 b/lib/libmd/sha.3 index 95c0603651b9..90cc93662429 100644 --- a/lib/libmd/sha.3 +++ b/lib/libmd/sha.3 @@ -9,7 +9,7 @@ .\" From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp .\" $FreeBSD$ .\" -.Dd April 26, 2016 +.Dd July 20, 2018 .Dt SHA 3 .Os .Sh NAME @@ -100,7 +100,9 @@ initialize it with run over the data with .Fn SHA1_Update , and finally extract the result using -.Fn SHA1_Final . +.Fn SHA1_Final , +which will also erase the +.Vt SHA_CTX . .Pp .Fn SHA1_End is a wrapper for diff --git a/lib/libmd/sha0c.c b/lib/libmd/sha0c.c index b35b7f275ffd..ee4407939598 100644 --- a/lib/libmd/sha0c.c +++ b/lib/libmd/sha0c.c @@ -446,9 +446,7 @@ SHA_CTX *c; l=c->h3; nl2c(l,cp); l=c->h4; nl2c(l,cp); - /* clear stuff, sha_block may be leaving some stuff on the stack - * but I'm not worried :-) */ - c->num=0; -/* memset((char *)&c,0,sizeof(c));*/ + /* Clear the context state */ + explicit_bzero(&c, sizeof(c)); } diff --git a/lib/libmd/sha1c.c b/lib/libmd/sha1c.c index 93a4ff37683b..d0bcc35f93d7 100644 --- a/lib/libmd/sha1c.c +++ b/lib/libmd/sha1c.c @@ -482,10 +482,8 @@ SHA_CTX *c; l=c->h3; nl2c(l,cp); l=c->h4; nl2c(l,cp); - /* clear stuff, sha1_block may be leaving some stuff on the stack - * but I'm not worried :-) */ - c->num=0; -/* memset((char *)&c,0,sizeof(c));*/ + /* Clear the context state */ + explicit_bzero(&c, sizeof(c)); } #ifdef WEAK_REFS diff --git a/lib/libmd/sha256.3 b/lib/libmd/sha256.3 index 25bbb1220486..eeac4041f479 100644 --- a/lib/libmd/sha256.3 +++ b/lib/libmd/sha256.3 @@ -9,7 +9,7 @@ .\" From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp .\" $FreeBSD$ .\" -.Dd July 9, 2018 +.Dd July 20, 2018 .Dt SHA256 3 .Os .Sh NAME @@ -88,7 +88,9 @@ initialize it with run over the data with .Fn SHA256_Update , and finally extract the result using -.Fn SHA256_Final . +.Fn SHA256_Final , +which will also erase the +.Vt SHA256_CTX . .Pp .Fn SHA256_End is a wrapper for diff --git a/lib/libmd/sha512.3 b/lib/libmd/sha512.3 index c5f9ac6f1770..a842e9cada61 100644 --- a/lib/libmd/sha512.3 +++ b/lib/libmd/sha512.3 @@ -9,7 +9,7 @@ .\" From: Id: mdX.3,v 1.14 1999/02/11 20:31:49 wollman Exp .\" $FreeBSD$ .\" -.Dd April 22, 2016 +.Dd July 20, 2018 .Dt SHA512 3 .Os .Sh NAME @@ -110,7 +110,9 @@ initialize it with run over the data with .Fn SHA512_Update , and finally extract the result using -.Fn SHA512_Final . +.Fn SHA512_Final , +which will also erase the +.Vt SHA512_CTX . .Pp .Fn SHA512_End is a wrapper for diff --git a/lib/libmd/skein.3 b/lib/libmd/skein.3 index 11c78a797aa3..2d6a9e3fd4b1 100644 --- a/lib/libmd/skein.3 +++ b/lib/libmd/skein.3 @@ -124,7 +124,9 @@ initialize it with run over the data with .Fn SKEIN256_Update , and finally extract the result using -.Fn SKEIN256_Final . +.Fn SKEIN256_Final , +which will also erase the +.Vt SKEIN256_CTX . .Pp .Fn SKEIN256_End is a wrapper for diff --git a/sys/crypto/sha2/sha256c.c b/sys/crypto/sha2/sha256c.c index 70980ac5fb7a..135fb68ccc65 100644 --- a/sys/crypto/sha2/sha256c.c +++ b/sys/crypto/sha2/sha256c.c @@ -298,7 +298,7 @@ SHA256_Final(unsigned char digest[static SHA256_DIGEST_LENGTH], SHA256_CTX *ctx) be32enc_vect(digest, ctx->state, SHA256_DIGEST_LENGTH); /* Clear the context state */ - memset(ctx, 0, sizeof(*ctx)); + explicit_bzero(ctx, sizeof(*ctx)); } /*** SHA-224: *********************************************************/ diff --git a/sys/crypto/sha2/sha512c.c b/sys/crypto/sha2/sha512c.c index 21c7efabe156..e0dd36120a90 100644 --- a/sys/crypto/sha2/sha512c.c +++ b/sys/crypto/sha2/sha512c.c @@ -331,7 +331,7 @@ SHA512_Final(unsigned char digest[static SHA512_DIGEST_LENGTH], SHA512_CTX *ctx) be64enc_vect(digest, ctx->state, SHA512_DIGEST_LENGTH); /* Clear the context state */ - memset(ctx, 0, sizeof(*ctx)); + explicit_bzero(ctx, sizeof(*ctx)); } /*** SHA-512t: *********************************************************/ @@ -374,7 +374,7 @@ SHA512_224_Final(unsigned char digest[static SHA512_224_DIGEST_LENGTH], SHA512_C be64enc_vect(digest, ctx->state, SHA512_224_DIGEST_LENGTH); /* Clear the context state */ - memset(ctx, 0, sizeof(*ctx)); + explicit_bzero(ctx, sizeof(*ctx)); } void @@ -413,7 +413,7 @@ SHA512_256_Final(unsigned char digest[static SHA512_256_DIGEST_LENGTH], SHA512_C be64enc_vect(digest, ctx->state, SHA512_256_DIGEST_LENGTH); /* Clear the context state */ - memset(ctx, 0, sizeof(*ctx)); + explicit_bzero(ctx, sizeof(*ctx)); } /*** SHA-384: *********************************************************/ @@ -463,7 +463,7 @@ SHA384_Final(unsigned char digest[static SHA384_DIGEST_LENGTH], SHA384_CTX *ctx) be64enc_vect(digest, ctx->state, SHA384_DIGEST_LENGTH); /* Clear the context state */ - memset(ctx, 0, sizeof(*ctx)); + explicit_bzero(ctx, sizeof(*ctx)); } #ifdef WEAK_REFS diff --git a/sys/crypto/skein/skein.c b/sys/crypto/skein/skein.c index b8d5905078a3..fd17623db21a 100644 --- a/sys/crypto/skein/skein.c +++ b/sys/crypto/skein/skein.c @@ -812,6 +812,7 @@ SKEIN256_Final(unsigned char digest[static SKEIN_256_BLOCK_BYTES], SKEIN256_CTX { Skein_256_Final(ctx, digest); + explicit_bzero(ctx, sizeof(*ctx)); } void @@ -819,6 +820,7 @@ SKEIN512_Final(unsigned char digest[static SKEIN_512_BLOCK_BYTES], SKEIN512_CTX { Skein_512_Final(ctx, digest); + explicit_bzero(ctx, sizeof(*ctx)); } void @@ -826,6 +828,7 @@ SKEIN1024_Final(unsigned char digest[static SKEIN1024_BLOCK_BYTES], SKEIN1024_CT { Skein1024_Final(ctx, digest); + explicit_bzero(ctx, sizeof(*ctx)); } #ifdef WEAK_REFS