Mercurial > hg > th-libs
annotate th_crypto.h @ 215:f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 12 Feb 2016 18:17:44 +0200 |
parents | d9f1d1c977ff |
children | 4fee16cb28c1 |
rev | line source |
---|---|
135
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * MD5 implementation, modified for th-libs from |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Colin Plumb's implementation by Matti 'ccr' Hämäläinen. |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 * |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 * This code implements the MD5 message-digest algorithm. |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 * The algorithm is due to Ron Rivest. This code was |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 * written by Colin Plumb in 1993, no copyright is claimed. |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 * This code is in the public domain; do with it what you wish. |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 */ |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #ifndef TH_CRYPTO_H |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 #define TH_CRYPTO_H 1 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 #ifdef HAVE_CONFIG_H |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 #include "config.h" |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 #endif |
199
d9f1d1c977ff
Include stdio.h here, we need it for th_md5_print().
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
16 |
135
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 #include "th_endian.h" |
199
d9f1d1c977ff
Include stdio.h here, we need it for th_md5_print().
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
18 #include <stdio.h> |
135
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 #ifdef __cplusplus |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 extern "C" { |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 #endif |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 typedef struct |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 { |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 uint32_t bits[2]; // Message length in bits, lsw first |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 uint32_t buf[4]; // Digest buffer |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 uint8_t in[64]; // Accumulate block |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 } th_md5state_t; |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 #define TH_MD5HASH_LENGTH (16) |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 #define TH_MD5HASH_LENGTH_CH (TH_MD5HASH_LENGTH * 2) |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 typedef uint8_t th_md5hash_t[TH_MD5HASH_LENGTH]; |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 void th_md5_init(th_md5state_t *ctx); |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 void th_md5_append(th_md5state_t *ctx, const uint8_t *buf, size_t len); |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 void th_md5_finish(th_md5state_t *ctx, th_md5hash_t digest); |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 void th_md5_print(FILE *, const th_md5hash_t digest); |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 |
215
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
43 void th_md5_append_uint8(th_md5state_t *ctx, uint8_t val); |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
44 |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
45 #define TH_DEFINE_HEADER(xname) \ |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
46 void th_md5_append_ ## xname ## 16 (th_md5state_t *ctx, uint16_t val); \ |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
47 void th_md5_append_ ## xname ## 32 (th_md5state_t *ctx, uint32_t val); \ |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
48 void th_md5_append_ ## xname ## 64 (th_md5state_t *ctx, uint64_t val); |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
49 |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
50 TH_DEFINE_HEADER(he) |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
51 TH_DEFINE_HEADER(le) |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
52 TH_DEFINE_HEADER(be) |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
53 |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
54 #undef TH_DEFINE_HEADER |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
55 |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
56 |
135
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 #ifdef __cplusplus |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 } |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 #endif |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 #endif /* TH_CRYPTO_H */ |