| 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/http/des.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 #if defined(USE_OPENSSL) | 9 #if defined(USE_OPENSSL) |
| 10 #include <openssl/des.h> | 10 #include <openssl/des.h> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 * under the terms of either the GPL or the LGPL, and not to allow others to | 49 * under the terms of either the GPL or the LGPL, and not to allow others to |
| 50 * use your version of this file under the terms of the MPL, indicate your | 50 * use your version of this file under the terms of the MPL, indicate your |
| 51 * decision by deleting the provisions above and replace them with the notice | 51 * decision by deleting the provisions above and replace them with the notice |
| 52 * and other provisions required by the GPL or the LGPL. If you do not delete | 52 * and other provisions required by the GPL or the LGPL. If you do not delete |
| 53 * the provisions above, a recipient may use your version of this file under | 53 * the provisions above, a recipient may use your version of this file under |
| 54 * the terms of any one of the MPL, the GPL or the LGPL. | 54 * the terms of any one of the MPL, the GPL or the LGPL. |
| 55 * | 55 * |
| 56 * ***** END LICENSE BLOCK ***** */ | 56 * ***** END LICENSE BLOCK ***** */ |
| 57 | 57 |
| 58 // Set odd parity bit (in least significant bit position). | 58 // Set odd parity bit (in least significant bit position). |
| 59 static uint8 DESSetKeyParity(uint8 x) { | 59 static uint8_t DESSetKeyParity(uint8_t x) { |
| 60 if ((((x >> 7) ^ (x >> 6) ^ (x >> 5) ^ | 60 if ((((x >> 7) ^ (x >> 6) ^ (x >> 5) ^ |
| 61 (x >> 4) ^ (x >> 3) ^ (x >> 2) ^ | 61 (x >> 4) ^ (x >> 3) ^ (x >> 2) ^ |
| 62 (x >> 1)) & 0x01) == 0) { | 62 (x >> 1)) & 0x01) == 0) { |
| 63 x |= 0x01; | 63 x |= 0x01; |
| 64 } else { | 64 } else { |
| 65 x &= 0xfe; | 65 x &= 0xfe; |
| 66 } | 66 } |
| 67 return x; | 67 return x; |
| 68 } | 68 } |
| 69 | 69 |
| 70 namespace net { | 70 namespace net { |
| 71 | 71 |
| 72 void DESMakeKey(const uint8* raw, uint8* key) { | 72 void DESMakeKey(const uint8_t* raw, uint8_t* key) { |
| 73 key[0] = DESSetKeyParity(raw[0]); | 73 key[0] = DESSetKeyParity(raw[0]); |
| 74 key[1] = DESSetKeyParity((raw[0] << 7) | (raw[1] >> 1)); | 74 key[1] = DESSetKeyParity((raw[0] << 7) | (raw[1] >> 1)); |
| 75 key[2] = DESSetKeyParity((raw[1] << 6) | (raw[2] >> 2)); | 75 key[2] = DESSetKeyParity((raw[1] << 6) | (raw[2] >> 2)); |
| 76 key[3] = DESSetKeyParity((raw[2] << 5) | (raw[3] >> 3)); | 76 key[3] = DESSetKeyParity((raw[2] << 5) | (raw[3] >> 3)); |
| 77 key[4] = DESSetKeyParity((raw[3] << 4) | (raw[4] >> 4)); | 77 key[4] = DESSetKeyParity((raw[3] << 4) | (raw[4] >> 4)); |
| 78 key[5] = DESSetKeyParity((raw[4] << 3) | (raw[5] >> 5)); | 78 key[5] = DESSetKeyParity((raw[4] << 3) | (raw[5] >> 5)); |
| 79 key[6] = DESSetKeyParity((raw[5] << 2) | (raw[6] >> 6)); | 79 key[6] = DESSetKeyParity((raw[5] << 2) | (raw[6] >> 6)); |
| 80 key[7] = DESSetKeyParity((raw[6] << 1)); | 80 key[7] = DESSetKeyParity((raw[6] << 1)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 #if defined(USE_OPENSSL) | 83 #if defined(USE_OPENSSL) |
| 84 | 84 |
| 85 void DESEncrypt(const uint8* key, const uint8* src, uint8* hash) { | 85 void DESEncrypt(const uint8_t* key, const uint8_t* src, uint8_t* hash) { |
| 86 crypto::EnsureOpenSSLInit(); | 86 crypto::EnsureOpenSSLInit(); |
| 87 | 87 |
| 88 DES_key_schedule ks; | 88 DES_key_schedule ks; |
| 89 DES_set_key( | 89 DES_set_key( |
| 90 reinterpret_cast<const DES_cblock*>(key), &ks); | 90 reinterpret_cast<const DES_cblock*>(key), &ks); |
| 91 | 91 |
| 92 DES_ecb_encrypt(reinterpret_cast<const DES_cblock*>(src), | 92 DES_ecb_encrypt(reinterpret_cast<const DES_cblock*>(src), |
| 93 reinterpret_cast<DES_cblock*>(hash), &ks, DES_ENCRYPT); | 93 reinterpret_cast<DES_cblock*>(hash), &ks, DES_ENCRYPT); |
| 94 } | 94 } |
| 95 | 95 |
| 96 #elif defined(OS_IOS) | 96 #elif defined(OS_IOS) |
| 97 | 97 |
| 98 void DESEncrypt(const uint8* key, const uint8* src, uint8* hash) { | 98 void DESEncrypt(const uint8_t* key, const uint8_t* src, uint8_t* hash) { |
| 99 CCCryptorStatus status; | 99 CCCryptorStatus status; |
| 100 size_t data_out_moved = 0; | 100 size_t data_out_moved = 0; |
| 101 status = CCCrypt(kCCEncrypt, kCCAlgorithmDES, kCCOptionECBMode, | 101 status = CCCrypt(kCCEncrypt, kCCAlgorithmDES, kCCOptionECBMode, |
| 102 key, 8, NULL, src, 8, hash, 8, &data_out_moved); | 102 key, 8, NULL, src, 8, hash, 8, &data_out_moved); |
| 103 DCHECK(status == kCCSuccess); | 103 DCHECK(status == kCCSuccess); |
| 104 DCHECK(data_out_moved == 8); | 104 DCHECK(data_out_moved == 8); |
| 105 } | 105 } |
| 106 | 106 |
| 107 #endif | 107 #endif |
| 108 | 108 |
| 109 } // namespace net | 109 } // namespace net |
| OLD | NEW |