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)
21 for (i = 0; i < length; i++)
22 (*key)[i % 8] ^= (str[i] << 1);
23 #else /* MIT COMPATIBLE */
24 for (i = 0; i < length; i++) {
25 register unsigned char j = str[i];
28 (*key)[i % 8] ^= (j << 1);
30 /* Reverse the bit order 05/05/92 eay */
31 j = ((j << 4) & 0xf0) | ((j >> 4) & 0x0f);
32 j = ((j << 2) & 0xcc) | ((j >> 2) & 0x33);
33 j = ((j << 1) & 0xaa) | ((j >> 1) & 0x55);
34 (*key)[7 - (i % 8)] ^= j;
38 DES_set_odd_parity(key);
39 DES_set_key_unchecked(key, &ks);
40 DES_cbc_cksum((const unsigned char *)str, key, length, &ks, key);
41 OPENSSL_cleanse(&ks, sizeof(ks));
42 DES_set_odd_parity(key);
45 void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
55 for (i = 0; i < length; i++) {
56 (*key2)[i] = (*key1)[i] = (str[i] << 1);
59 for (i = 0; i < length; i++) {
61 (*key2)[i % 8] ^= (str[i] << 1);
63 (*key1)[i % 8] ^= (str[i] << 1);
66 #else /* MIT COMPATIBLE */
67 for (i = 0; i < length; i++) {
68 register unsigned char j = str[i];
72 (*key1)[i % 8] ^= (j << 1);
74 (*key2)[i % 8] ^= (j << 1);
76 j = ((j << 4) & 0xf0) | ((j >> 4) & 0x0f);
77 j = ((j << 2) & 0xcc) | ((j >> 2) & 0x33);
78 j = ((j << 1) & 0xaa) | ((j >> 1) & 0x55);
80 (*key1)[7 - (i % 8)] ^= j;
82 (*key2)[7 - (i % 8)] ^= j;
86 memcpy(key2, key1, 8);
88 DES_set_odd_parity(key1);
89 DES_set_odd_parity(key2);
90 DES_set_key_unchecked(key1, &ks);
91 DES_cbc_cksum((const unsigned char *)str, key1, length, &ks, key1);
92 DES_set_key_unchecked(key2, &ks);
93 DES_cbc_cksum((const unsigned char *)str, key2, length, &ks, key2);
94 OPENSSL_cleanse(&ks, sizeof(ks));
95 DES_set_odd_parity(key1);
96 DES_set_odd_parity(key2);