Update copyright notices.
[userv-utils] / ipif / blowfish.h
CommitLineData
f0e54a99 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
1fb3cba0 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
1fb3cba0 29typedef uint32_t blowfish__p[BLOWFISH__PSIZE];
30typedef uint32_t blowfish__s[4][256];
2dc68225 31
32struct blowfish_expandedkey {
33 blowfish__p p;
34 blowfish__s s;
35};
36
1fb3cba0 37/* It's ok to pass the [_cbc]_(en|de)crypt functions the same
38 * input and output pointers.
39 */
40
2dc68225 41void blowfish_loadkey(struct blowfish_expandedkey *ek,
1fb3cba0 42 const uint8_t *key, int keybytes);
2dc68225 43void blowfish_encrypt(const struct blowfish_expandedkey *ek,
1fb3cba0 44 const uint8_t plain[BLOWFISH_BLOCKBYTES],
45 uint8_t cipher[BLOWFISH_BLOCKBYTES]);
2dc68225 46void blowfish_decrypt(const struct blowfish_expandedkey *ek,
1fb3cba0 47 const uint8_t cipher[BLOWFISH_BLOCKBYTES],
48 uint8_t plain[BLOWFISH_BLOCKBYTES]);
2dc68225 49
50struct blowfish_cbc_state {
51 struct blowfish_expandedkey ek;
1fb3cba0 52 uint32_t chainl, chainr;
2dc68225 53};
54
55void blowfish_cbc_setiv(struct blowfish_cbc_state *cs,
1fb3cba0 56 const uint8_t iv[BLOWFISH_BLOCKBYTES]);
2dc68225 57void blowfish_cbc_encrypt(struct blowfish_cbc_state *cs,
1fb3cba0 58 const uint8_t plain[BLOWFISH_BLOCKBYTES],
59 uint8_t cipher[BLOWFISH_BLOCKBYTES]);
2dc68225 60void blowfish_cbc_decrypt(struct blowfish_cbc_state *cs,
1fb3cba0 61 const uint8_t cipher[BLOWFISH_BLOCKBYTES],
62 uint8_t plain[BLOWFISH_BLOCKBYTES]);
2dc68225 63
64#endif