Mercurial > hg > th-libs
annotate th_crypto.h @ 135:1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 24 Sep 2014 23:45:39 +0300 |
parents | |
children | d9f1d1c977ff |
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 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 #include "th_endian.h" |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 #ifdef __cplusplus |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 extern "C" { |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 #endif |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 |
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 typedef struct |
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 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
|
27 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
|
28 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
|
29 } th_md5state_t; |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 |
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 #define TH_MD5HASH_LENGTH (16) |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 #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
|
34 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 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
|
36 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 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
|
38 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
|
39 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
|
40 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
|
41 |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 #ifdef __cplusplus |
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 #endif |
1b39682de64f
Add "crypto" module, only silly MD5 calculation in it now.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 #endif /* TH_CRYPTO_H */ |