Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 1 | /* $OpenBSD: sha1.h,v 1.23 2004/06/22 01:57:30 jfb Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * SHA-1 in C |
| 5 | * By Steve Reid <steve@edmweb.com> |
| 6 | * 100% Public Domain |
| 7 | */ |
| 8 | |
| 9 | #ifndef _SHA1_H |
| 10 | #define _SHA1_H |
| 11 | |
| 12 | #define SHA1_BLOCK_LENGTH 64 |
| 13 | #define SHA1_DIGEST_LENGTH 20 |
| 14 | #define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1) |
| 15 | |
| 16 | typedef struct { |
| 17 | uint32_t state[5]; |
| 18 | uint64_t count; |
| 19 | uint8_t buffer[SHA1_BLOCK_LENGTH]; |
| 20 | } SHA1_CTX; |
| 21 | |
| 22 | void SHA1Init(SHA1_CTX *); |
| 23 | void SHA1Pad(SHA1_CTX *); |
| 24 | void SHA1Transform(uint32_t [5], const uint8_t [SHA1_BLOCK_LENGTH]); |
| 25 | void SHA1Update(SHA1_CTX *, const uint8_t *, size_t); |
| 26 | void SHA1Final(uint8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *); |
| 27 | |
| 28 | #define HTONDIGEST(x) do { \ |
| 29 | x[0] = htonl(x[0]); \ |
| 30 | x[1] = htonl(x[1]); \ |
| 31 | x[2] = htonl(x[2]); \ |
| 32 | x[3] = htonl(x[3]); \ |
| 33 | x[4] = htonl(x[4]); } while (0) |
| 34 | |
| 35 | #define NTOHDIGEST(x) do { \ |
| 36 | x[0] = ntohl(x[0]); \ |
| 37 | x[1] = ntohl(x[1]); \ |
| 38 | x[2] = ntohl(x[2]); \ |
| 39 | x[3] = ntohl(x[3]); \ |
| 40 | x[4] = ntohl(x[4]); } while (0) |
| 41 | |
| 42 | #endif /* _SHA1_H */ |