2dc68225 |
1 | /**/ |
2 | |
3 | #ifndef BLOWFISH__H_INCLUDED |
4 | #define BLOWFISH__H_INCLUDED |
5 | |
1fb3cba0 |
6 | #include <stdint.h> |
7 | |
2dc68225 |
8 | #define BLOWFISH_BLOCKBYTES 8 |
9 | #define BLOWFISH_MAXKEYBYTES 56 |
10 | #define BLOWFISH__N 16 |
11 | #define BLOWFISH__PSIZE BLOWFISH__N+2 |
12 | |
1fb3cba0 |
13 | typedef uint32_t blowfish__p[BLOWFISH__PSIZE]; |
14 | typedef uint32_t blowfish__s[4][256]; |
2dc68225 |
15 | |
16 | struct blowfish_expandedkey { |
17 | blowfish__p p; |
18 | blowfish__s s; |
19 | }; |
20 | |
1fb3cba0 |
21 | /* It's ok to pass the [_cbc]_(en|de)crypt functions the same |
22 | * input and output pointers. |
23 | */ |
24 | |
2dc68225 |
25 | void blowfish_loadkey(struct blowfish_expandedkey *ek, |
1fb3cba0 |
26 | const uint8_t *key, int keybytes); |
2dc68225 |
27 | void blowfish_encrypt(const struct blowfish_expandedkey *ek, |
1fb3cba0 |
28 | const uint8_t plain[BLOWFISH_BLOCKBYTES], |
29 | uint8_t cipher[BLOWFISH_BLOCKBYTES]); |
2dc68225 |
30 | void blowfish_decrypt(const struct blowfish_expandedkey *ek, |
1fb3cba0 |
31 | const uint8_t cipher[BLOWFISH_BLOCKBYTES], |
32 | uint8_t plain[BLOWFISH_BLOCKBYTES]); |
2dc68225 |
33 | |
34 | struct blowfish_cbc_state { |
35 | struct blowfish_expandedkey ek; |
1fb3cba0 |
36 | uint32_t chainl, chainr; |
2dc68225 |
37 | }; |
38 | |
39 | void blowfish_cbc_setiv(struct blowfish_cbc_state *cs, |
1fb3cba0 |
40 | const uint8_t iv[BLOWFISH_BLOCKBYTES]); |
2dc68225 |
41 | void blowfish_cbc_encrypt(struct blowfish_cbc_state *cs, |
1fb3cba0 |
42 | const uint8_t plain[BLOWFISH_BLOCKBYTES], |
43 | uint8_t cipher[BLOWFISH_BLOCKBYTES]); |
2dc68225 |
44 | void blowfish_cbc_decrypt(struct blowfish_cbc_state *cs, |
1fb3cba0 |
45 | const uint8_t cipher[BLOWFISH_BLOCKBYTES], |
46 | uint8_t plain[BLOWFISH_BLOCKBYTES]); |
2dc68225 |
47 | |
48 | #endif |