chiark / gitweb /
Make it build\!
[become] / src / icrypt.h
1 /* -*-c-*-
2  *
3  * $Id: icrypt.h,v 1.4 1998/01/12 16:46:03 mdw Exp $
4  *
5  * Higher level encryption functions
6  *
7  * (c) 1998 Mark Wooding
8  */
9
10 /*----- Licensing notice --------------------------------------------------*
11  *
12  * This file is part of `become'
13  *
14  * `Become' is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * `Become' 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 General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with `become'; if not, write to the Free Software Foundation,
26  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27  */
28
29 /*----- Revision history --------------------------------------------------*
30  *
31  * $Log: icrypt.h,v $
32  * Revision 1.4  1998/01/12 16:46:03  mdw
33  * Fix copyright date.
34  *
35  * Revision 1.3  1997/09/26 09:14:58  mdw
36  * Merged blowfish branch into trunk.
37  *
38  * Revision 1.2.2.1  1997/09/26 09:08:08  mdw
39  * Use the Blowfish encryption algorithm instead of IDEA.  This is partly
40  * because I prefer Blowfish (without any particularly strong evidence) but
41  * mainly because IDEA is patented and Blowfish isn't.
42  *
43  * Revision 1.2  1997/08/04 10:24:22  mdw
44  * Sources placed under CVS control.
45  *
46  * Revision 1.1  1997/07/21  13:47:49  mdw
47  * Initial revision
48  *
49  */
50
51 #ifndef ICRYPT_H
52 #define ICRYPT_H
53
54 #ifdef __cplusplus
55   extern "C" {
56 #endif
57
58 /*----- Required headers --------------------------------------------------*/
59
60 #include <stddef.h>
61
62 #ifndef BLOWFISH_H
63 #  include "blowfish.h"
64 #endif
65
66 #ifndef CONFIG_H
67 #  include "config.h"
68 #endif
69
70 /*----- Type definitions --------------------------------------------------*/
71
72 /* --- @icrypt_job@ --- */
73
74 typedef struct icrypt_job {
75   blowfish_key k;                       /* Key for en/decrypting */
76   int i;                                /* Index into the IV buffer */
77   unsigned char iv[BLOWFISH_BLKSIZE];   /* IV bytes for encrypting */
78 } icrypt_job;
79
80 /*----- Functions provided ------------------------------------------------*/
81
82 extern void icrypt_init(icrypt_job */*j*/,
83                         unsigned char */*k*/,
84                         size_t /*sz*/,
85                         const unsigned char */*iv*/);
86
87 /* --- @icrypt_encrypt@ --- *
88  *
89  * Arguments:   @icrypt_job *j@ = job handle
90  *              @const void *src@ = pointer to source buffer
91  *              @void *dest@ = pointer to destination buffer
92  *              @size_t sz@ = size of buffers to handle
93  *
94  * Returns:     ---
95  *
96  * Use:         Encrypts data from the source to the destination, using the
97  *              key attached to the job handle.
98  */
99
100 extern void icrypt_encrypt(icrypt_job */*j*/, const void */*src*/,
101                            void */*dest*/, size_t /*sz*/);
102
103 /* --- @icrypt_decrypt@ --- *
104  *
105  * Arguments:   @icrypt_job *j@ = job handle
106  *              @const void *src@ = pointer to source buffer
107  *              @void *dest@ = pointer to destination buffer
108  *              @size_t sz@ = size of buffers to handle
109  *
110  * Returns:     ---
111  *
112  * Use:         Decrypts data from the source to the destination, using
113  *              the key attached to the job handle.
114  */
115
116 extern void icrypt_decrypt(icrypt_job */*j*/, const void */*src*/,
117                            void */*dest*/, size_t /*sz*/);
118
119 /* --- @icrypt_reset@ --- *
120  *
121  * Arguments:   @icrypt_job *j@ = pointer to job context block
122  *              @unsigned char *k@ = pointer to key data, or zero for
123  *                      no change
124  *              @size_t sz@ = size of the key in bytes
125  *              @const unsigned char *iv@ = pointer to IV, or zero
126  *
127  * Returns:     ---
128  *
129  * Use:         Alters the context block.  This can be used after recovery
130  *              of a session key, for example.
131  */
132
133 extern void icrypt_reset(icrypt_job */*j*/,
134                          unsigned char */*k*/,
135                          size_t /*sz*/,
136                          const unsigned char */*iv*/);
137
138 /* --- @icrypt_saveIV@ --- *
139  *
140  * Arguments:   @icrypt_job *j@ = pointer to job context block
141  *              @unsigned char *iv@ = where to store the IV
142  *
143  * Returns:     ---
144  *
145  * Use:         Writes out the job's IV after munging it a little.
146  */
147
148 extern void icrypt_saveIV(icrypt_job */*j*/, unsigned char */*iv*/);
149
150 /*----- That's all, folks -------------------------------------------------*/
151
152 #ifdef __cplusplus
153   }
154 #endif
155
156 #endif