Browse Source

export byte swapping routine.

OPENBSD_2_0
millert 28 years ago
parent
commit
3d97fdc36a
2 changed files with 10 additions and 9 deletions
  1. +1
    -0
      src/include/sha1.h
  2. +9
    -9
      src/lib/libc/hash/sha1.c

+ 1
- 0
src/include/sha1.h View File

@ -52,5 +52,6 @@ void sha1Init __P((SHA1_INFO *));
void sha1Transform __P((SHA1_INFO *));
void sha1Final __P((SHA1_INFO *));
void sha1Update __P((SHA1_INFO *, unsigned char *, int));
void sha1ByteReverse __P((u_int32_t *, int));
#endif /* _SHA1_H */

+ 9
- 9
src/lib/libc/hash/sha1.c View File

@ -1,5 +1,5 @@
#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: sha1.c,v 1.3 1996/09/30 04:01:30 millert Exp $";
static char rcsid[] = "$OpenBSD: sha1.c,v 1.4 1996/09/30 23:27:05 millert Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@ -206,7 +206,7 @@ void sha1Transform(sha1Info)
makes for very slow code, so we rely on the user to sort out endianness
at compile time */
static void byteReverse(buffer, byteCount)
void sha1ByteReverse(buffer, byteCount)
LONG *buffer;
int byteCount;
{
@ -243,7 +243,7 @@ void sha1Update(sha1Info, buffer, count)
{
memcpy( (void *) sha1Info->data, (void *) buffer, SHA1_BLOCKSIZE );
#if BYTE_ORDER == LITTLE_ENDIAN
byteReverse( sha1Info->data, SHA1_BLOCKSIZE );
sha1ByteReverse( sha1Info->data, SHA1_BLOCKSIZE );
#endif /* LITTLE_ENDIAN */
sha1Transform( sha1Info );
buffer += SHA1_BLOCKSIZE;
@ -272,9 +272,9 @@ void sha1Final(sha1Info)
if( count > 56 )
{
/* Two lots of padding: Pad the first block to 64 bytes */
memset( ( void * ) sha1Info->data + count, 0, 64 - count );
memset( ( char * ) sha1Info->data + count, 0, 64 - count );
#if BYTE_ORDER == LITTLE_ENDIAN
byteReverse( sha1Info->data, SHA1_BLOCKSIZE );
sha1ByteReverse( sha1Info->data, SHA1_BLOCKSIZE );
#endif /* LITTLE_ENDIAN */
sha1Transform( sha1Info );
@ -283,9 +283,9 @@ void sha1Final(sha1Info)
}
else
/* Pad block to 56 bytes */
memset( ( void * ) sha1Info->data + count, 0, 56 - count );
memset( ( char * ) sha1Info->data + count, 0, 56 - count );
#if BYTE_ORDER == LITTLE_ENDIAN
byteReverse( sha1Info->data, SHA1_BLOCKSIZE );
sha1ByteReverse( sha1Info->data, SHA1_BLOCKSIZE );
#endif /* LITTLE_ENDIAN */
/* Append length in bits and transform */
@ -294,7 +294,7 @@ void sha1Final(sha1Info)
sha1Transform( sha1Info );
#if BYTE_ORDER == LITTLE_ENDIAN
byteReverse( sha1Info->data, SHA1_DIGESTSIZE );
sha1ByteReverse( sha1Info->data, SHA1_DIGESTSIZE );
#endif /* LITTLE_ENDIAN */
}
@ -344,7 +344,7 @@ void main()
/* Now perform time trial, generating MD for 10MB of data. First,
initialize the test data */
memset( data, 0, TEST_BLOCK_SIZE );
memset( ( void * ) data, 0, TEST_BLOCK_SIZE );
/* Get start time */
printf( "SHA1 time trial. Processing %ld characters...\n", TEST_BYTES );


Loading…
Cancel
Save