Update to GPLv3+; update copyright notices everywhere.
[userv-utils] / ipif / blowfish.h
1 /*
2 * This file is part of ipif, part of userv-utils
3 *
4 * Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk>
5 * Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk>
6 * Copyright 1999,2003
7 * Chancellor Masters and Scholars of the University of Cambridge
8 * Copyright 2010 Tony Finch <fanf@dotat.at>
9 *
10 * This is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with userv-utils; if not, see http://www.gnu.org/licenses/.
22 */
23
24 #ifndef BLOWFISH__H_INCLUDED
25 #define BLOWFISH__H_INCLUDED
26
27 #include <stdint.h>
28
29 #define BLOWFISH_BLOCKBYTES 8
30 #define BLOWFISH_MAXKEYBYTES 56
31 #define BLOWFISH__N 16
32 #define BLOWFISH__PSIZE BLOWFISH__N+2
33
34 typedef uint32_t blowfish__p[BLOWFISH__PSIZE];
35 typedef uint32_t blowfish__s[4][256];
36
37 struct blowfish_expandedkey {
38 blowfish__p p;
39 blowfish__s s;
40 };
41
42 /* It's ok to pass the [_cbc]_(en|de)crypt functions the same
43 * input and output pointers.
44 */
45
46 void blowfish_loadkey(struct blowfish_expandedkey *ek,
47 const uint8_t *key, int keybytes);
48 void blowfish_encrypt(const struct blowfish_expandedkey *ek,
49 const uint8_t plain[BLOWFISH_BLOCKBYTES],
50 uint8_t cipher[BLOWFISH_BLOCKBYTES]);
51 void blowfish_decrypt(const struct blowfish_expandedkey *ek,
52 const uint8_t cipher[BLOWFISH_BLOCKBYTES],
53 uint8_t plain[BLOWFISH_BLOCKBYTES]);
54
55 struct blowfish_cbc_state {
56 struct blowfish_expandedkey ek;
57 uint32_t chainl, chainr;
58 };
59
60 void blowfish_cbc_setiv(struct blowfish_cbc_state *cs,
61 const uint8_t iv[BLOWFISH_BLOCKBYTES]);
62 void blowfish_cbc_encrypt(struct blowfish_cbc_state *cs,
63 const uint8_t plain[BLOWFISH_BLOCKBYTES],
64 uint8_t cipher[BLOWFISH_BLOCKBYTES]);
65 void blowfish_cbc_decrypt(struct blowfish_cbc_state *cs,
66 const uint8_t cipher[BLOWFISH_BLOCKBYTES],
67 uint8_t plain[BLOWFISH_BLOCKBYTES]);
68
69 #endif