OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/des.h" | 5 #include "net/ntlm/des.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "crypto/openssl_util.h" | 8 #include "crypto/openssl_util.h" |
9 #include "third_party/boringssl/src/include/openssl/des.h" | 9 #include "third_party/boringssl/src/include/openssl/des.h" |
10 | 10 |
11 // The iOS version of DESEncrypt is our own code. | 11 // The iOS version of DESEncrypt is our own code. |
12 // DESSetKeyParity and DESMakeKey are based on | 12 // DESSetKeyParity and DESMakeKey are based on |
13 // mozilla/security/manager/ssl/src/nsNTLMAuthModule.cpp, CVS rev. 1.14. | 13 // mozilla/security/manager/ssl/src/nsNTLMAuthModule.cpp, CVS rev. 1.14. |
14 | 14 |
15 /* ***** BEGIN LICENSE BLOCK ***** | 15 /* ***** BEGIN LICENSE BLOCK ***** |
(...skipping 27 matching lines...) Expand all Loading... |
43 * use your version of this file under the terms of the MPL, indicate your | 43 * use your version of this file under the terms of the MPL, indicate your |
44 * decision by deleting the provisions above and replace them with the notice | 44 * decision by deleting the provisions above and replace them with the notice |
45 * and other provisions required by the GPL or the LGPL. If you do not delete | 45 * and other provisions required by the GPL or the LGPL. If you do not delete |
46 * the provisions above, a recipient may use your version of this file under | 46 * the provisions above, a recipient may use your version of this file under |
47 * the terms of any one of the MPL, the GPL or the LGPL. | 47 * the terms of any one of the MPL, the GPL or the LGPL. |
48 * | 48 * |
49 * ***** END LICENSE BLOCK ***** */ | 49 * ***** END LICENSE BLOCK ***** */ |
50 | 50 |
51 // Set odd parity bit (in least significant bit position). | 51 // Set odd parity bit (in least significant bit position). |
52 static uint8_t DESSetKeyParity(uint8_t x) { | 52 static uint8_t DESSetKeyParity(uint8_t x) { |
53 if ((((x >> 7) ^ (x >> 6) ^ (x >> 5) ^ | 53 if ((((x >> 7) ^ (x >> 6) ^ (x >> 5) ^ (x >> 4) ^ (x >> 3) ^ (x >> 2) ^ |
54 (x >> 4) ^ (x >> 3) ^ (x >> 2) ^ | 54 (x >> 1)) & |
55 (x >> 1)) & 0x01) == 0) { | 55 0x01) == 0) { |
56 x |= 0x01; | 56 x |= 0x01; |
57 } else { | 57 } else { |
58 x &= 0xfe; | 58 x &= 0xfe; |
59 } | 59 } |
60 return x; | 60 return x; |
61 } | 61 } |
62 | 62 |
63 namespace net { | 63 namespace net { |
64 | 64 |
65 void DESMakeKey(const uint8_t* raw, uint8_t* key) { | 65 void DESMakeKey(const uint8_t* raw, uint8_t* key) { |
66 key[0] = DESSetKeyParity(raw[0]); | 66 key[0] = DESSetKeyParity(raw[0]); |
67 key[1] = DESSetKeyParity((raw[0] << 7) | (raw[1] >> 1)); | 67 key[1] = DESSetKeyParity((raw[0] << 7) | (raw[1] >> 1)); |
68 key[2] = DESSetKeyParity((raw[1] << 6) | (raw[2] >> 2)); | 68 key[2] = DESSetKeyParity((raw[1] << 6) | (raw[2] >> 2)); |
69 key[3] = DESSetKeyParity((raw[2] << 5) | (raw[3] >> 3)); | 69 key[3] = DESSetKeyParity((raw[2] << 5) | (raw[3] >> 3)); |
70 key[4] = DESSetKeyParity((raw[3] << 4) | (raw[4] >> 4)); | 70 key[4] = DESSetKeyParity((raw[3] << 4) | (raw[4] >> 4)); |
71 key[5] = DESSetKeyParity((raw[4] << 3) | (raw[5] >> 5)); | 71 key[5] = DESSetKeyParity((raw[4] << 3) | (raw[5] >> 5)); |
72 key[6] = DESSetKeyParity((raw[5] << 2) | (raw[6] >> 6)); | 72 key[6] = DESSetKeyParity((raw[5] << 2) | (raw[6] >> 6)); |
73 key[7] = DESSetKeyParity((raw[6] << 1)); | 73 key[7] = DESSetKeyParity((raw[6] << 1)); |
74 } | 74 } |
75 | 75 |
76 void DESEncrypt(const uint8_t* key, const uint8_t* src, uint8_t* hash) { | 76 void DESEncrypt(const uint8_t* key, const uint8_t* src, uint8_t* hash) { |
77 crypto::EnsureOpenSSLInit(); | 77 crypto::EnsureOpenSSLInit(); |
78 | 78 |
79 DES_key_schedule ks; | 79 DES_key_schedule ks; |
80 DES_set_key( | 80 DES_set_key(reinterpret_cast<const DES_cblock*>(key), &ks); |
81 reinterpret_cast<const DES_cblock*>(key), &ks); | |
82 | 81 |
83 DES_ecb_encrypt(reinterpret_cast<const DES_cblock*>(src), | 82 DES_ecb_encrypt(reinterpret_cast<const DES_cblock*>(src), |
84 reinterpret_cast<DES_cblock*>(hash), &ks, DES_ENCRYPT); | 83 reinterpret_cast<DES_cblock*>(hash), &ks, DES_ENCRYPT); |
85 } | 84 } |
86 | 85 |
87 } // namespace net | 86 } // namespace net |
OLD | NEW |