| 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 "crypto/encryptor.h" | 5 #include "crypto/encryptor.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "build/build_config.h" | 8 #include "base/sys_byteorder.h" |
| 9 | |
| 10 // Include headers to provide bswap for all platforms. | |
| 11 #if defined(COMPILER_MSVC) | |
| 12 #include <stdlib.h> | |
| 13 #define bswap_16(x) _byteswap_ushort(x) | |
| 14 #define bswap_32(x) _byteswap_ulong(x) | |
| 15 #define bswap_64(x) _byteswap_uint64(x) | |
| 16 #elif defined(OS_MACOSX) | |
| 17 #include <libkern/OSByteOrder.h> | |
| 18 #define bswap_16(x) OSSwapInt16(x) | |
| 19 #define bswap_32(x) OSSwapInt32(x) | |
| 20 #define bswap_64(x) OSSwapInt64(x) | |
| 21 #elif defined(OS_OPENBSD) | |
| 22 #include <sys/endian.h> | |
| 23 #define bswap_16(x) swap16(x) | |
| 24 #define bswap_32(x) swap32(x) | |
| 25 #define bswap_64(x) swap64(x) | |
| 26 #else | |
| 27 #include <byteswap.h> | |
| 28 #endif | |
| 29 | |
| 30 #if defined(ARCH_CPU_LITTLE_ENDIAN) | |
| 31 #define ntoh_64(x) bswap_64(x) | |
| 32 #define hton_64(x) bswap_64(x) | |
| 33 #else | |
| 34 #define ntoh_64(x) (x) | |
| 35 #define hton_64(x) (x) | |
| 36 #endif | |
| 37 | 9 |
| 38 namespace crypto { | 10 namespace crypto { |
| 39 | 11 |
| 40 ///////////////////////////////////////////////////////////////////////////// | 12 ///////////////////////////////////////////////////////////////////////////// |
| 41 // Encyptor::Counter Implementation. | 13 // Encyptor::Counter Implementation. |
| 42 Encryptor::Counter::Counter(const base::StringPiece& counter) { | 14 Encryptor::Counter::Counter(const base::StringPiece& counter) { |
| 43 CHECK(sizeof(counter_) == counter.length()); | 15 CHECK(sizeof(counter_) == counter.length()); |
| 44 | 16 |
| 45 memcpy(&counter_, counter.data(), sizeof(counter_)); | 17 memcpy(&counter_, counter.data(), sizeof(counter_)); |
| 46 } | 18 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 DCHECK_EQ(CTR, mode_); | 88 DCHECK_EQ(CTR, mode_); |
| 117 const uint8* plaintext_ptr = reinterpret_cast<const uint8*>(plaintext); | 89 const uint8* plaintext_ptr = reinterpret_cast<const uint8*>(plaintext); |
| 118 const uint8* mask_ptr = reinterpret_cast<const uint8*>(mask); | 90 const uint8* mask_ptr = reinterpret_cast<const uint8*>(mask); |
| 119 uint8* ciphertext_ptr = reinterpret_cast<uint8*>(ciphertext); | 91 uint8* ciphertext_ptr = reinterpret_cast<uint8*>(ciphertext); |
| 120 | 92 |
| 121 for (size_t i = 0; i < plaintext_len; ++i) | 93 for (size_t i = 0; i < plaintext_len; ++i) |
| 122 ciphertext_ptr[i] = plaintext_ptr[i] ^ mask_ptr[i]; | 94 ciphertext_ptr[i] = plaintext_ptr[i] ^ mask_ptr[i]; |
| 123 } | 95 } |
| 124 | 96 |
| 125 } // namespace crypto | 97 } // namespace crypto |
| OLD | NEW |