2 * This file is part of ipif, part of userv-utils
4 * Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk>
5 * Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk>
7 * Chancellor Masters and Scholars of the University of Cambridge
8 * Copyright 2010 Tony Finch <fanf@dotat.at>
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.
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.
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/.
24 #ifndef BLOWFISH__H_INCLUDED
25 #define BLOWFISH__H_INCLUDED
29 #define BLOWFISH_BLOCKBYTES 8
30 #define BLOWFISH_MAXKEYBYTES 56
31 #define BLOWFISH__N 16
32 #define BLOWFISH__PSIZE BLOWFISH__N+2
34 typedef uint32_t blowfish__p[BLOWFISH__PSIZE];
35 typedef uint32_t blowfish__s[4][256];
37 struct blowfish_expandedkey {
42 /* It's ok to pass the [_cbc]_(en|de)crypt functions the same
43 * input and output pointers.
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]);
55 struct blowfish_cbc_state {
56 struct blowfish_expandedkey ek;
57 uint32_t chainl, chainr;
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]);