xref: /openssh-portable/openbsd-compat/sha1.h (revision 81bfbd0b)
1*81bfbd0bSDamien Miller /*	$OpenBSD: sha1.h,v 1.24 2012/12/05 23:19:57 deraadt Exp $	*/
2*81bfbd0bSDamien Miller 
3*81bfbd0bSDamien Miller /*
4*81bfbd0bSDamien Miller  * SHA-1 in C
5*81bfbd0bSDamien Miller  * By Steve Reid <steve@edmweb.com>
6*81bfbd0bSDamien Miller  * 100% Public Domain
7*81bfbd0bSDamien Miller  */
8*81bfbd0bSDamien Miller 
9*81bfbd0bSDamien Miller #ifndef _SHA1_H
10*81bfbd0bSDamien Miller #define _SHA1_H
11*81bfbd0bSDamien Miller 
12*81bfbd0bSDamien Miller #ifndef WITH_OPENSSL
13*81bfbd0bSDamien Miller 
14*81bfbd0bSDamien Miller #define	SHA1_BLOCK_LENGTH		64
15*81bfbd0bSDamien Miller #define	SHA1_DIGEST_LENGTH		20
16*81bfbd0bSDamien Miller #define	SHA1_DIGEST_STRING_LENGTH	(SHA1_DIGEST_LENGTH * 2 + 1)
17*81bfbd0bSDamien Miller 
18*81bfbd0bSDamien Miller typedef struct {
19*81bfbd0bSDamien Miller     u_int32_t state[5];
20*81bfbd0bSDamien Miller     u_int64_t count;
21*81bfbd0bSDamien Miller     u_int8_t buffer[SHA1_BLOCK_LENGTH];
22*81bfbd0bSDamien Miller } SHA1_CTX;
23*81bfbd0bSDamien Miller 
24*81bfbd0bSDamien Miller void SHA1Init(SHA1_CTX *);
25*81bfbd0bSDamien Miller void SHA1Pad(SHA1_CTX *);
26*81bfbd0bSDamien Miller void SHA1Transform(u_int32_t [5], const u_int8_t [SHA1_BLOCK_LENGTH])
27*81bfbd0bSDamien Miller 	__attribute__((__bounded__(__minbytes__,1,5)))
28*81bfbd0bSDamien Miller 	__attribute__((__bounded__(__minbytes__,2,SHA1_BLOCK_LENGTH)));
29*81bfbd0bSDamien Miller void SHA1Update(SHA1_CTX *, const u_int8_t *, size_t)
30*81bfbd0bSDamien Miller 	__attribute__((__bounded__(__string__,2,3)));
31*81bfbd0bSDamien Miller void SHA1Final(u_int8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *)
32*81bfbd0bSDamien Miller 	__attribute__((__bounded__(__minbytes__,1,SHA1_DIGEST_LENGTH)));
33*81bfbd0bSDamien Miller char *SHA1End(SHA1_CTX *, char *)
34*81bfbd0bSDamien Miller 	__attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
35*81bfbd0bSDamien Miller char *SHA1File(const char *, char *)
36*81bfbd0bSDamien Miller 	__attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
37*81bfbd0bSDamien Miller char *SHA1FileChunk(const char *, char *, off_t, off_t)
38*81bfbd0bSDamien Miller 	__attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
39*81bfbd0bSDamien Miller char *SHA1Data(const u_int8_t *, size_t, char *)
40*81bfbd0bSDamien Miller 	__attribute__((__bounded__(__string__,1,2)))
41*81bfbd0bSDamien Miller 	__attribute__((__bounded__(__minbytes__,3,SHA1_DIGEST_STRING_LENGTH)));
42*81bfbd0bSDamien Miller 
43*81bfbd0bSDamien Miller #define HTONDIGEST(x) do {                                              \
44*81bfbd0bSDamien Miller         x[0] = htonl(x[0]);                                             \
45*81bfbd0bSDamien Miller         x[1] = htonl(x[1]);                                             \
46*81bfbd0bSDamien Miller         x[2] = htonl(x[2]);                                             \
47*81bfbd0bSDamien Miller         x[3] = htonl(x[3]);                                             \
48*81bfbd0bSDamien Miller         x[4] = htonl(x[4]); } while (0)
49*81bfbd0bSDamien Miller 
50*81bfbd0bSDamien Miller #define NTOHDIGEST(x) do {                                              \
51*81bfbd0bSDamien Miller         x[0] = ntohl(x[0]);                                             \
52*81bfbd0bSDamien Miller         x[1] = ntohl(x[1]);                                             \
53*81bfbd0bSDamien Miller         x[2] = ntohl(x[2]);                                             \
54*81bfbd0bSDamien Miller         x[3] = ntohl(x[3]);                                             \
55*81bfbd0bSDamien Miller         x[4] = ntohl(x[4]); } while (0)
56*81bfbd0bSDamien Miller 
57*81bfbd0bSDamien Miller #endif /* !WITH_OPENSSL */
58*81bfbd0bSDamien Miller #endif /* _SHA1_H */
59