/*
* FIPS-180-1 compliant SHA-1 implementation
*
- * $Id$
- *
* Copyright (C) 2001-2003 Christophe Devine
* Copyright (C) 2012 Chris Elston, Katalix Systems Ltd <celston@katalix.com>
*
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Changed to use guint instead of uint 2004 by Anders Broman
- * Original code found at http://www.cr0.net:8040/code/crypto/sha1/
+ * Original code found at http://www.cr0.net:8040/code/crypto/sha1/
* References: http://www.ietf.org/rfc/rfc3174.txt?number=3174
*
* 2012-08-21 - C Elston - Split sha1_hmac function to allow incremental usage.
#include <glib.h>
#include "sha1.h"
-#include "file_util.h"
#define GET_UINT32(n,b,i) \
{ \
static guint8 sha1_padding[64] =
{
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 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;
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;
#include <stdlib.h>
#include <stdio.h>
-#include <glib.h>
#include <errno.h>
/*
char output[41];
sha1_context ctx;
unsigned char buf[1000];
- unsigned char sha1sum[20];
+ unsigned char sha1sum[SHA1_DIGEST_LEN];
if( argc < 2 )
{
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] );
}
sha1_finish( &ctx, sha1sum );
- for( j = 0; j < 20; j++ )
+ for( j = 0; j < SHA1_DIGEST_LEN; j++ )
{
printf( "%02x", sha1sum[j] );
}
#endif
+
+/*
+ * Editor modelines - http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */