2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include <openssl/crypto.h>
13 void DES_string_to_key(const char *str, DES_cblock *key)
20 for (i = 0; i < length; i++) {
21 register unsigned char j = str[i];
24 (*key)[i % 8] ^= (j << 1);
26 /* Reverse the bit order 05/05/92 eay */
27 j = ((j << 4) & 0xf0) | ((j >> 4) & 0x0f);
28 j = ((j << 2) & 0xcc) | ((j >> 2) & 0x33);
29 j = ((j << 1) & 0xaa) | ((j >> 1) & 0x55);
30 (*key)[7 - (i % 8)] ^= j;
33 DES_set_odd_parity(key);
34 DES_set_key_unchecked(key, &ks);
35 DES_cbc_cksum((const unsigned char *)str, key, length, &ks, key);
36 OPENSSL_cleanse(&ks, sizeof(ks));
37 DES_set_odd_parity(key);
40 void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
48 for (i = 0; i < length; i++) {
49 register unsigned char j = str[i];
53 (*key1)[i % 8] ^= (j << 1);
55 (*key2)[i % 8] ^= (j << 1);
57 j = ((j << 4) & 0xf0) | ((j >> 4) & 0x0f);
58 j = ((j << 2) & 0xcc) | ((j >> 2) & 0x33);
59 j = ((j << 1) & 0xaa) | ((j >> 1) & 0x55);
61 (*key1)[7 - (i % 8)] ^= j;
63 (*key2)[7 - (i % 8)] ^= j;
67 memcpy(key2, key1, 8);
68 DES_set_odd_parity(key1);
69 DES_set_odd_parity(key2);
70 DES_set_key_unchecked(key1, &ks);
71 DES_cbc_cksum((const unsigned char *)str, key1, length, &ks, key1);
72 DES_set_key_unchecked(key2, &ks);
73 DES_cbc_cksum((const unsigned char *)str, key2, length, &ks, key2);
74 OPENSSL_cleanse(&ks, sizeof(ks));
75 DES_set_odd_parity(key1);
76 DES_set_odd_parity(key2);