c4f2d992 |
1 | /* -*-c-*- |
2 | * |
9e5602f0 |
3 | * $Id: crypt.h,v 1.3 1997/09/26 09:14:58 mdw Exp $ |
c4f2d992 |
4 | * |
5 | * Cryptographic transfer of `become' requests |
6 | * |
7 | * (c) 1997 EBI |
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: crypt.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:04 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:21 mdw |
41 | * Sources placed under CVS control. |
42 | * |
43 | * Revision 1.1 1997/07/21 13:47:51 mdw |
c4f2d992 |
44 | * Initial revision |
45 | * |
46 | */ |
47 | |
48 | #ifndef CRYPT_H |
49 | #define CRYPT_H |
50 | |
51 | #ifdef __cplusplus |
52 | extern "C" { |
53 | #endif |
54 | |
55 | /*----- Required headers --------------------------------------------------*/ |
56 | |
57 | #include <string.h> |
58 | |
59 | #ifndef BECOME_H |
60 | # include "become.h" |
61 | #endif |
62 | |
63 | #ifndef CONFIG_H |
64 | # include "config.h" |
65 | #endif |
66 | |
67 | /*----- Type definitions and data structures ------------------------------*/ |
68 | |
69 | /* --- Encryption formats --- */ |
70 | |
71 | enum { |
9e5602f0 |
72 | cryptType_blowfish, /* Symmetric Blowfish encryption */ |
c4f2d992 |
73 | cryptType_rsa /* Public key RSA (later project) */ |
74 | }; |
75 | |
9e5602f0 |
76 | /* --- Blowfish has a variable key size --- * |
77 | * |
78 | * Fix a key size here. |
79 | */ |
80 | |
81 | #define BLOWFISH_KEYSIZE (16u) |
82 | |
c4f2d992 |
83 | /* --- Encrypted buffer format --- * |
84 | * |
85 | * C structures are no good here. Time for some explicit offsets. |
86 | */ |
87 | |
88 | enum { |
89 | crq_cryptType = 0, /* Encryption type (1 byte) */ |
90 | crq_iv = crq_cryptType + 1, /* Plaintext IV (8 bytes) */ |
9e5602f0 |
91 | crq_session = crq_iv + 8, /* Session key (16 bytes) */ |
c4f2d992 |
92 | crq_cipher = crq_session + 16, /* Where to start encrypting */ |
93 | crq_time = crq_cipher, /* Time stamp (4 bytes) */ |
94 | crq_pid = crq_time + 4, /* Process ID (4 bytes) */ |
95 | crq_from = crq_pid + 4, /* From user id (4 bytes) */ |
96 | crq_to = crq_from + 4, /* To user id (4 bytes) */ |
97 | crq_cmd = crq_to + 4, /* Command string (lots of bytes) */ |
98 | crq_check = crq_cmd + CMDLEN_MAX, /* Checksum for request (4 bytes) */ |
99 | crq_size = crq_check + 4 /* Size of encrypted request */ |
100 | }; |
101 | |
102 | /* --- Encrypted result format --- */ |
103 | |
104 | enum { |
105 | crp_iv = 0, /* Plaintext IV (8 bytes) */ |
106 | crp_cipher = crp_iv + 8, /* Where to start encrypting */ |
107 | crp_time = crp_cipher, /* Time of request (4 bytes) */ |
108 | crp_pid = crp_time + 4, /* Process ID of client (4 bytes) */ |
109 | crp_answer = crp_pid + 4, /* Answer (1 or 0) (1 byte) */ |
110 | crp_check = crp_answer + 1, /* Checksum for reply (4 bytes) */ |
111 | crp_size = crp_check + 4 /* Size of encrypted reply */ |
112 | }; |
113 | |
c4f2d992 |
114 | /*----- Functions provided ------------------------------------------------*/ |
115 | |
116 | /* --- @crypt_packRequest@ --- * |
117 | * |
118 | * Arguments: @request *rq@ = pointer to request block |
119 | * @unsigned char *buff@ = pointer to a buffer |
120 | * @time_t t@ = the current time |
121 | * @pid_t pid@ = my process ID |
122 | * @unsigned char *k@ = pointer to 128-bit key |
123 | * @unsigned char *sk@ = where to put the session key |
124 | * |
125 | * Returns: The number of bytes written. |
126 | * |
127 | * Use: Packs a request block into a buffer. The buffer should have |
128 | * space for at least @crq_size@ bytes. The buffer comes back |
129 | * encrypted and ready to send. |
130 | */ |
131 | |
132 | extern void crypt_packRequest(request */*rq*/, unsigned char */*buff*/, |
133 | time_t /*t*/, pid_t /*pid*/, |
134 | unsigned char */*k*/, unsigned char */*sk*/); |
135 | |
136 | /* --- @crypt_unpackRequest@ --- * |
137 | * |
138 | * Arguments: @reqest *rq@ = pointer to destination request block |
139 | * @unsigned char *buff@ = pointer to source buffer |
140 | * @unsigned char *k@ = pointer to encryption key |
141 | * @unsigned char *sk@ = pointer to where to store session key |
142 | * @unsigned char *rpl@ = where to start building reply |
143 | * |
144 | * Returns: --- |
145 | * |
146 | * Use: Decrypts and unpacks a request buffer. |
147 | */ |
148 | |
149 | extern int crypt_unpackRequest(request */*rq*/, unsigned char */*buff*/, |
150 | unsigned char */*k*/, unsigned char */*sk*/, |
151 | unsigned char */*rpl*/); |
152 | |
153 | /* --- @crypt_packReply@ --- * |
154 | * |
155 | * Arguments: @unsigned char *buff@ = pointer to reply block |
156 | * @unsigned char *sk@ = pointer to session key |
157 | * @int answer@ = yes or no |
158 | * |
159 | * Returns: --- |
160 | * |
161 | * Use: Packs and encrypts a reply block. |
162 | */ |
163 | |
164 | extern void crypt_packReply(unsigned char */*buff*/, unsigned char */*sk*/, |
165 | int /*answer*/); |
166 | |
167 | /* --- @crypt_unpackReply@ --- * |
168 | * |
169 | * Arguments: @unsigned char *buff@ = pointer to reply buffer |
170 | * @unsigned char *sk@ = pointer to session key |
171 | * @time_t t@ = time at which request was sent |
172 | * @pid_t pid@ = my process ID |
173 | * |
174 | * Returns: >0 if request granted, zero if denied, <0 if reply rejected |
175 | * |
176 | * Use: Unpacks a reply block, and informs the caller of the outcome. |
177 | */ |
178 | |
179 | extern int crypt_unpackReply(unsigned char */*buff*/, unsigned char */*sk*/, |
180 | time_t /*t*/, pid_t /*pid*/); |
181 | |
182 | /*----- That's all, folks -------------------------------------------------*/ |
183 | |
184 | #ifdef __cplusplus |
185 | } |
186 | #endif |
187 | |
188 | #endif |