xref: /openbsd/include/sha1.h (revision 4a39ccd0)
1*4a39ccd0Sderaadt /*	$OpenBSD: sha1.h,v 1.24 2012/12/05 23:19:57 deraadt Exp $	*/
2d7005814Smillert 
3e7ee6cdcSmillert /*
4e7ee6cdcSmillert  * SHA-1 in C
5e7ee6cdcSmillert  * By Steve Reid <steve@edmweb.com>
6e7ee6cdcSmillert  * 100% Public Domain
7e7ee6cdcSmillert  */
8d7005814Smillert 
9a10e7b05Smillert #ifndef _SHA1_H
10a10e7b05Smillert #define _SHA1_H
11a10e7b05Smillert 
12e5c6a985Smillert #define	SHA1_BLOCK_LENGTH		64
13e5c6a985Smillert #define	SHA1_DIGEST_LENGTH		20
14e5c6a985Smillert #define	SHA1_DIGEST_STRING_LENGTH	(SHA1_DIGEST_LENGTH * 2 + 1)
15e5c6a985Smillert 
16d7005814Smillert typedef struct {
17e7ee6cdcSmillert     u_int32_t state[5];
1884306cf4Smillert     u_int64_t count;
19e5c6a985Smillert     u_int8_t buffer[SHA1_BLOCK_LENGTH];
20e7ee6cdcSmillert } SHA1_CTX;
21d7005814Smillert 
22232cf197Smillert __BEGIN_DECLS
2384306cf4Smillert void SHA1Init(SHA1_CTX *);
249dfc8d30Smillert void SHA1Pad(SHA1_CTX *);
25687924d3Smillert void SHA1Transform(u_int32_t [5], const u_int8_t [SHA1_BLOCK_LENGTH])
26d9dd16ceSavsm 	__attribute__((__bounded__(__minbytes__,1,5)))
27e5c6a985Smillert 	__attribute__((__bounded__(__minbytes__,2,SHA1_BLOCK_LENGTH)));
289dfc8d30Smillert void SHA1Update(SHA1_CTX *, const u_int8_t *, size_t)
29d9dd16ceSavsm 	__attribute__((__bounded__(__string__,2,3)));
30e5c6a985Smillert void SHA1Final(u_int8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *)
31e5c6a985Smillert 	__attribute__((__bounded__(__minbytes__,1,SHA1_DIGEST_LENGTH)));
326cb58d42Smillert char *SHA1End(SHA1_CTX *, char *)
33e5c6a985Smillert 	__attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
34e4803734Sjfb char *SHA1File(const char *, char *)
35e5c6a985Smillert 	__attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
36e4803734Sjfb char *SHA1FileChunk(const char *, char *, off_t, off_t)
379dfc8d30Smillert 	__attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
386cb58d42Smillert char *SHA1Data(const u_int8_t *, size_t, char *)
39d9dd16ceSavsm 	__attribute__((__bounded__(__string__,1,2)))
40e5c6a985Smillert 	__attribute__((__bounded__(__minbytes__,3,SHA1_DIGEST_STRING_LENGTH)));
41232cf197Smillert __END_DECLS
42a10e7b05Smillert 
43232cf197Smillert #define HTONDIGEST(x) do {                                              \
445a7ec767Sangelos         x[0] = htonl(x[0]);                                             \
455a7ec767Sangelos         x[1] = htonl(x[1]);                                             \
465a7ec767Sangelos         x[2] = htonl(x[2]);                                             \
475a7ec767Sangelos         x[3] = htonl(x[3]);                                             \
48232cf197Smillert         x[4] = htonl(x[4]); } while (0)
495a7ec767Sangelos 
50232cf197Smillert #define NTOHDIGEST(x) do {                                              \
515a7ec767Sangelos         x[0] = ntohl(x[0]);                                             \
525a7ec767Sangelos         x[1] = ntohl(x[1]);                                             \
535a7ec767Sangelos         x[2] = ntohl(x[2]);                                             \
545a7ec767Sangelos         x[3] = ntohl(x[3]);                                             \
55232cf197Smillert         x[4] = ntohl(x[4]); } while (0)
565a7ec767Sangelos 
57a10e7b05Smillert #endif /* _SHA1_H */
58