1285031Sdes/*	$OpenBSD: sha1.h,v 1.24 2012/12/05 23:19:57 deraadt Exp $	*/
2285031Sdes
3285031Sdes/*
4285031Sdes * SHA-1 in C
5285031Sdes * By Steve Reid <steve@edmweb.com>
6285031Sdes * 100% Public Domain
7285031Sdes */
8285031Sdes
9285031Sdes#ifndef _SHA1_H
10285031Sdes#define _SHA1_H
11285031Sdes
12285031Sdes#ifndef WITH_OPENSSL
13285031Sdes
14285031Sdes#define	SHA1_BLOCK_LENGTH		64
15285031Sdes#define	SHA1_DIGEST_LENGTH		20
16285031Sdes#define	SHA1_DIGEST_STRING_LENGTH	(SHA1_DIGEST_LENGTH * 2 + 1)
17285031Sdes
18285031Sdestypedef struct {
19285031Sdes    u_int32_t state[5];
20285031Sdes    u_int64_t count;
21285031Sdes    u_int8_t buffer[SHA1_BLOCK_LENGTH];
22285031Sdes} SHA1_CTX;
23285031Sdes
24285031Sdesvoid SHA1Init(SHA1_CTX *);
25285031Sdesvoid SHA1Pad(SHA1_CTX *);
26285031Sdesvoid SHA1Transform(u_int32_t [5], const u_int8_t [SHA1_BLOCK_LENGTH])
27285031Sdes	__attribute__((__bounded__(__minbytes__,1,5)))
28285031Sdes	__attribute__((__bounded__(__minbytes__,2,SHA1_BLOCK_LENGTH)));
29285031Sdesvoid SHA1Update(SHA1_CTX *, const u_int8_t *, size_t)
30285031Sdes	__attribute__((__bounded__(__string__,2,3)));
31285031Sdesvoid SHA1Final(u_int8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *)
32285031Sdes	__attribute__((__bounded__(__minbytes__,1,SHA1_DIGEST_LENGTH)));
33285031Sdeschar *SHA1End(SHA1_CTX *, char *)
34285031Sdes	__attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
35285031Sdeschar *SHA1File(const char *, char *)
36285031Sdes	__attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
37285031Sdeschar *SHA1FileChunk(const char *, char *, off_t, off_t)
38285031Sdes	__attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
39285031Sdeschar *SHA1Data(const u_int8_t *, size_t, char *)
40285031Sdes	__attribute__((__bounded__(__string__,1,2)))
41285031Sdes	__attribute__((__bounded__(__minbytes__,3,SHA1_DIGEST_STRING_LENGTH)));
42285031Sdes
43285031Sdes#define HTONDIGEST(x) do {                                              \
44285031Sdes        x[0] = htonl(x[0]);                                             \
45285031Sdes        x[1] = htonl(x[1]);                                             \
46285031Sdes        x[2] = htonl(x[2]);                                             \
47285031Sdes        x[3] = htonl(x[3]);                                             \
48285031Sdes        x[4] = htonl(x[4]); } while (0)
49285031Sdes
50285031Sdes#define NTOHDIGEST(x) do {                                              \
51285031Sdes        x[0] = ntohl(x[0]);                                             \
52285031Sdes        x[1] = ntohl(x[1]);                                             \
53285031Sdes        x[2] = ntohl(x[2]);                                             \
54285031Sdes        x[3] = ntohl(x[3]);                                             \
55285031Sdes        x[4] = ntohl(x[4]); } while (0)
56285031Sdes
57285031Sdes#endif /* !WITH_OPENSSL */
58285031Sdes#endif /* _SHA1_H */
59