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