Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: net/http/des.cc

Issue 2873673002: Add unit tests for NTLMv1 portable implementation (Closed)
Patch Set: Rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/des.h ('k') | net/http/des_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/http/des.h"
6
7 #include "base/logging.h"
8 #include "crypto/openssl_util.h"
9 #include "third_party/boringssl/src/include/openssl/des.h"
10
11 // The iOS version of DESEncrypt is our own code.
12 // DESSetKeyParity and DESMakeKey are based on
13 // mozilla/security/manager/ssl/src/nsNTLMAuthModule.cpp, CVS rev. 1.14.
14
15 /* ***** BEGIN LICENSE BLOCK *****
16 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
17 *
18 * The contents of this file are subject to the Mozilla Public License Version
19 * 1.1 (the "License"); you may not use this file except in compliance with
20 * the License. You may obtain a copy of the License at
21 * http://www.mozilla.org/MPL/
22 *
23 * Software distributed under the License is distributed on an "AS IS" basis,
24 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
25 * for the specific language governing rights and limitations under the
26 * License.
27 *
28 * The Original Code is Mozilla.
29 *
30 * The Initial Developer of the Original Code is IBM Corporation.
31 * Portions created by IBM Corporation are Copyright (C) 2003
32 * IBM Corporation. All Rights Reserved.
33 *
34 * Contributor(s):
35 * Darin Fisher <darin@meer.net>
36 *
37 * Alternatively, the contents of this file may be used under the terms of
38 * either the GNU General Public License Version 2 or later (the "GPL"), or
39 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
40 * in which case the provisions of the GPL or the LGPL are applicable instead
41 * of those above. If you wish to allow use of your version of this file only
42 * under the terms of either the GPL or the LGPL, and not to allow others to
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
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
47 * the terms of any one of the MPL, the GPL or the LGPL.
48 *
49 * ***** END LICENSE BLOCK ***** */
50
51 // Set odd parity bit (in least significant bit position).
52 static uint8_t DESSetKeyParity(uint8_t x) {
53 if ((((x >> 7) ^ (x >> 6) ^ (x >> 5) ^
54 (x >> 4) ^ (x >> 3) ^ (x >> 2) ^
55 (x >> 1)) & 0x01) == 0) {
56 x |= 0x01;
57 } else {
58 x &= 0xfe;
59 }
60 return x;
61 }
62
63 namespace net {
64
65 void DESMakeKey(const uint8_t* raw, uint8_t* key) {
66 key[0] = DESSetKeyParity(raw[0]);
67 key[1] = DESSetKeyParity((raw[0] << 7) | (raw[1] >> 1));
68 key[2] = DESSetKeyParity((raw[1] << 6) | (raw[2] >> 2));
69 key[3] = DESSetKeyParity((raw[2] << 5) | (raw[3] >> 3));
70 key[4] = DESSetKeyParity((raw[3] << 4) | (raw[4] >> 4));
71 key[5] = DESSetKeyParity((raw[4] << 3) | (raw[5] >> 5));
72 key[6] = DESSetKeyParity((raw[5] << 2) | (raw[6] >> 6));
73 key[7] = DESSetKeyParity((raw[6] << 1));
74 }
75
76 void DESEncrypt(const uint8_t* key, const uint8_t* src, uint8_t* hash) {
77 crypto::EnsureOpenSSLInit();
78
79 DES_key_schedule ks;
80 DES_set_key(
81 reinterpret_cast<const DES_cblock*>(key), &ks);
82
83 DES_ecb_encrypt(reinterpret_cast<const DES_cblock*>(src),
84 reinterpret_cast<DES_cblock*>(hash), &ks, DES_ENCRYPT);
85 }
86
87 } // namespace net
OLDNEW
« no previous file with comments | « net/http/des.h ('k') | net/http/des_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698