sha1.c revision 22bed621ef87bc8b6c1fea599b02c4b38dd6bf48
/*
* Copyright (C) 2000, 2001, 2003-2005, 2007, 2009, 2011, 2012, 2014, 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id$ */
/* $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 $ */
/*! \file
* SHA-1 in C
* \author By Steve Reid <steve@edmweb.com>
* 100% Public Domain
* \verbatim
* 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
* \endverbatim
*/
#include "config.h"
#include <isc/assertions.h>
#include <isc/platform.h>
#if PKCS11CRYPTO
#include <pk11/internal.h>
#endif
#ifdef ISC_PLATFORM_OPENSSLHASH
#endif
void
{
}
void
}
void
unsigned int len)
{
(const void *) data,
}
void
}
void
}
void
return;
}
void
}
void
}
#else
/*@{*/
/*!
* 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;
/* Avoid compiler warnings */
}
/*!
* 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);
}
}
#endif