xref: /third_party/mesa3d/src/util/sha1/sha1.h (revision bf215546)
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
20extern "C" {
21#endif
22
23typedef struct _SHA1_CTX {
24    uint32_t state[5];
25    uint64_t count;
26    uint8_t buffer[SHA1_BLOCK_LENGTH];
27} SHA1_CTX;
28
29void SHA1Init(SHA1_CTX *);
30void SHA1Pad(SHA1_CTX *);
31void SHA1Transform(uint32_t [5], const uint8_t [SHA1_BLOCK_LENGTH]);
32void SHA1Update(SHA1_CTX *, const uint8_t *, size_t);
33void SHA1Final(uint8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *);
34
35#define HTONDIGEST(x) do {                                              \
36        x[0] = htonl(x[0]);                                             \
37        x[1] = htonl(x[1]);                                             \
38        x[2] = htonl(x[2]);                                             \
39        x[3] = htonl(x[3]);                                             \
40        x[4] = htonl(x[4]); } while (0)
41
42#define NTOHDIGEST(x) do {                                              \
43        x[0] = ntohl(x[0]);                                             \
44        x[1] = ntohl(x[1]);                                             \
45        x[2] = ntohl(x[2]);                                             \
46        x[3] = ntohl(x[3]);                                             \
47        x[4] = ntohl(x[4]); } while (0)
48
49#ifdef __cplusplus
50}
51#endif
52
53#endif /* _SHA1_H */
54