sha1.h revision 294407
1867Sache/*	$OpenBSD: sha1.h,v 1.24 2012/12/05 23:19:57 deraadt Exp $	*/
27398Sache
3867Sache/*
4867Sache * SHA-1 in C
5867Sache * By Steve Reid <steve@edmweb.com>
6867Sache * 100% Public Domain
7867Sache */
8867Sache
9867Sache#ifndef _SHA1_H
10867Sache#define _SHA1_H
11867Sache
12867Sache#ifndef WITH_OPENSSL
13867Sache
141092Sache#define	SHA1_BLOCK_LENGTH		64
15867Sache#define	SHA1_DIGEST_LENGTH		20
16867Sache#define	SHA1_DIGEST_STRING_LENGTH	(SHA1_DIGEST_LENGTH * 2 + 1)
17867Sache
18867Sachetypedef struct {
19867Sache    u_int32_t state[5];
20867Sache    u_int64_t count;
21867Sache    u_int8_t buffer[SHA1_BLOCK_LENGTH];
22867Sache} SHA1_CTX;
23867Sache
24867Sachevoid SHA1Init(SHA1_CTX *);
25867Sachevoid SHA1Pad(SHA1_CTX *);
26867Sachevoid SHA1Transform(u_int32_t [5], const u_int8_t [SHA1_BLOCK_LENGTH])
27867Sache	__attribute__((__bounded__(__minbytes__,1,5)))
28867Sache	__attribute__((__bounded__(__minbytes__,2,SHA1_BLOCK_LENGTH)));
297398Sachevoid SHA1Update(SHA1_CTX *, const u_int8_t *, size_t)
30867Sache	__attribute__((__bounded__(__string__,2,3)));
31867Sachevoid SHA1Final(u_int8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *)
32867Sache	__attribute__((__bounded__(__minbytes__,1,SHA1_DIGEST_LENGTH)));
33867Sachechar *SHA1End(SHA1_CTX *, char *)
347398Sache	__attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
35867Sachechar *SHA1File(const char *, char *)
36867Sache	__attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
37867Sachechar *SHA1FileChunk(const char *, char *, off_t, off_t)
38867Sache	__attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
39867Sachechar *SHA1Data(const u_int8_t *, size_t, char *)
40867Sache	__attribute__((__bounded__(__string__,1,2)))
41867Sache	__attribute__((__bounded__(__minbytes__,3,SHA1_DIGEST_STRING_LENGTH)));
42867Sache
43867Sache#define HTONDIGEST(x) do {                                              \
444107Sache        x[0] = htonl(x[0]);                                             \
45867Sache        x[1] = htonl(x[1]);                                             \
46867Sache        x[2] = htonl(x[2]);                                             \
474048Sache        x[3] = htonl(x[3]);                                             \
48867Sache        x[4] = htonl(x[4]); } while (0)
49867Sache
502910Sache#define NTOHDIGEST(x) do {                                              \
512910Sache        x[0] = ntohl(x[0]);                                             \
522910Sache        x[1] = ntohl(x[1]);                                             \
53867Sache        x[2] = ntohl(x[2]);                                             \
54867Sache        x[3] = ntohl(x[3]);                                             \
55867Sache        x[4] = ntohl(x[4]); } while (0)
565232Sache
574048Sache#endif /* !WITH_OPENSSL */
584048Sache#endif /* _SHA1_H */
594107Sache