| 1 | /**/ |
| 2 | |
| 3 | #ifndef BLOWFISH__H_INCLUDED |
| 4 | #define BLOWFISH__H_INCLUDED |
| 5 | |
| 6 | #define BLOWFISH_BLOCKBYTES 8 |
| 7 | #define BLOWFISH_MAXKEYBYTES 56 |
| 8 | #define BLOWFISH__N 16 |
| 9 | #define BLOWFISH__PSIZE BLOWFISH__N+2 |
| 10 | |
| 11 | typedef uint32 blowfish__p[BLOWFISH__PSIZE]; |
| 12 | typedef uint32 blowfish__s[4][256]; |
| 13 | |
| 14 | struct blowfish_expandedkey { |
| 15 | blowfish__p p; |
| 16 | blowfish__s s; |
| 17 | }; |
| 18 | |
| 19 | void blowfish_loadkey(struct blowfish_expandedkey *ek, |
| 20 | const uint8 *key, int keybytes); |
| 21 | void blowfish_encrypt(const struct blowfish_expandedkey *ek, |
| 22 | const uint8 plain[BLOWFISH_BLOCKBYTES], |
| 23 | uint8 cipher[BLOWFISH_BLOCKBYTES]); |
| 24 | void blowfish_decrypt(const struct blowfish_expandedkey *ek, |
| 25 | const uint8 cipher[BLOWFISH_BLOCKBYTES], |
| 26 | uint8 plain[BLOWFISH_BLOCKBYTES]); |
| 27 | |
| 28 | struct blowfish_cbc_state { |
| 29 | struct blowfish_expandedkey ek; |
| 30 | uint32 chainl, chainr; |
| 31 | }; |
| 32 | |
| 33 | void blowfish_cbc_setiv(struct blowfish_cbc_state *cs, |
| 34 | const uint8 iv[BLOWFISH_BLOCKBYTES]); |
| 35 | void blowfish_cbc_encrypt(struct blowfish_cbc_state *cs, |
| 36 | const uint8 plain[BLOWFISH_BLOCKBYTES], |
| 37 | uint8 cipher[BLOWFISH_BLOCKBYTES]); |
| 38 | void blowfish_cbc_decrypt(struct blowfish_cbc_state *cs, |
| 39 | const uint8 cipher[BLOWFISH_BLOCKBYTES], |
| 40 | uint8 plain[BLOWFISH_BLOCKBYTES]); |
| 41 | |
| 42 | #endif |