2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
11 * DES low level APIs are deprecated for public use, but still ok for internal
14 #include "internal/deprecated.h"
16 #include <openssl/crypto.h>
17 #include "des_local.h"
19 void DES_string_to_key(const char *str, DES_cblock *key)
26 for (i = 0; i < length; i++) {
27 register unsigned char j = str[i];
30 (*key)[i % 8] ^= (j << 1);
32 /* Reverse the bit order 05/05/92 eay */
33 j = ((j << 4) & 0xf0) | ((j >> 4) & 0x0f);
34 j = ((j << 2) & 0xcc) | ((j >> 2) & 0x33);
35 j = ((j << 1) & 0xaa) | ((j >> 1) & 0x55);
36 (*key)[7 - (i % 8)] ^= j;
39 DES_set_odd_parity(key);
40 DES_set_key_unchecked(key, &ks);
41 DES_cbc_cksum((const unsigned char *)str, key, length, &ks, key);
42 OPENSSL_cleanse(&ks, sizeof(ks));
43 DES_set_odd_parity(key);
46 void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2)
54 for (i = 0; i < length; i++) {
55 register unsigned char j = str[i];
59 (*key1)[i % 8] ^= (j << 1);
61 (*key2)[i % 8] ^= (j << 1);
63 j = ((j << 4) & 0xf0) | ((j >> 4) & 0x0f);
64 j = ((j << 2) & 0xcc) | ((j >> 2) & 0x33);
65 j = ((j << 1) & 0xaa) | ((j >> 1) & 0x55);
67 (*key1)[7 - (i % 8)] ^= j;
69 (*key2)[7 - (i % 8)] ^= j;
73 memcpy(key2, key1, 8);
74 DES_set_odd_parity(key1);
75 DES_set_odd_parity(key2);
76 DES_set_key_unchecked(key1, &ks);
77 DES_cbc_cksum((const unsigned char *)str, key1, length, &ks, key1);
78 DES_set_key_unchecked(key2, &ks);
79 DES_cbc_cksum((const unsigned char *)str, key2, length, &ks, key2);
80 OPENSSL_cleanse(&ks, sizeof(ks));
81 DES_set_odd_parity(key1);
82 DES_set_odd_parity(key2);