sha1.c File Reference

#include "config.h"
#include <isc/assertions.h>
#include <isc/platform.h>
#include <isc/sha1.h>
#include <isc/string.h>
#include <isc/types.h>
#include <isc/util.h>

Go to the source code of this file.

Data Structures

union  CHAR64LONG16

Defines

#define rol(value, bits)   (((value) << (bits)) | ((value) >> (32 - (bits))))
#define blk0(i)
#define blk(i)
#define R0(v, w, x, y, z, i)
#define R1(v, w, x, y, z, i)
#define R2(v, w, x, y, z, i)
#define R3(v, w, x, y, z, i)
#define R4(v, w, x, y, z, i)

Functions

static void transform (isc_uint32_t state[5], const unsigned char buffer[64])
void isc_sha1_init (isc_sha1_t *context)
void isc_sha1_invalidate (isc_sha1_t *context)
void isc_sha1_update (isc_sha1_t *context, const unsigned char *data, unsigned int len)
void isc_sha1_final (isc_sha1_t *context, unsigned char *digest)

Variables

static const unsigned char final_200 = 128
static const unsigned char final_0 = 0


Detailed Description

SHA-1 in C
Author:
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
 * 

Definition in file sha1.c.


Define Documentation

#define rol ( value,
bits   )     (((value) << (bits)) | ((value) >> (32 - (bits))))

Definition at line 132 of file sha1.c.

#define blk0 (  ) 

Value:

(block->l[i] = (rol(block->l[i], 24) & 0xFF00FF00) \
         | (rol(block->l[i], 8) & 0x00FF00FF))
blk0() and blk() perform the initial expand. I got the idea of expanding during the round function from SSLeay

Definition at line 140 of file sha1.c.

#define blk (  ) 

Value:

(block->l[i & 15] = rol(block->l[(i + 13) & 15] \
                                ^ block->l[(i + 8) & 15] \
                                ^ block->l[(i + 2) & 15] \
                                ^ block->l[i & 15], 1))
blk0() and blk() perform the initial expand. I got the idea of expanding during the round function from SSLeay

Definition at line 145 of file sha1.c.

#define R0 ( v,
w,
x,
y,
z,
 ) 

Value:

z += ((w & (x ^ y)) ^ y) + blk0(i) + 0x5A827999 + rol(v, 5); \
        w = rol(w, 30);
(R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1

Definition at line 156 of file sha1.c.

Referenced by transform().

#define R1 ( v,
w,
x,
y,
z,
 ) 

Value:

z += ((w & (x ^ y)) ^ y) + blk(i) + 0x5A827999 + rol(v, 5); \
        w = rol(w, 30);
(R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1

Definition at line 159 of file sha1.c.

Referenced by transform().

#define R2 ( v,
w,
x,
y,
z,
 ) 

Value:

z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); \
        w = rol(w, 30);
(R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1

Definition at line 162 of file sha1.c.

Referenced by transform().

#define R3 ( v,
w,
x,
y,
z,
 ) 

Value:

z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + rol(v, 5); \
        w = rol(w, 30);
(R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1

Definition at line 165 of file sha1.c.

Referenced by transform().

#define R4 ( v,
w,
x,
y,
z,
 ) 

Value:

z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); \
        w = rol(w, 30);
(R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1

Definition at line 168 of file sha1.c.

Referenced by transform().


Function Documentation

static void transform ( isc_uint32_t  state[5],
const unsigned char  buffer[64] 
) [static]

Hash a single 512-bit block. This is the core of the algorithm.

Definition at line 252 of file sha1.c.

References block, INSIST, POST, R0, R1, R2, R3, and R4.

void isc_sha1_init ( isc_sha1_t context  ) 

isc_sha1_init - Initialize new context

Definition at line 317 of file sha1.c.

References isc_sha1_t::count, INSIST, and isc_sha1_t::state.

Referenced by ATF_TC_BODY(), dns_ds_buildrdata(), hmacsha1_fromdns(), isc_entropy_getdata(), isc_hmacsha1_init(), isc_hmacsha1_sign(), and isc_iterated_hash().

void isc_sha1_invalidate ( isc_sha1_t context  ) 

Definition at line 332 of file sha1.c.

Referenced by isc_hmacsha1_invalidate().

void isc_sha1_update ( isc_sha1_t context,
const unsigned char *  data,
unsigned int  len 
)

Run your data through this.

Definition at line 340 of file sha1.c.

References isc_sha1_t::buffer, isc_sha1_t::count, INSIST, isc_sha1_t::state, and transform().

Referenced by ATF_TC_BODY(), dns_ds_buildrdata(), hmacsha1_fromdns(), isc_entropy_getdata(), isc_hmacsha1_init(), isc_hmacsha1_sign(), isc_hmacsha1_update(), isc_iterated_hash(), and isc_sha1_final().

void isc_sha1_final ( isc_sha1_t context,
unsigned char *  digest 
)

Definition at line 374 of file sha1.c.

References isc_sha1_t::count, INSIST, isc_sha1_update(), and isc_sha1_t::state.

Referenced by ATF_TC_BODY(), dns_ds_buildrdata(), hmacsha1_fromdns(), isc_entropy_getdata(), isc_hmacsha1_init(), isc_hmacsha1_sign(), and isc_iterated_hash().


Variable Documentation

const unsigned char final_200 = 128 [static]

Add padding and return the message digest.

Definition at line 370 of file sha1.c.

const unsigned char final_0 = 0 [static]

Definition at line 371 of file sha1.c.


Generated on Tue Apr 28 17:41:18 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha