Index: head/lib/libmd/md4c.c =================================================================== --- head/lib/libmd/md4c.c +++ head/lib/libmd/md4c.c @@ -183,7 +183,7 @@ /* Zeroize sensitive information. */ - memset ((POINTER)context, 0, sizeof (*context)); + explicit_bzero(context, sizeof(*context)); } /* MD4 basic transformation. Transforms state based on block. Index: head/lib/libmd/md5c.c =================================================================== --- head/lib/libmd/md5c.c +++ head/lib/libmd/md5c.c @@ -220,7 +220,7 @@ 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. */ Index: head/lib/libmd/mdX.3 =================================================================== --- head/lib/libmd/mdX.3 +++ head/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 @@ 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 Index: head/lib/libmd/ripemd.3 =================================================================== --- head/lib/libmd/ripemd.3 +++ head/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 @@ 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 Index: head/lib/libmd/rmd160c.c =================================================================== --- head/lib/libmd/rmd160c.c +++ head/lib/libmd/rmd160c.c @@ -523,10 +523,8 @@ 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 Index: head/lib/libmd/sha.3 =================================================================== --- head/lib/libmd/sha.3 +++ head/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 @@ 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 Index: head/lib/libmd/sha0c.c =================================================================== --- head/lib/libmd/sha0c.c +++ head/lib/libmd/sha0c.c @@ -446,9 +446,7 @@ 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)); } Index: head/lib/libmd/sha1c.c =================================================================== --- head/lib/libmd/sha1c.c +++ head/lib/libmd/sha1c.c @@ -482,10 +482,8 @@ 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 Index: head/lib/libmd/sha256.3 =================================================================== --- head/lib/libmd/sha256.3 +++ head/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 @@ 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 Index: head/lib/libmd/sha512.3 =================================================================== --- head/lib/libmd/sha512.3 +++ head/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 @@ 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 Index: head/lib/libmd/skein.3 =================================================================== --- head/lib/libmd/skein.3 +++ head/lib/libmd/skein.3 @@ -124,7 +124,9 @@ 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 Index: head/sys/crypto/sha2/sha256c.c =================================================================== --- head/sys/crypto/sha2/sha256c.c +++ head/sys/crypto/sha2/sha256c.c @@ -298,7 +298,7 @@ be32enc_vect(digest, ctx->state, SHA256_DIGEST_LENGTH); /* Clear the context state */ - memset(ctx, 0, sizeof(*ctx)); + explicit_bzero(ctx, sizeof(*ctx)); } /*** SHA-224: *********************************************************/ Index: head/sys/crypto/sha2/sha512c.c =================================================================== --- head/sys/crypto/sha2/sha512c.c +++ head/sys/crypto/sha2/sha512c.c @@ -331,7 +331,7 @@ 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 @@ 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 @@ 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 @@ 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 Index: head/sys/crypto/skein/skein.c =================================================================== --- head/sys/crypto/skein/skein.c +++ head/sys/crypto/skein/skein.c @@ -812,6 +812,7 @@ { Skein_256_Final(ctx, digest); + explicit_bzero(ctx, sizeof(*ctx)); } void @@ -819,6 +820,7 @@ { Skein_512_Final(ctx, digest); + explicit_bzero(ctx, sizeof(*ctx)); } void @@ -826,6 +828,7 @@ { Skein1024_Final(ctx, digest); + explicit_bzero(ctx, sizeof(*ctx)); } #ifdef WEAK_REFS