• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*	$OpenBSD: sha1.h,v 1.24 2012/12/05 23:19:57 deraadt 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 #include <stddef.h>
13 #include <stdint.h>
14 
15 #define	SHA1_BLOCK_LENGTH		64
16 #define	SHA1_DIGEST_LENGTH		20
17 #define	SHA1_DIGEST_STRING_LENGTH	(SHA1_DIGEST_LENGTH * 2 + 1)
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 typedef struct _SHA1_CTX {
24     uint32_t state[5];
25     uint64_t count;
26     uint8_t buffer[SHA1_BLOCK_LENGTH];
27 } SHA1_CTX;
28 
29 void SHA1Init(SHA1_CTX *);
30 void SHA1Update(SHA1_CTX *, const uint8_t *, size_t);
31 void SHA1Final(uint8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *);
32 
33 #define HTONDIGEST(x) do {                                              \
34         x[0] = htonl(x[0]);                                             \
35         x[1] = htonl(x[1]);                                             \
36         x[2] = htonl(x[2]);                                             \
37         x[3] = htonl(x[3]);                                             \
38         x[4] = htonl(x[4]); } while (0)
39 
40 #define NTOHDIGEST(x) do {                                              \
41         x[0] = ntohl(x[0]);                                             \
42         x[1] = ntohl(x[1]);                                             \
43         x[2] = ntohl(x[2]);                                             \
44         x[3] = ntohl(x[3]);                                             \
45         x[4] = ntohl(x[4]); } while (0)
46 
47 #ifdef __cplusplus
48 }
49 #endif
50 
51 #endif /* _SHA1_H */
52