embedded IPsec 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:

(f)=xi+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
        (b)=ROTATE((b),30);

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:

Xupdate(f,xi,xa,xb,xc,xd); \
        (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
        (b)=ROTATE((b),30);

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:

Xupdate(f,xi,xa,xb,xc,xd); \
        (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
        (b)=ROTATE((b),30);

Definition at line 345 of file sha1.c.

#define BODY_32_39 i,
a,
b,
c,
d,
e,
f,
xa,
xb,
xc,
xd   ) 
 

Value:

Xupdate(f,xa,xa,xb,xc,xd); \
        (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
        (b)=ROTATE((b),30);

Definition at line 350 of file sha1.c.

#define BODY_40_59 i,
a,
b,
c,
d,
e,
f,
xa,
xb,
xc,
xd   ) 
 

Value:

Xupdate(f,xa,xa,xb,xc,xd); \
        (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \
        (b)=ROTATE((b),30);

Definition at line 355 of file sha1.c.

#define BODY_60_79 i,
a,
b,
c,
d,
e,
f,
xa,
xb,
xc,
xd   ) 
 

Value:

Xupdate(f,xa,xa,xb,xc,xd); \
        (f)=xa+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \
        (b)=ROTATE((b),30);

Definition at line 360 of file sha1.c.

#define F_00_19 b,
c,
 )     ((((c) ^ (d)) & (b)) ^ (d))
 

Definition at line 331 of file sha1.c.

#define F_20_39 b,
c,
 )     ((b) ^ (c) ^ (d))
 

Definition at line 332 of file sha1.c.

#define F_40_59 b,
c,
 )     (((b) & (c)) | (((b)|(c)) & (d)))
 

Definition at line 333 of file sha1.c.

#define F_60_79 b,
c,
 )     F_20_39(b,c,d)
 

Definition at line 334 of file sha1.c.

#define HOST_c2l c,
 ) 
 

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,
 ) 
 

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,
 ) 
 

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,
 ) 
 

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
 

Definition at line 301 of file sha1.c.

#define INIT_DATA_h1   0xefcdab89UL
 

Definition at line 302 of file sha1.c.

#define INIT_DATA_h2   0x98badcfeUL
 

Definition at line 303 of file sha1.c.

#define INIT_DATA_h3   0x10325476UL
 

Definition at line 304 of file sha1.c.

#define INIT_DATA_h4   0xc3d2e1f0UL
 

Definition at line 305 of file sha1.c.

#define K_00_19   0x5a827999UL
 

Definition at line 319 of file sha1.c.

#define K_20_39   0x6ed9eba1UL
 

Definition at line 320 of file sha1.c.

#define K_40_59   0x8f1bbcdcUL
 

Definition at line 321 of file sha1.c.

#define K_60_79   0xca62c1d6UL
 

Definition at line 322 of file sha1.c.

#define SHA_CBLOCK   (SHA_LBLOCK*4)
 

Definition at line 82 of file sha1.c.

#define SHA_LAST_BLOCK   (SHA_CBLOCK-8)
 

Definition at line 85 of file sha1.c.

#define SHA_LBLOCK   (SHA_CBLOCK/4)
 

Definition at line 91 of file sha1.c.

#define X  )     XX##i
 

Definition at line 366 of file sha1.c.

#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
 

Definition at line 620 of file sha1.c.

unsigned char* SHA1 const unsigned char *  d,
unsigned long  n,
unsigned char *  md
 

Definition at line 59 of file sha1.c.

void sha1_block_data_order SHA_CTX c,
const void *  p,
int  num
 

Definition at line 487 of file sha1.c.

void sha1_block_host_order SHA_CTX c,
const void *  p,
int  num
 

Definition at line 368 of file sha1.c.

void SHA1_Final unsigned char *  md,
SHA_CTX c
 

Definition at line 251 of file sha1.c.

void SHA1_Init SHA_CTX c  ) 
 

Definition at line 307 of file sha1.c.

void SHA1_Transform SHA_CTX c,
const unsigned char *  data
 

Definition at line 245 of file sha1.c.

void SHA1_Update SHA_CTX c,
const void *  data_,
unsigned long  len
 

Definition at line 158 of file sha1.c.


Copyright 2003 by Christian Scheurer and Niklaus Schild