Initial revision
[become] / src / icrypt.h
1 /* -*-c-*-
2 *
3 * $Id: icrypt.h,v 1.1 1997/07/21 13:47:49 mdw Exp $
4 *
5 * Higher level IDEA encryption
6 *
7 * (c) 1997 Mark Wooding
8 */
9
10 /*----- Licencing 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
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
29 /*----- Revision history --------------------------------------------------*
30 *
31 * $Log: icrypt.h,v $
32 * Revision 1.1 1997/07/21 13:47:49 mdw
33 * Initial revision
34 *
35 */
36
37 #ifndef ICRYPT_H
38 #define ICRYPT_H
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /*----- Required headers --------------------------------------------------*/
45
46 #include <stddef.h>
47
48 #ifndef CONFIG_H
49 # include "config.h"
50 #endif
51
52 #ifndef IDEA_H
53 # include "idea.h"
54 #endif
55
56 /*----- Type definitions --------------------------------------------------*/
57
58 /* --- @icrypt_job@ --- */
59
60 typedef struct icrypt_job {
61 idea_key k; /* IDEA key for en/decrypting */
62 int i; /* Index into the IV buffer */
63 char iv[IDEA_BLKSIZE]; /* IV bytes for encrypting */
64 } icrypt_job;
65
66 /*----- Functions provided ------------------------------------------------*/
67
68 /* --- @icrypt_init@ --- *
69 *
70 * Arguments: @icrypt_job *j@ = pointer to job context block
71 * @unsigned char *k@ = pointer to key data
72 * @const unsigned char *iv@ = pointer to IV
73 *
74 * Returns: ---
75 *
76 * Use: Primes the context block ready for encryption.
77 */
78
79 extern void icrypt_init(icrypt_job */*j*/,
80 unsigned char */*k*/,
81 const unsigned char */*iv*/);
82
83 /* --- @icrypt_encrypt@ --- *
84 *
85 * Arguments: @icrypt_job *j@ = job handle
86 * @const void *src@ = pointer to source buffer
87 * @void *dest@ = pointer to destination buffer
88 * @size_t sz@ = size of buffers to handle
89 *
90 * Returns: ---
91 *
92 * Use: Encrypts data from the source to the destination, using the
93 * key attached to the job handle.
94 */
95
96 extern void icrypt_encrypt(icrypt_job */*j*/, const void */*src*/,
97 void */*dest*/, size_t /*sz*/);
98
99 /* --- @icrypt_decrypt@ --- *
100 *
101 * Arguments: @icrypt_job *j@ = job handle
102 * @const void *src@ = pointer to source buffer
103 * @void *dest@ = pointer to destination buffer
104 * @size_t sz@ = size of buffers to handle
105 *
106 * Returns: ---
107 *
108 * Use: Decrypts data from the source to the destination, using
109 * the key attached to the job handle.
110 */
111
112 extern void icrypt_decrypt(icrypt_job */*j*/, const void */*src*/,
113 void */*dest*/, size_t /*sz*/);
114
115 /* --- @icrypt_reset@ --- *
116 *
117 * Arguments: @icrypt_job *j@ = pointer to job context block
118 * @unsigned char *k@ = pointer to key data, or zero for
119 * no change
120 * @const unsigned char *iv@ = pointer to IV, or zero
121 *
122 * Returns: ---
123 *
124 * Use: Alters the context block. This can be used after recovery
125 * of a session key, for example.
126 */
127
128 extern void icrypt_reset(icrypt_job */*j*/,
129 unsigned char */*k*/,
130 const unsigned char */*iv*/);
131
132 /* --- @icrypt_saveIV@ --- *
133 *
134 * Arguments: @icrypt_job *j@ = pointer to job context block
135 * @unsigned char *iv@ = where to store the IV
136 *
137 * Returns: ---
138 *
139 * Use: Writes out the job's IV after munging it a little.
140 */
141
142 extern void icrypt_saveIV(icrypt_job */*j*/, unsigned char */*iv*/);
143
144 /*----- That's all, folks -------------------------------------------------*/
145
146 #ifdef __cplusplus
147 }
148 #endif
149
150 #endif