d03ab969 |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: blowfish.h,v 1.1 1999/09/03 08:41:11 mdw Exp $ |
4 | * |
5 | * The Blowfish block cipher |
6 | * |
7 | * (c) 1998 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
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. |
18 | * |
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. |
23 | * |
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 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: blowfish.h,v $ |
33 | * Revision 1.1 1999/09/03 08:41:11 mdw |
34 | * Initial import. |
35 | * |
36 | */ |
37 | |
38 | /*----- Notes on the Blowfish block cipher --------------------------------* |
39 | * |
40 | * Blowfish was invented by Bruce Schneier. The algorithm is unpatented and |
41 | * free for anyone to use. It's fast, simple, offers a big key, and is |
42 | * looking relatively bulletproof. It's also this author's block cipher of |
43 | * choice, for what little that's worth. The disadvantage is that Blowfish |
44 | * has a particularly heavyweight key schedule. |
45 | */ |
46 | |
47 | #ifndef BLOWFISH_H |
48 | #define BLOWFISH_H |
49 | |
50 | #ifdef __cplusplus |
51 | extern "C" { |
52 | #endif |
53 | |
54 | /*----- Header files ------------------------------------------------------*/ |
55 | |
56 | #include <stddef.h> |
57 | |
58 | #include <mLib/bits.h> |
59 | |
60 | /*----- Magical numbers ---------------------------------------------------*/ |
61 | |
62 | #define BLOWFISH_BLKSZ 8 |
63 | #define BLOWFISH_KEYSZ 0 |
64 | #define BLOWFISH_CLASS (N, B, 64) |
65 | |
66 | /*----- Data structures ---------------------------------------------------*/ |
67 | |
68 | typedef struct blowfish_ctx { |
69 | uint32 p[18]; |
70 | uint32 s0[256], s1[256], s2[256], s3[256]; |
71 | } blowfish_ctx; |
72 | |
73 | /*----- Functions provided ------------------------------------------------*/ |
74 | |
75 | /* --- @blowfish_init@ --- * |
76 | * |
77 | * Arguments: @blowfish_ctx *k@ = pointer to key block to fill in |
78 | * @const void *buf@ = pointer to buffer of key material |
79 | * @size_t sz@ = size of key material |
80 | * |
81 | * Returns: --- |
82 | * |
83 | * Use: Initializes a Blowfish key buffer. Blowfish accepts |
84 | * a more-or-less arbitrary size key. |
85 | */ |
86 | |
87 | extern void blowfish_init(blowfish_ctx */*k*/, |
88 | const void */*buf*/, size_t /*sz*/); |
89 | |
90 | /* --- @blowfish_eblk@, @blowfish_dblk@ --- * |
91 | * |
92 | * Arguments: @const blowfish_ctx *k@ = pointer to key block |
93 | * @const uint32 s[2]@ = pointer to source block |
94 | * @uint32 d[2]@ = pointer to destination block |
95 | * |
96 | * Returns: --- |
97 | * |
98 | * Use: Low-level block encryption and decryption. |
99 | */ |
100 | |
101 | extern void blowfish_eblk(const blowfish_ctx */*k*/, |
102 | const uint32 */*s*/, uint32 */*d*/); |
103 | |
104 | extern void blowfish_dblk(const blowfish_ctx */*k*/, |
105 | const uint32 */*s*/, uint32 */*d*/); |
106 | |
107 | /*----- That's all, folks -------------------------------------------------*/ |
108 | |
109 | #ifdef __cplusplus |
110 | } |
111 | #endif |
112 | |
113 | #endif |