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