Provide various documentation for userv-cgi in /usr/share.
[userv-utils] / ipif / blowfish.h
CommitLineData
f0e54a99 1/*
c07be359 2 * This file is part of ipif, part of userv-utils
f0e54a99 3 *
9028e234
IJ
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 *
f0e54a99 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
9028e234 12 * the Free Software Foundation; either version 3 of the License, or
f0e54a99 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
9028e234 21 * along with userv-utils; if not, see http://www.gnu.org/licenses/.
f0e54a99 22 */
2dc68225 23
24#ifndef BLOWFISH__H_INCLUDED
25#define BLOWFISH__H_INCLUDED
26
1fb3cba0 27#include <stdint.h>
28
2dc68225 29#define BLOWFISH_BLOCKBYTES 8
30#define BLOWFISH_MAXKEYBYTES 56
31#define BLOWFISH__N 16
32#define BLOWFISH__PSIZE BLOWFISH__N+2
33
1fb3cba0 34typedef uint32_t blowfish__p[BLOWFISH__PSIZE];
35typedef uint32_t blowfish__s[4][256];
2dc68225 36
37struct blowfish_expandedkey {
38 blowfish__p p;
39 blowfish__s s;
40};
41
1fb3cba0 42/* It's ok to pass the [_cbc]_(en|de)crypt functions the same
43 * input and output pointers.
44 */
45
2dc68225 46void blowfish_loadkey(struct blowfish_expandedkey *ek,
1fb3cba0 47 const uint8_t *key, int keybytes);
2dc68225 48void blowfish_encrypt(const struct blowfish_expandedkey *ek,
1fb3cba0 49 const uint8_t plain[BLOWFISH_BLOCKBYTES],
50 uint8_t cipher[BLOWFISH_BLOCKBYTES]);
2dc68225 51void blowfish_decrypt(const struct blowfish_expandedkey *ek,
1fb3cba0 52 const uint8_t cipher[BLOWFISH_BLOCKBYTES],
53 uint8_t plain[BLOWFISH_BLOCKBYTES]);
2dc68225 54
55struct blowfish_cbc_state {
56 struct blowfish_expandedkey ek;
1fb3cba0 57 uint32_t chainl, chainr;
2dc68225 58};
59
60void blowfish_cbc_setiv(struct blowfish_cbc_state *cs,
1fb3cba0 61 const uint8_t iv[BLOWFISH_BLOCKBYTES]);
2dc68225 62void blowfish_cbc_encrypt(struct blowfish_cbc_state *cs,
1fb3cba0 63 const uint8_t plain[BLOWFISH_BLOCKBYTES],
64 uint8_t cipher[BLOWFISH_BLOCKBYTES]);
2dc68225 65void blowfish_cbc_decrypt(struct blowfish_cbc_state *cs,
1fb3cba0 66 const uint8_t cipher[BLOWFISH_BLOCKBYTES],
67 uint8_t plain[BLOWFISH_BLOCKBYTES]);
2dc68225 68
69#endif