aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil/sha1.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-05-09 16:35:45 -0700
committerGuy Harris <guy@alum.mit.edu>2015-05-09 23:36:11 +0000
commitacf7985f7377806e23d7ec9daa14a3a6886a51c7 (patch)
tree3c46c8ceb05fc7feee052c138c437f83f5381a53 /wsutil/sha1.c
parentbb89e7724220098e7b7fba5d31daf0d916b2d553 (diff)
Define the SHA-1 digest length in wsutil/sha1.h and use it.
Hopefully that'll make it a little easier to make sure that we're not overflowing arrays. Change-Id: I770df045ef9a45fd486c1271ea424b3334bb39d2 Reviewed-on: https://code.wireshark.org/review/8370 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wsutil/sha1.c')
-rw-r--r--wsutil/sha1.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/wsutil/sha1.c b/wsutil/sha1.c
index b7a2a76cef..3aaf557052 100644
--- a/wsutil/sha1.c
+++ b/wsutil/sha1.c
@@ -261,7 +261,7 @@ static guint8 sha1_padding[64] =
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
-void sha1_finish( sha1_context *ctx, guint8 digest[20] )
+void sha1_finish( sha1_context *ctx, guint8 digest[SHA1_DIGEST_LEN] )
{
guint32 last, padn;
guint32 high, low;
@@ -312,20 +312,20 @@ void sha1_hmac_update( sha1_hmac_context *hctx, const guint8 *buf, guint32 bufle
sha1_update( &hctx->ctx, buf, buflen );
}
-void sha1_hmac_finish( sha1_hmac_context *hctx, guint8 digest[20] )
+void sha1_hmac_finish( sha1_hmac_context *hctx, guint8 digest[SHA1_DIGEST_LEN] )
{
- guint8 tmpbuf[20];
+ guint8 tmpbuf[SHA1_DIGEST_LEN];
sha1_finish( &hctx->ctx, tmpbuf );
sha1_starts( &hctx->ctx );
sha1_update( &hctx->ctx, hctx->k_opad, 64 );
- sha1_update( &hctx->ctx, tmpbuf, 20 );
+ sha1_update( &hctx->ctx, tmpbuf, SHA1_DIGEST_LEN );
sha1_finish( &hctx->ctx, digest );
}
void sha1_hmac( const guint8 *key, guint32 keylen, const guint8 *buf, guint32 buflen,
- guint8 digest[20] )
+ guint8 digest[SHA1_DIGEST_LEN] )
{
sha1_hmac_context hctx;
@@ -365,7 +365,7 @@ int main( int argc, char *argv[] )
char output[41];
sha1_context ctx;
unsigned char buf[1000];
- unsigned char sha1sum[20];
+ unsigned char sha1sum[SHA1_DIGEST_LEN];
if( argc < 2 )
{
@@ -394,7 +394,7 @@ int main( int argc, char *argv[] )
sha1_finish( &ctx, sha1sum );
- for( j = 0; j < 20; j++ )
+ for( j = 0; j < SHA1_DIGEST_LEN; j++ )
{
g_snprintf( output + j * 2, 41-j*2, "%02x", sha1sum[j] );
}
@@ -427,7 +427,7 @@ int main( int argc, char *argv[] )
sha1_finish( &ctx, sha1sum );
- for( j = 0; j < 20; j++ )
+ for( j = 0; j < SHA1_DIGEST_LEN; j++ )
{
printf( "%02x", sha1sum[j] );
}