libmd: Always erase context in _Final method, and when doing

it, consistently use explicit_bzero().

Update manual pages to match the behavior.

Reviewed by:	pfg, allanjude, jmg
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D16316
This commit is contained in:
delphij 2018-07-20 07:01:28 +00:00
parent 2e338ed14a
commit 8f0497f698
14 changed files with 39 additions and 30 deletions

View File

@ -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.

View File

@ -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. */

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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));
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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: *********************************************************/

View File

@ -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

View File

@ -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