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

Unified Diff: crypto/p224.cc

Issue 9716020: Add base::HostToNetXX() & NetToHostXX(), and use them to replace htonX() & ntohX() in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crypto/encryptor.cc ('k') | crypto/symmetric_key_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/p224.cc
diff --git a/crypto/p224.cc b/crypto/p224.cc
index d0e4baf3bba8f8c2b06cabce61cb9cc3867e14fc..575b51f4ce946cf06b4443ddf68cda8667240752 100644
--- a/crypto/p224.cc
+++ b/crypto/p224.cc
@@ -13,16 +13,11 @@
#include "base/sys_byteorder.h"
-#if defined(OS_WIN)
-// Allow htonl/ntohl to be called without requiring ws2_32.dll to be loaded,
-// which isn't available in Chrome's sandbox. See crbug.com/116591.
-// TODO(wez): Replace these calls with base::htonl() etc when available.
-#define ntohl(x) _byteswap_ulong(x)
-#define htonl(x) _byteswap_ulong(x)
-#endif // OS_WIN
-
namespace {
+using base::HostToNet32;
+using base::NetToHost32;
+
// Field element functions.
//
// The field that we're dealing with is ℤ/pℤ where p = 2**224 - 2**96 + 1.
@@ -564,27 +559,33 @@ void ScalarMult(Point* out, const Point& a,
// Get224Bits reads 7 words from in and scatters their contents in
// little-endian form into 8 words at out, 28 bits per output word.
void Get224Bits(uint32* out, const uint32* in) {
- out[0] = ntohl(in[6]) & kBottom28Bits;
- out[1] = ((ntohl(in[5]) << 4) | (ntohl(in[6]) >> 28)) & kBottom28Bits;
- out[2] = ((ntohl(in[4]) << 8) | (ntohl(in[5]) >> 24)) & kBottom28Bits;
- out[3] = ((ntohl(in[3]) << 12) | (ntohl(in[4]) >> 20)) & kBottom28Bits;
- out[4] = ((ntohl(in[2]) << 16) | (ntohl(in[3]) >> 16)) & kBottom28Bits;
- out[5] = ((ntohl(in[1]) << 20) | (ntohl(in[2]) >> 12)) & kBottom28Bits;
- out[6] = ((ntohl(in[0]) << 24) | (ntohl(in[1]) >> 8)) & kBottom28Bits;
- out[7] = (ntohl(in[0]) >> 4) & kBottom28Bits;
+ out[0] = NetToHost32(in[6]) & kBottom28Bits;
+ out[1] = ((NetToHost32(in[5]) << 4) |
+ (NetToHost32(in[6]) >> 28)) & kBottom28Bits;
+ out[2] = ((NetToHost32(in[4]) << 8) |
+ (NetToHost32(in[5]) >> 24)) & kBottom28Bits;
+ out[3] = ((NetToHost32(in[3]) << 12) |
+ (NetToHost32(in[4]) >> 20)) & kBottom28Bits;
+ out[4] = ((NetToHost32(in[2]) << 16) |
+ (NetToHost32(in[3]) >> 16)) & kBottom28Bits;
+ out[5] = ((NetToHost32(in[1]) << 20) |
+ (NetToHost32(in[2]) >> 12)) & kBottom28Bits;
+ out[6] = ((NetToHost32(in[0]) << 24) |
+ (NetToHost32(in[1]) >> 8)) & kBottom28Bits;
+ out[7] = (NetToHost32(in[0]) >> 4) & kBottom28Bits;
}
// Put224Bits performs the inverse operation to Get224Bits: taking 28 bits from
// each of 8 input words and writing them in big-endian order to 7 words at
// out.
void Put224Bits(uint32* out, const uint32* in) {
- out[6] = htonl((in[0] >> 0) | (in[1] << 28));
- out[5] = htonl((in[1] >> 4) | (in[2] << 24));
- out[4] = htonl((in[2] >> 8) | (in[3] << 20));
- out[3] = htonl((in[3] >> 12) | (in[4] << 16));
- out[2] = htonl((in[4] >> 16) | (in[5] << 12));
- out[1] = htonl((in[5] >> 20) | (in[6] << 8));
- out[0] = htonl((in[6] >> 24) | (in[7] << 4));
+ out[6] = HostToNet32((in[0] >> 0) | (in[1] << 28));
+ out[5] = HostToNet32((in[1] >> 4) | (in[2] << 24));
+ out[4] = HostToNet32((in[2] >> 8) | (in[3] << 20));
+ out[3] = HostToNet32((in[3] >> 12) | (in[4] << 16));
+ out[2] = HostToNet32((in[4] >> 16) | (in[5] << 12));
+ out[1] = HostToNet32((in[5] >> 20) | (in[6] << 8));
+ out[0] = HostToNet32((in[6] >> 24) | (in[7] << 4));
}
} // anonymous namespace
« no previous file with comments | « crypto/encryptor.cc ('k') | crypto/symmetric_key_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698