935da5a4 |
1 | /* |
2 | * Copyright (C) 1997,2000 Ian Jackson |
3 | * |
4 | * This is free software; you can redistribute it and/or modify it |
5 | * under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, but |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with userv-utils; if not, write to the Free Software |
16 | * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
17 | */ |
2dc68225 |
18 | |
19 | #ifndef BLOWFISH__H_INCLUDED |
20 | #define BLOWFISH__H_INCLUDED |
21 | |
84f87e82 |
22 | #include <stdint.h> |
23 | |
2dc68225 |
24 | #define BLOWFISH_BLOCKBYTES 8 |
25 | #define BLOWFISH_MAXKEYBYTES 56 |
26 | #define BLOWFISH__N 16 |
27 | #define BLOWFISH__PSIZE BLOWFISH__N+2 |
28 | |
84f87e82 |
29 | typedef uint32_t blowfish__p[BLOWFISH__PSIZE]; |
30 | typedef uint32_t blowfish__s[4][256]; |
2dc68225 |
31 | |
32 | struct blowfish_expandedkey { |
33 | blowfish__p p; |
34 | blowfish__s s; |
35 | }; |
36 | |
84f87e82 |
37 | /* It's ok to pass the [_cbc]_(en|de)crypt functions the same |
38 | * input and output pointers. |
39 | */ |
40 | |
2dc68225 |
41 | void blowfish_loadkey(struct blowfish_expandedkey *ek, |
84f87e82 |
42 | const uint8_t *key, int keybytes); |
2dc68225 |
43 | void blowfish_encrypt(const struct blowfish_expandedkey *ek, |
84f87e82 |
44 | const uint8_t plain[BLOWFISH_BLOCKBYTES], |
45 | uint8_t cipher[BLOWFISH_BLOCKBYTES]); |
2dc68225 |
46 | void blowfish_decrypt(const struct blowfish_expandedkey *ek, |
84f87e82 |
47 | const uint8_t cipher[BLOWFISH_BLOCKBYTES], |
48 | uint8_t plain[BLOWFISH_BLOCKBYTES]); |
2dc68225 |
49 | |
50 | struct blowfish_cbc_state { |
51 | struct blowfish_expandedkey ek; |
84f87e82 |
52 | uint32_t chainl, chainr; |
2dc68225 |
53 | }; |
54 | |
55 | void blowfish_cbc_setiv(struct blowfish_cbc_state *cs, |
84f87e82 |
56 | const uint8_t iv[BLOWFISH_BLOCKBYTES]); |
2dc68225 |
57 | void blowfish_cbc_encrypt(struct blowfish_cbc_state *cs, |
84f87e82 |
58 | const uint8_t plain[BLOWFISH_BLOCKBYTES], |
59 | uint8_t cipher[BLOWFISH_BLOCKBYTES]); |
2dc68225 |
60 | void blowfish_cbc_decrypt(struct blowfish_cbc_state *cs, |
84f87e82 |
61 | const uint8_t cipher[BLOWFISH_BLOCKBYTES], |
62 | uint8_t plain[BLOWFISH_BLOCKBYTES]); |
2dc68225 |
63 | |
64 | #endif |