sha1.c revision 3f08fb69eb3b5f6eaa3c57160dff0998e1569283
/*
* Copyright (C) 2000, 2001 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: sha1.c,v 1.13 2004/03/04 01:43:24 marka Exp $ */
/* $NetBSD: sha1.c,v 1.5 2000/01/22 22:19:14 mycroft Exp $ */
/* $OpenBSD: sha1.c,v 1.9 1997/07/23 21:12:32 kstailey Exp $ */
/*
* SHA-1 in C
* By Steve Reid <steve@edmweb.com>
* 100% Public Domain
*
* Test Vectors (from FIPS PUB 180-1)
* "abc"
* A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
* "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
* 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
* A million repetitions of "a"
* 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
*/
#include "config.h"
#include <isc/assertions.h>
/*
* blk0() and blk() perform the initial expand.
* I got the idea of expanding during the round function from SSLeay
*/
#if !defined(WORDS_BIGENDIAN)
# define blk0(i) \
#else
#endif
#define blk(i) \
/*
* (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1
*/
#define R0(v,w,x,y,z,i) \
w = rol(w, 30);
#define R1(v,w,x,y,z,i) \
w = rol(w, 30);
#define R2(v,w,x,y,z,i) \
w = rol(w, 30);
#define R3(v,w,x,y,z,i) \
w = rol(w, 30);
#define R4(v,w,x,y,z,i) \
w = rol(w, 30);
typedef union {
unsigned char c[64];
unsigned int l[16];
} CHAR64LONG16;
#ifdef __sparc_v9__
static void
{
}
static void
{
}
static void
{
}
static void
{
}
#endif
/*
* Hash a single 512-bit block. This is the core of the algorithm.
*/
static void
isc_uint32_t a, b, c, d, e;
/* Copy context->state[] to working vars */
a = state[0];
b = state[1];
c = state[2];
d = state[3];
e = state[4];
#ifdef __sparc_v9__
#else
/* 4 rounds of 20 operations each. Loop unrolled. */
#endif
/* Add the working vars back into context.state[] */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
state[4] += e;
/* Wipe variables */
a = b = c = d = e = 0;
}
/*
* isc_sha1_init - Initialize new context
*/
void
{
/* SHA1 initialization constants */
}
void
}
/*
* Run your data through this.
*/
void
unsigned int len)
{
unsigned int i, j;
j = (j >> 3) & 63;
if ((j + len) > 63) {
j = 0;
} else {
i = 0;
}
}
/*
* Add padding and return the message digest.
*/
static const unsigned char final_200 = 128;
static const unsigned char final_0 = 0;
void
unsigned int i;
unsigned char finalcount[8];
for (i = 0; i < 8; i++) {
/* Endian independent */
finalcount[i] = (unsigned char)
>> ((3 - (i & 3)) * 8)) & 255);
}
/* The next Update should cause a transform() */
if (digest) {
for (i = 0; i < 20; i++)
digest[i] = (unsigned char)
>> ((3 - (i & 3)) * 8)) & 255);
}
}