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

Side by Side Diff: crypto/p224.cc

Issue 9614004: Avoid loading ws2_32.dll just to get htons() and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make patch 4.7% uglier with helpful TODOs. Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | net/base/net_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This is an implementation of the P224 elliptic curve group. It's written to 5 // This is an implementation of the P224 elliptic curve group. It's written to
6 // be short and simple rather than fast, although it's still constant-time. 6 // be short and simple rather than fast, although it's still constant-time.
7 // 7 //
8 // See http://www.imperialviolet.org/2010/12/04/ecc.html ([1]) for background. 8 // See http://www.imperialviolet.org/2010/12/04/ecc.html ([1]) for background.
9 9
10 #include "crypto/p224.h" 10 #include "crypto/p224.h"
11 11
12 #include <string.h> 12 #include <string.h>
13 13
14 #include "base/sys_byteorder.h" 14 #include "base/sys_byteorder.h"
15 15
16 #if defined(OS_WIN)
17 // Allow htonl/ntohl to be called without requiring ws2_32.dll to be loaded,
18 // which isn't available in Chrome's sandbox. See crbug.com/116591.
19 // TODO(wez): Replace these calls with base::htonl() etc when available.
20 #define ntohl(x) _byteswap_ulong(x)
21 #define htonl(x) _byteswap_ulong(x)
22 #endif // OS_WIN
23
16 namespace { 24 namespace {
17 25
18 // Field element functions. 26 // Field element functions.
19 // 27 //
20 // The field that we're dealing with is ℤ/pℤ where p = 2**224 - 2**96 + 1. 28 // The field that we're dealing with is ℤ/pℤ where p = 2**224 - 2**96 + 1.
21 // 29 //
22 // Field elements are represented by a FieldElement, which is a typedef to an 30 // Field elements are represented by a FieldElement, which is a typedef to an
23 // array of 8 uint32's. The value of a FieldElement, a, is: 31 // array of 8 uint32's. The value of a FieldElement, a, is:
24 // a[0] + 2**28·a[1] + 2**56·a[1] + ... + 2**196·a[7] 32 // a[0] + 2**28·a[1] + 2**56·a[1] + ... + 2**196·a[7]
25 // 33 //
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 Subtract(&out->y, kP, y); 677 Subtract(&out->y, kP, y);
670 Reduce(&out->y); 678 Reduce(&out->y);
671 679
672 memset(&out->z, 0, sizeof(out->z)); 680 memset(&out->z, 0, sizeof(out->z));
673 out->z[0] = 1; 681 out->z[0] = 1;
674 } 682 }
675 683
676 } // namespace p224 684 } // namespace p224
677 685
678 } // namespace crypto 686 } // namespace crypto
OLDNEW
« no previous file with comments | « no previous file | net/base/net_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698