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