d03ab969 |
1 | /* -*-c-*- |
2 | * |
b817bfc6 |
3 | * $Id: blowfish.h,v 1.4 2004/04/08 01:36:15 mdw Exp $ |
d03ab969 |
4 | * |
5 | * The Blowfish block cipher |
6 | * |
7 | * (c) 1998 Straylight/Edgeware |
8 | */ |
9 | |
45c0fd36 |
10 | /*----- Licensing notice --------------------------------------------------* |
d03ab969 |
11 | * |
12 | * This file is part of Catacomb. |
13 | * |
14 | * Catacomb is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU Library General Public License as |
16 | * published by the Free Software Foundation; either version 2 of the |
17 | * License, or (at your option) any later version. |
45c0fd36 |
18 | * |
d03ab969 |
19 | * Catacomb is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU Library General Public License for more details. |
45c0fd36 |
23 | * |
d03ab969 |
24 | * You should have received a copy of the GNU Library General Public |
25 | * License along with Catacomb; if not, write to the Free |
26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
d03ab969 |
30 | /*----- Notes on the Blowfish block cipher --------------------------------* |
31 | * |
32 | * Blowfish was invented by Bruce Schneier. The algorithm is unpatented and |
33 | * free for anyone to use. It's fast, simple, offers a big key, and is |
34 | * looking relatively bulletproof. It's also this author's block cipher of |
35 | * choice, for what little that's worth. The disadvantage is that Blowfish |
36 | * has a particularly heavyweight key schedule. |
37 | */ |
38 | |
b3f05084 |
39 | #ifndef CATACOMB_BLOWFISH_H |
40 | #define CATACOMB_BLOWFISH_H |
d03ab969 |
41 | |
42 | #ifdef __cplusplus |
43 | extern "C" { |
44 | #endif |
45 | |
46 | /*----- Header files ------------------------------------------------------*/ |
47 | |
48 | #include <stddef.h> |
49 | |
50 | #include <mLib/bits.h> |
51 | |
52 | /*----- Magical numbers ---------------------------------------------------*/ |
53 | |
54 | #define BLOWFISH_BLKSZ 8 |
89ae755d |
55 | #define BLOWFISH_KEYSZ 32 |
d03ab969 |
56 | #define BLOWFISH_CLASS (N, B, 64) |
57 | |
89ae755d |
58 | extern const octet blowfish_keysz[]; |
59 | |
d03ab969 |
60 | /*----- Data structures ---------------------------------------------------*/ |
61 | |
62 | typedef struct blowfish_ctx { |
63 | uint32 p[18]; |
64 | uint32 s0[256], s1[256], s2[256], s3[256]; |
65 | } blowfish_ctx; |
66 | |
67 | /*----- Functions provided ------------------------------------------------*/ |
68 | |
69 | /* --- @blowfish_init@ --- * |
70 | * |
71 | * Arguments: @blowfish_ctx *k@ = pointer to key block to fill in |
72 | * @const void *buf@ = pointer to buffer of key material |
73 | * @size_t sz@ = size of key material |
74 | * |
75 | * Returns: --- |
76 | * |
77 | * Use: Initializes a Blowfish key buffer. Blowfish accepts |
78 | * a more-or-less arbitrary size key. |
79 | */ |
80 | |
81 | extern void blowfish_init(blowfish_ctx */*k*/, |
82 | const void */*buf*/, size_t /*sz*/); |
83 | |
84 | /* --- @blowfish_eblk@, @blowfish_dblk@ --- * |
85 | * |
86 | * Arguments: @const blowfish_ctx *k@ = pointer to key block |
87 | * @const uint32 s[2]@ = pointer to source block |
88 | * @uint32 d[2]@ = pointer to destination block |
89 | * |
90 | * Returns: --- |
91 | * |
92 | * Use: Low-level block encryption and decryption. |
93 | */ |
94 | |
95 | extern void blowfish_eblk(const blowfish_ctx */*k*/, |
96 | const uint32 */*s*/, uint32 */*d*/); |
97 | |
98 | extern void blowfish_dblk(const blowfish_ctx */*k*/, |
99 | const uint32 */*s*/, uint32 */*d*/); |
100 | |
101 | /*----- That's all, folks -------------------------------------------------*/ |
102 | |
103 | #ifdef __cplusplus |
104 | } |
105 | #endif |
106 | |
107 | #endif |