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 <openssl/des.h> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 | |
9 #if defined(USE_OPENSSL) | |
10 #include <openssl/des.h> | |
11 #include "crypto/openssl_util.h" | 10 #include "crypto/openssl_util.h" |
12 #elif defined(OS_IOS) | |
13 #include <CommonCrypto/CommonCryptor.h> | |
14 #else | |
15 #error "Unknown platform" | |
16 #endif | |
17 | 11 |
18 // The iOS version of DESEncrypt is our own code. | 12 // The iOS version of DESEncrypt is our own code. |
19 // DESSetKeyParity and DESMakeKey are based on | 13 // DESSetKeyParity and DESMakeKey are based on |
20 // mozilla/security/manager/ssl/src/nsNTLMAuthModule.cpp, CVS rev. 1.14. | 14 // mozilla/security/manager/ssl/src/nsNTLMAuthModule.cpp, CVS rev. 1.14. |
21 | 15 |
22 /* ***** BEGIN LICENSE BLOCK ***** | 16 /* ***** BEGIN LICENSE BLOCK ***** |
23 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 17 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
24 * | 18 * |
25 * The contents of this file are subject to the Mozilla Public License Version | 19 * The contents of this file are subject to the Mozilla Public License Version |
26 * 1.1 (the "License"); you may not use this file except in compliance with | 20 * 1.1 (the "License"); you may not use this file except in compliance with |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 key[0] = DESSetKeyParity(raw[0]); | 67 key[0] = DESSetKeyParity(raw[0]); |
74 key[1] = DESSetKeyParity((raw[0] << 7) | (raw[1] >> 1)); | 68 key[1] = DESSetKeyParity((raw[0] << 7) | (raw[1] >> 1)); |
75 key[2] = DESSetKeyParity((raw[1] << 6) | (raw[2] >> 2)); | 69 key[2] = DESSetKeyParity((raw[1] << 6) | (raw[2] >> 2)); |
76 key[3] = DESSetKeyParity((raw[2] << 5) | (raw[3] >> 3)); | 70 key[3] = DESSetKeyParity((raw[2] << 5) | (raw[3] >> 3)); |
77 key[4] = DESSetKeyParity((raw[3] << 4) | (raw[4] >> 4)); | 71 key[4] = DESSetKeyParity((raw[3] << 4) | (raw[4] >> 4)); |
78 key[5] = DESSetKeyParity((raw[4] << 3) | (raw[5] >> 5)); | 72 key[5] = DESSetKeyParity((raw[4] << 3) | (raw[5] >> 5)); |
79 key[6] = DESSetKeyParity((raw[5] << 2) | (raw[6] >> 6)); | 73 key[6] = DESSetKeyParity((raw[5] << 2) | (raw[6] >> 6)); |
80 key[7] = DESSetKeyParity((raw[6] << 1)); | 74 key[7] = DESSetKeyParity((raw[6] << 1)); |
81 } | 75 } |
82 | 76 |
83 #if defined(USE_OPENSSL) | |
84 | |
85 void DESEncrypt(const uint8_t* key, const uint8_t* src, uint8_t* hash) { | 77 void DESEncrypt(const uint8_t* key, const uint8_t* src, uint8_t* hash) { |
86 crypto::EnsureOpenSSLInit(); | 78 crypto::EnsureOpenSSLInit(); |
87 | 79 |
88 DES_key_schedule ks; | 80 DES_key_schedule ks; |
89 DES_set_key( | 81 DES_set_key( |
90 reinterpret_cast<const DES_cblock*>(key), &ks); | 82 reinterpret_cast<const DES_cblock*>(key), &ks); |
91 | 83 |
92 DES_ecb_encrypt(reinterpret_cast<const DES_cblock*>(src), | 84 DES_ecb_encrypt(reinterpret_cast<const DES_cblock*>(src), |
93 reinterpret_cast<DES_cblock*>(hash), &ks, DES_ENCRYPT); | 85 reinterpret_cast<DES_cblock*>(hash), &ks, DES_ENCRYPT); |
94 } | 86 } |
95 | 87 |
96 #elif defined(OS_IOS) | |
97 | |
98 void DESEncrypt(const uint8_t* key, const uint8_t* src, uint8_t* hash) { | |
99 CCCryptorStatus status; | |
100 size_t data_out_moved = 0; | |
101 status = CCCrypt(kCCEncrypt, kCCAlgorithmDES, kCCOptionECBMode, | |
102 key, 8, NULL, src, 8, hash, 8, &data_out_moved); | |
103 DCHECK(status == kCCSuccess); | |
104 DCHECK(data_out_moved == 8); | |
105 } | |
106 | |
107 #endif | |
108 | |
109 } // namespace net | 88 } // namespace net |
OLD | NEW |