| 1 |
/* -*- Mode: C; c-file-style: "stroustrup" -*- */ |
| 2 |
|
| 3 |
#if !defined( _sha1_h ) |
| 4 |
#define _sha1_h |
| 5 |
|
| 6 |
/* for size_t */ |
| 7 |
#include <string.h> |
| 8 |
#include "types.h" |
| 9 |
|
| 10 |
#if defined( __cplusplus ) |
| 11 |
extern "C" { |
| 12 |
#endif |
| 13 |
|
| 14 |
#define SHA1_INPUT_BYTES 64 /* 512 bits */ |
| 15 |
#define SHA1_INPUT_WORDS ( SHA1_INPUT_BYTES >> 2 ) |
| 16 |
#define SHA1_DIGEST_WORDS 5 /* 160 bits */ |
| 17 |
#define SHA1_DIGEST_BYTES ( SHA1_DIGEST_WORDS * 4 ) |
| 18 |
|
| 19 |
#if defined( OPENSSL ) |
| 20 |
|
| 21 |
#include <openssl/sha.h> |
| 22 |
#define SHA1_ctx SHA_CTX |
| 23 |
#define SHA1_Final( ctx, digest ) SHA1_Final( digest, ctx ) |
| 24 |
#undef SHA1_DIGEST_BYTES |
| 25 |
#define SHA1_DIGEST_BYTES SHA_DIGEST_LENGTH |
| 26 |
|
| 27 |
#define SHA1_Init_With_IV( ctx, iv ) \ |
| 28 |
do { \ |
| 29 |
(ctx)->h0 = iv[0]; \ |
| 30 |
(ctx)->h1 = iv[1]; \ |
| 31 |
(ctx)->h2 = iv[2]; \ |
| 32 |
(ctx)->h3 = iv[3]; \ |
| 33 |
(ctx)->h4 = iv[4]; \ |
| 34 |
(ctx)->Nh = 0; \ |
| 35 |
(ctx)->Nl = 0; \ |
| 36 |
(ctx)->num = 0l \ |
| 37 |
} while (0) |
| 38 |
|
| 39 |
#define SHA1_Transform( iv, data ) SHA1_Xform( iv, data ) |
| 40 |
|
| 41 |
#else |
| 42 |
|
| 43 |
typedef struct { |
| 44 |
word32 H[ SHA1_DIGEST_WORDS ]; |
| 45 |
#if defined( word64 ) |
| 46 |
word64 bits; /* we want a 64 bit word */ |
| 47 |
#else |
| 48 |
word32 hbits, lbits; /* if we don't have one we simulate it */ |
| 49 |
#endif |
| 50 |
byte M[ SHA1_INPUT_BYTES ]; |
| 51 |
} SHA1_ctx; |
| 52 |
|
| 53 |
void SHA1_Init ( SHA1_ctx* ); |
| 54 |
void SHA1_Update( SHA1_ctx*, const void*, size_t ); |
| 55 |
void SHA1_Final ( SHA1_ctx*, byte[ SHA1_DIGEST_BYTES ] ); |
| •56 |
void SHA1_Transform( word32 H[ SHA1_DIGEST_WORDS ], |
| 57 |
const byte M[ SHA1_INPUT_BYTES ] ); |
| 58 |
|
| 59 |
/* these provide extra access to internals of SHA1 for MDC and MACs */ |
| 60 |
|
| 61 |
void SHA1_Init_With_IV( SHA1_ctx*, const byte[ SHA1_DIGEST_BYTES ] ); |
| 62 |
|
| 63 |
#endif |
| 64 |
|
| 65 |
void SHA1_Xform( word32[ SHA1_DIGEST_WORDS ], |
| 66 |
const byte[ SHA1_INPUT_BYTES ] ); |
| 67 |
|
| 68 |
#if defined( __cplusplus ) |
| 69 |
} |
| 70 |
#endif |
| 71 |
|
| 72 |
#endif |