1/* crypto/des/des_old.c -*- mode:C; c-file-style: "eay" -*- */ 2 3/*- 4 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 5 * 6 * The function names in here are deprecated and are only present to 7 * provide an interface compatible with libdes. OpenSSL now provides 8 * functions where "des_" has been replaced with "DES_" in the names, 9 * to make it possible to make incompatible changes that are needed 10 * for C type security and other stuff. 11 * 12 * Please consider starting to use the DES_ functions rather than the 13 * des_ ones. The des_ functions will dissapear completely before 14 * OpenSSL 1.0! 15 * 16 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING 17 */ 18 19/* 20 * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project 21 * 2001. 22 */ 23/* ==================================================================== 24 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. 25 * 26 * Redistribution and use in source and binary forms, with or without 27 * modification, are permitted provided that the following conditions 28 * are met: 29 * 30 * 1. Redistributions of source code must retain the above copyright 31 * notice, this list of conditions and the following disclaimer. 32 * 33 * 2. Redistributions in binary form must reproduce the above copyright 34 * notice, this list of conditions and the following disclaimer in 35 * the documentation and/or other materials provided with the 36 * distribution. 37 * 38 * 3. All advertising materials mentioning features or use of this 39 * software must display the following acknowledgment: 40 * "This product includes software developed by the OpenSSL Project 41 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 42 * 43 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 44 * endorse or promote products derived from this software without 45 * prior written permission. For written permission, please contact 46 * openssl-core@openssl.org. 47 * 48 * 5. Products derived from this software may not be called "OpenSSL" 49 * nor may "OpenSSL" appear in their names without prior written 50 * permission of the OpenSSL Project. 51 * 52 * 6. Redistributions of any form whatsoever must retain the following 53 * acknowledgment: 54 * "This product includes software developed by the OpenSSL Project 55 * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 56 * 57 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 58 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 60 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 61 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 62 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 63 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 64 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 66 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 67 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 68 * OF THE POSSIBILITY OF SUCH DAMAGE. 69 * ==================================================================== 70 * 71 * This product includes cryptographic software written by Eric Young 72 * (eay@cryptsoft.com). This product includes software written by Tim 73 * Hudson (tjh@cryptsoft.com). 74 * 75 */ 76 77#define OPENSSL_DES_LIBDES_COMPATIBILITY 78#include <openssl/des.h> 79#include <openssl/rand.h> 80 81const char *_ossl_old_des_options(void) 82{ 83 return DES_options(); 84} 85 86void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input, 87 _ossl_old_des_cblock *output, 88 des_key_schedule ks1, des_key_schedule ks2, 89 des_key_schedule ks3, int enc) 90{ 91 DES_ecb3_encrypt((const_DES_cblock *)input, output, 92 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2, 93 (DES_key_schedule *)ks3, enc); 94} 95 96DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input, 97 _ossl_old_des_cblock *output, long length, 98 des_key_schedule schedule, 99 _ossl_old_des_cblock *ivec) 100{ 101 return DES_cbc_cksum((unsigned char *)input, output, length, 102 (DES_key_schedule *)schedule, ivec); 103} 104 105void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input, 106 _ossl_old_des_cblock *output, long length, 107 des_key_schedule schedule, 108 _ossl_old_des_cblock *ivec, int enc) 109{ 110 DES_cbc_encrypt((unsigned char *)input, (unsigned char *)output, 111 length, (DES_key_schedule *)schedule, ivec, enc); 112} 113 114void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input, 115 _ossl_old_des_cblock *output, long length, 116 des_key_schedule schedule, 117 _ossl_old_des_cblock *ivec, int enc) 118{ 119 DES_ncbc_encrypt((unsigned char *)input, (unsigned char *)output, 120 length, (DES_key_schedule *)schedule, ivec, enc); 121} 122 123void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input, 124 _ossl_old_des_cblock *output, long length, 125 des_key_schedule schedule, 126 _ossl_old_des_cblock *ivec, 127 _ossl_old_des_cblock *inw, 128 _ossl_old_des_cblock *outw, int enc) 129{ 130 DES_xcbc_encrypt((unsigned char *)input, (unsigned char *)output, 131 length, (DES_key_schedule *)schedule, ivec, inw, outw, 132 enc); 133} 134 135void _ossl_old_des_cfb_encrypt(unsigned char *in, unsigned char *out, 136 int numbits, long length, 137 des_key_schedule schedule, 138 _ossl_old_des_cblock *ivec, int enc) 139{ 140 DES_cfb_encrypt(in, out, numbits, length, 141 (DES_key_schedule *)schedule, ivec, enc); 142} 143 144void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input, 145 _ossl_old_des_cblock *output, 146 des_key_schedule ks, int enc) 147{ 148 DES_ecb_encrypt(input, output, (DES_key_schedule *)ks, enc); 149} 150 151void _ossl_old_des_encrypt(DES_LONG *data, des_key_schedule ks, int enc) 152{ 153 DES_encrypt1(data, (DES_key_schedule *)ks, enc); 154} 155 156void _ossl_old_des_encrypt2(DES_LONG *data, des_key_schedule ks, int enc) 157{ 158 DES_encrypt2(data, (DES_key_schedule *)ks, enc); 159} 160 161void _ossl_old_des_encrypt3(DES_LONG *data, des_key_schedule ks1, 162 des_key_schedule ks2, des_key_schedule ks3) 163{ 164 DES_encrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2, 165 (DES_key_schedule *)ks3); 166} 167 168void _ossl_old_des_decrypt3(DES_LONG *data, des_key_schedule ks1, 169 des_key_schedule ks2, des_key_schedule ks3) 170{ 171 DES_decrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2, 172 (DES_key_schedule *)ks3); 173} 174 175void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, 176 _ossl_old_des_cblock *output, long length, 177 des_key_schedule ks1, 178 des_key_schedule ks2, 179 des_key_schedule ks3, 180 _ossl_old_des_cblock *ivec, int enc) 181{ 182 DES_ede3_cbc_encrypt((unsigned char *)input, (unsigned char *)output, 183 length, (DES_key_schedule *)ks1, 184 (DES_key_schedule *)ks2, (DES_key_schedule *)ks3, 185 ivec, enc); 186} 187 188void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out, 189 long length, des_key_schedule ks1, 190 des_key_schedule ks2, 191 des_key_schedule ks3, 192 _ossl_old_des_cblock *ivec, int *num, 193 int enc) 194{ 195 DES_ede3_cfb64_encrypt(in, out, length, 196 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2, 197 (DES_key_schedule *)ks3, ivec, num, enc); 198} 199 200void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out, 201 long length, des_key_schedule ks1, 202 des_key_schedule ks2, 203 des_key_schedule ks3, 204 _ossl_old_des_cblock *ivec, int *num) 205{ 206 DES_ede3_ofb64_encrypt(in, out, length, 207 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2, 208 (DES_key_schedule *)ks3, ivec, num); 209} 210 211#if 0 /* broken code, preserved just in case anyone 212 * specifically looks for this */ 213void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), 214 _ossl_old_des_cblock (*in_white), 215 _ossl_old_des_cblock (*out_white)) 216{ 217 DES_xwhite_in2out(des_key, in_white, out_white); 218} 219#endif 220 221int _ossl_old_des_enc_read(int fd, char *buf, int len, des_key_schedule sched, 222 _ossl_old_des_cblock *iv) 223{ 224 return DES_enc_read(fd, buf, len, (DES_key_schedule *)sched, iv); 225} 226 227int _ossl_old_des_enc_write(int fd, char *buf, int len, 228 des_key_schedule sched, _ossl_old_des_cblock *iv) 229{ 230 return DES_enc_write(fd, buf, len, (DES_key_schedule *)sched, iv); 231} 232 233char *_ossl_old_des_fcrypt(const char *buf, const char *salt, char *ret) 234{ 235 return DES_fcrypt(buf, salt, ret); 236} 237 238char *_ossl_old_des_crypt(const char *buf, const char *salt) 239{ 240 return DES_crypt(buf, salt); 241} 242 243char *_ossl_old_crypt(const char *buf, const char *salt) 244{ 245 return DES_crypt(buf, salt); 246} 247 248void _ossl_old_des_ofb_encrypt(unsigned char *in, unsigned char *out, 249 int numbits, long length, 250 des_key_schedule schedule, 251 _ossl_old_des_cblock *ivec) 252{ 253 DES_ofb_encrypt(in, out, numbits, length, (DES_key_schedule *)schedule, 254 ivec); 255} 256 257void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input, 258 _ossl_old_des_cblock *output, long length, 259 des_key_schedule schedule, 260 _ossl_old_des_cblock *ivec, int enc) 261{ 262 DES_pcbc_encrypt((unsigned char *)input, (unsigned char *)output, 263 length, (DES_key_schedule *)schedule, ivec, enc); 264} 265 266DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input, 267 _ossl_old_des_cblock *output, long length, 268 int out_count, _ossl_old_des_cblock *seed) 269{ 270 return DES_quad_cksum((unsigned char *)input, output, length, 271 out_count, seed); 272} 273 274void _ossl_old_des_random_seed(_ossl_old_des_cblock key) 275{ 276 RAND_seed(key, sizeof(_ossl_old_des_cblock)); 277} 278 279void _ossl_old_des_random_key(_ossl_old_des_cblock ret) 280{ 281 DES_random_key((DES_cblock *)ret); 282} 283 284int _ossl_old_des_read_password(_ossl_old_des_cblock *key, const char *prompt, 285 int verify) 286{ 287 return DES_read_password(key, prompt, verify); 288} 289 290int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1, 291 _ossl_old_des_cblock *key2, 292 const char *prompt, int verify) 293{ 294 return DES_read_2passwords(key1, key2, prompt, verify); 295} 296 297void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key) 298{ 299 DES_set_odd_parity(key); 300} 301 302int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key) 303{ 304 return DES_is_weak_key(key); 305} 306 307int _ossl_old_des_set_key(_ossl_old_des_cblock *key, 308 des_key_schedule schedule) 309{ 310 return DES_set_key(key, (DES_key_schedule *)schedule); 311} 312 313int _ossl_old_des_key_sched(_ossl_old_des_cblock *key, 314 des_key_schedule schedule) 315{ 316 return DES_key_sched(key, (DES_key_schedule *)schedule); 317} 318 319void _ossl_old_des_string_to_key(char *str, _ossl_old_des_cblock *key) 320{ 321 DES_string_to_key(str, key); 322} 323 324void _ossl_old_des_string_to_2keys(char *str, _ossl_old_des_cblock *key1, 325 _ossl_old_des_cblock *key2) 326{ 327 DES_string_to_2keys(str, key1, key2); 328} 329 330void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, 331 long length, des_key_schedule schedule, 332 _ossl_old_des_cblock *ivec, int *num, 333 int enc) 334{ 335 DES_cfb64_encrypt(in, out, length, (DES_key_schedule *)schedule, 336 ivec, num, enc); 337} 338 339void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, 340 long length, des_key_schedule schedule, 341 _ossl_old_des_cblock *ivec, int *num) 342{ 343 DES_ofb64_encrypt(in, out, length, (DES_key_schedule *)schedule, 344 ivec, num); 345} 346