chiark / gitweb /
@@ -1,10 +1,10 @@
[userv-utils.git] / ipif / blowfish.h
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  */
18
19 #ifndef BLOWFISH__H_INCLUDED
20 #define BLOWFISH__H_INCLUDED
21
22 #include <stdint.h>
23
24 #define BLOWFISH_BLOCKBYTES 8
25 #define BLOWFISH_MAXKEYBYTES 56
26 #define BLOWFISH__N 16
27 #define BLOWFISH__PSIZE BLOWFISH__N+2
28
29 typedef uint32_t blowfish__p[BLOWFISH__PSIZE];
30 typedef uint32_t blowfish__s[4][256];
31
32 struct blowfish_expandedkey {
33   blowfish__p p;
34   blowfish__s s;
35 };
36
37 /* It's ok to pass the [_cbc]_(en|de)crypt functions the same
38  * input and output pointers.
39  */
40
41 void blowfish_loadkey(struct blowfish_expandedkey *ek,
42                       const uint8_t *key, int keybytes);
43 void blowfish_encrypt(const struct blowfish_expandedkey *ek,
44                       const uint8_t plain[BLOWFISH_BLOCKBYTES],
45                       uint8_t cipher[BLOWFISH_BLOCKBYTES]);
46 void blowfish_decrypt(const struct blowfish_expandedkey *ek,
47                       const uint8_t cipher[BLOWFISH_BLOCKBYTES],
48                       uint8_t plain[BLOWFISH_BLOCKBYTES]);
49
50 struct blowfish_cbc_state {
51   struct blowfish_expandedkey ek;
52   uint32_t chainl, chainr;
53 };
54
55 void blowfish_cbc_setiv(struct blowfish_cbc_state *cs,
56                         const uint8_t iv[BLOWFISH_BLOCKBYTES]);
57 void blowfish_cbc_encrypt(struct blowfish_cbc_state *cs,
58                           const uint8_t plain[BLOWFISH_BLOCKBYTES],
59                           uint8_t cipher[BLOWFISH_BLOCKBYTES]);
60 void blowfish_cbc_decrypt(struct blowfish_cbc_state *cs,
61                           const uint8_t cipher[BLOWFISH_BLOCKBYTES],
62                           uint8_t plain[BLOWFISH_BLOCKBYTES]);
63
64 #endif