source
code documentation
sha1.c File Reference
Detailed Description
RFC 3174 - US Secure Hash Algorithm 1 (SHA1) and RFC 2104 - HMAC: Keyed-Hashing for Message Authentication.
- Author:
- Christian Scheurer <http://www.christianscheurer.ch>
OUTLINE: RFC3174 (US Secure Hash Algorithm 1 (SHA1)) implementation. Requires Infineon C167 MCU and Keil C166 compiler.
IMPLEMENTATION: "This product includes cryptographic software written by Eric Young (eay@cryptsoft.com)" (taken form www.openssl.org)"
NOTES:
This document is part of embedded IPsec
Copyright (c) 2003 Niklaus Schild and Christian Scheurer, HTI Biel/Bienne
All rights reserved.
This file contains code from the OpenSSL Project
portions Copyright (c) 1998-2003 OpenSSL (www.openssl.org)
Definition in file sha1.c.
#include <string.h>
#include "ipsec/sha1.h"
#include "ipsec/debug.h"
Go to the source code of this file.
|
Defines |
#define | Xupdate(a, ix, ia, ib, ic, id) |
#define | SHA_CBLOCK (SHA_LBLOCK*4) |
#define | SHA_LAST_BLOCK (SHA_CBLOCK-8) |
#define | SHA_LBLOCK (SHA_CBLOCK/4) |
#define | HOST_c2l(c, l) |
#define | HOST_p_c2l(c, l, n) |
#define | HOST_p_c2l_p(c, l, sc, len) |
#define | HOST_c2l_p(c, l, n) |
#define | HOST_l2c(l, c) |
#define | INIT_DATA_h0 0x67452301UL |
#define | INIT_DATA_h1 0xefcdab89UL |
#define | INIT_DATA_h2 0x98badcfeUL |
#define | INIT_DATA_h3 0x10325476UL |
#define | INIT_DATA_h4 0xc3d2e1f0UL |
#define | K_00_19 0x5a827999UL |
#define | K_20_39 0x6ed9eba1UL |
#define | K_40_59 0x8f1bbcdcUL |
#define | K_60_79 0xca62c1d6UL |
#define | F_00_19(b, c, d) ((((c) ^ (d)) & (b)) ^ (d)) |
#define | F_20_39(b, c, d) ((b) ^ (c) ^ (d)) |
#define | F_40_59(b, c, d) (((b) & (c)) | (((b)|(c)) & (d))) |
#define | F_60_79(b, c, d) F_20_39(b,c,d) |
#define | BODY_00_15(i, a, b, c, d, e, f, xi) |
#define | BODY_16_19(i, a, b, c, d, e, f, xi, xa, xb, xc, xd) |
#define | BODY_20_31(i, a, b, c, d, e, f, xi, xa, xb, xc, xd) |
#define | BODY_32_39(i, a, b, c, d, e, f, xa, xb, xc, xd) |
#define | BODY_40_59(i, a, b, c, d, e, f, xa, xb, xc, xd) |
#define | BODY_60_79(i, a, b, c, d, e, f, xa, xb, xc, xd) |
#define | X(i) XX##i |
Functions |
unsigned char * | SHA1 (const unsigned char *d, unsigned long n, unsigned char *md) |
void | sha1_block_host_order (SHA_CTX *c, const void *p, int num) |
void | sha1_block_data_order (SHA_CTX *c, const void *p, int num) |
void | SHA1_Update (SHA_CTX *c, const void *data_, unsigned long len) |
void | SHA1_Transform (SHA_CTX *c, const unsigned char *data) |
void | SHA1_Final (unsigned char *md, SHA_CTX *c) |
void | SHA1_Init (SHA_CTX *c) |
void | hmac_sha1 (unsigned char *text, int text_len, unsigned char *key, int key_len, unsigned char *digest) |
Define Documentation
#define BODY_00_15 |
( |
i, |
|
|
a, |
|
|
b, |
|
|
c, |
|
|
d, |
|
|
e, |
|
|
f, |
|
|
xi |
|
) |
|
|
|
Value:
Definition at line 336 of file sha1.c. |
#define BODY_16_19 |
( |
i, |
|
|
a, |
|
|
b, |
|
|
c, |
|
|
d, |
|
|
e, |
|
|
f, |
|
|
xi, |
|
|
xa, |
|
|
xb, |
|
|
xc, |
|
|
xd |
|
) |
|
|
|
Value:
Definition at line 340 of file sha1.c. |
#define BODY_20_31 |
( |
i, |
|
|
a, |
|
|
b, |
|
|
c, |
|
|
d, |
|
|
e, |
|
|
f, |
|
|
xi, |
|
|
xa, |
|
|
xb, |
|
|
xc, |
|
|
xd |
|
) |
|
|
|
Value:
Definition at line 345 of file sha1.c. |
#define BODY_32_39 |
( |
i, |
|
|
a, |
|
|
b, |
|
|
c, |
|
|
d, |
|
|
e, |
|
|
f, |
|
|
xa, |
|
|
xb, |
|
|
xc, |
|
|
xd |
|
) |
|
|
|
Value:
Definition at line 350 of file sha1.c. |
#define BODY_40_59 |
( |
i, |
|
|
a, |
|
|
b, |
|
|
c, |
|
|
d, |
|
|
e, |
|
|
f, |
|
|
xa, |
|
|
xb, |
|
|
xc, |
|
|
xd |
|
) |
|
|
|
Value:
Definition at line 355 of file sha1.c. |
#define BODY_60_79 |
( |
i, |
|
|
a, |
|
|
b, |
|
|
c, |
|
|
d, |
|
|
e, |
|
|
f, |
|
|
xa, |
|
|
xb, |
|
|
xc, |
|
|
xd |
|
) |
|
|
|
Value:
Definition at line 360 of file sha1.c. |
#define F_00_19 |
( |
b, |
|
|
c, |
|
|
d |
|
) |
((((c) ^ (d)) & (b)) ^ (d))
|
|
#define F_20_39 |
( |
b, |
|
|
c, |
|
|
d |
|
) |
((b) ^ (c) ^ (d))
|
|
#define F_40_59 |
( |
b, |
|
|
c, |
|
|
d |
|
) |
(((b) & (c)) | (((b)|(c)) & (d)))
|
|
#define F_60_79 |
( |
b, |
|
|
c, |
|
|
d |
|
) |
F_20_39(b,c,d)
|
|
#define HOST_c2l |
( |
c, |
|
|
l |
|
) |
|
|
|
Value: (l =(((unsigned long)(*((c)++)))<<24), \
l|=(((unsigned long)(*((c)++)))<<16), \
l|=(((unsigned long)(*((c)++)))<< 8), \
l|=(((unsigned long)(*((c)++))) ), \
l)
Definition at line 119 of file sha1.c. |
#define HOST_c2l_p |
( |
c, |
|
|
l, |
|
|
n |
|
) |
|
|
|
Value: { \
l=0; (c)+=n; \
switch (n) { \
case 3: l =((unsigned long)(*(--(c))))<< 8; \
case 2: l|=((unsigned long)(*(--(c))))<<16; \
case 1: l|=((unsigned long)(*(--(c))))<<24; \
} }
Definition at line 140 of file sha1.c. |
#define HOST_l2c |
( |
l, |
|
|
c |
|
) |
|
|
|
Value: (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
*((c)++)=(unsigned char)(((l)>>16)&0xff), \
*((c)++)=(unsigned char)(((l)>> 8)&0xff), \
*((c)++)=(unsigned char)(((l) )&0xff), \
l)
Definition at line 147 of file sha1.c. |
#define HOST_p_c2l |
( |
c, |
|
|
l, |
|
|
n |
|
) |
|
|
|
Value: { \
switch (n) { \
case 0: l =((unsigned long)(*((c)++)))<<24; \
case 1: l|=((unsigned long)(*((c)++)))<<16; \
case 2: l|=((unsigned long)(*((c)++)))<< 8; \
case 3: l|=((unsigned long)(*((c)++))); \
} }
Definition at line 124 of file sha1.c. |
#define HOST_p_c2l_p |
( |
c, |
|
|
l, |
|
|
sc, |
|
|
len |
|
) |
|
|
|
Value: { \
switch (sc) { \
case 0: l =((unsigned long)(*((c)++)))<<24; \
if (--len == 0) break; \
case 1: l|=((unsigned long)(*((c)++)))<<16; \
if (--len == 0) break; \
case 2: l|=((unsigned long)(*((c)++)))<< 8; \
} }
Definition at line 131 of file sha1.c. |
#define INIT_DATA_h0 0x67452301UL
|
|
#define INIT_DATA_h1 0xefcdab89UL
|
|
#define INIT_DATA_h2 0x98badcfeUL
|
|
#define INIT_DATA_h3 0x10325476UL
|
|
#define INIT_DATA_h4 0xc3d2e1f0UL
|
|
#define K_00_19 0x5a827999UL
|
|
#define K_20_39 0x6ed9eba1UL
|
|
#define K_40_59 0x8f1bbcdcUL
|
|
#define K_60_79 0xca62c1d6UL
|
|
#define SHA_CBLOCK (SHA_LBLOCK*4)
|
|
#define SHA_LAST_BLOCK (SHA_CBLOCK-8)
|
|
#define SHA_LBLOCK (SHA_CBLOCK/4)
|
|
#define Xupdate |
( |
a, |
|
|
ix, |
|
|
ia, |
|
|
ib, |
|
|
ic, |
|
|
id |
|
) |
|
|
|
Value: ( (a)=(ia^ib^ic^id), \
ix=(a)=ROTATE((a),1) \
)
Definition at line 73 of file sha1.c. |
Function Documentation
void hmac_sha1 |
( |
unsigned char * |
text, |
|
|
int |
text_len, |
|
|
unsigned char * |
key, |
|
|
int |
key_len, |
|
|
unsigned char * |
digest |
|
) |
|
|
unsigned char* SHA1 |
( |
const unsigned char * |
d, |
|
|
unsigned long |
n, |
|
|
unsigned char * |
md |
|
) |
|
|
void sha1_block_data_order |
( |
SHA_CTX * |
c, |
|
|
const void * |
p, |
|
|
int |
num |
|
) |
|
|
void sha1_block_host_order |
( |
SHA_CTX * |
c, |
|
|
const void * |
p, |
|
|
int |
num |
|
) |
|
|
void SHA1_Final |
( |
unsigned char * |
md, |
|
|
SHA_CTX * |
c |
|
) |
|
|
void SHA1_Transform |
( |
SHA_CTX * |
c, |
|
|
const unsigned char * |
data |
|
) |
|
|
void SHA1_Update |
( |
SHA_CTX * |
c, |
|
|
const void * |
data_, |
|
|
unsigned long |
len |
|
) |
|
|
|