[mono-sha1] make SHA1Transform thread-safe
[mono.git] / mono / utils / sha1.h
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 <glib.h>
13
14 #define SHA1_BLOCK_LENGTH               64
15 #define SHA1_DIGEST_LENGTH              20
16 #define SHA1_DIGEST_STRING_LENGTH       (SHA1_DIGEST_LENGTH * 2 + 1)
17
18 typedef struct {
19     guint32 state[5];
20     guint64 count;
21     guint8 buffer[SHA1_BLOCK_LENGTH];
22 } SHA1_CTX;
23
24 G_BEGIN_DECLS
25 void mono_SHA1Init(SHA1_CTX *);
26 void mono_SHA1Pad(SHA1_CTX *);
27 void mono_SHA1Transform(guint32 [5], const guint8 [SHA1_BLOCK_LENGTH]);
28 void mono_SHA1Update(SHA1_CTX *, const guint8 *, size_t);
29 void mono_SHA1Final(guint8 [SHA1_DIGEST_LENGTH], SHA1_CTX *);
30 char *mono_SHA1End(SHA1_CTX *, char *);
31 G_END_DECLS
32
33 #define HTONDIGEST(x) do {                                              \
34         x[0] = htonl(x[0]);                                             \
35         x[1] = htonl(x[1]);                                             \
36         x[2] = htonl(x[2]);                                             \
37         x[3] = htonl(x[3]);                                             \
38         x[4] = htonl(x[4]); } while (0)
39
40 #define NTOHDIGEST(x) do {                                              \
41         x[0] = ntohl(x[0]);                                             \
42         x[1] = ntohl(x[1]);                                             \
43         x[2] = ntohl(x[2]);                                             \
44         x[3] = ntohl(x[3]);                                             \
45         x[4] = ntohl(x[4]); } while (0)
46
47 #endif /* _SHA1_H */