Mercurial > hg > th-libs
annotate th_crypto.h @ 469:fe5b803ae449
Rename the global variable th_verbosityLevel to th_verbosity.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 04 Jun 2018 02:41:27 +0300 |
parents | 9148bc3fa838 |
children | 36c50873e02c |
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 */ |
436
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
10 /// @file |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
11 /// @brief Cryptography and hash related functions |
135
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 #ifndef TH_CRYPTO_H |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 #define TH_CRYPTO_H 1 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 #ifdef HAVE_CONFIG_H |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 #include "config.h" |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 #endif |
199
d9f1d1c977ff
Include stdio.h here, we need it for th_md5_print().
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
18 |
135
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 #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
|
20 #include <stdio.h> |
135
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 #ifdef __cplusplus |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 extern "C" { |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 #endif |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 |
436
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
27 /** @def MD5 digest related defines |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
28 */ |
227 | 29 #define TH_MD5HASH_LENGTH (16) |
30 #define TH_MD5HASH_LENGTH_CH (TH_MD5HASH_LENGTH * 2) | |
31 | |
436
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
32 |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
33 /** MD5 digest state structure |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
34 */ |
135
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 typedef struct |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 { |
436
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
37 uint32_t bits[2]; ///< Message length in bits, lsw first |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
38 uint32_t buf[4]; ///< Digest buffer |
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
39 uint8_t in[64]; ///< Accumulate block |
135
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 } th_md5state_t; |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 |
436
9148bc3fa838
Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents:
227
diff
changeset
|
42 typedef uint8_t th_md5hash_t[TH_MD5HASH_LENGTH]; ///< A structure containing MD5 digest hash |
135
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 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
|
46 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
|
47 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
|
48 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
|
49 |
218
e20fdeee6bdf
Rename some functions for consistency.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
50 void th_md5_append_u8(th_md5state_t *ctx, uint8_t val); |
215
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
51 |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
52 #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
|
53 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
|
54 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
|
55 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
|
56 |
216
4fee16cb28c1
Meh, rename he/HE to ne/NE. Native vs Host.
Matti Hamalainen <ccr@tnsp.org>
parents:
215
diff
changeset
|
57 TH_DEFINE_HEADER(ne) |
215
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
58 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
|
59 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
|
60 |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
61 #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
|
62 |
f04743489c9e
Add endian converting th_md5_append_{he,le,be}{16,32,64}() functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
63 |
135
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 #ifdef __cplusplus |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 } |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 #endif |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 #endif /* TH_CRYPTO_H */ |