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