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 "build/build_config.h" |
9 | 9 |
10 // Include headers to provide bswap for all platforms. | 10 // Include headers to provide bswap for all platforms. |
11 #if defined(COMPILER_MSVC) | 11 #if defined(COMPILER_MSVC) |
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 #define bswap_16(x) _byteswap_ushort(x) | 13 #define bswap_16(x) _byteswap_ushort(x) |
14 #define bswap_32(x) _byteswap_ulong(x) | 14 #define bswap_32(x) _byteswap_ulong(x) |
15 #define bswap_64(x) _byteswap_uint64(x) | 15 #define bswap_64(x) _byteswap_uint64(x) |
16 #elif defined(OS_MACOSX) | 16 #elif defined(OS_MACOSX) |
17 #include <libkern/OSByteOrder.h> | 17 #include <libkern/OSByteOrder.h> |
18 #define bswap_16(x) OSSwapInt16(x) | 18 #define bswap_16(x) OSSwapInt16(x) |
19 #define bswap_32(x) OSSwapInt32(x) | 19 #define bswap_32(x) OSSwapInt32(x) |
20 #define bswap_64(x) OSSwapInt64(x) | 20 #define bswap_64(x) OSSwapInt64(x) |
21 #elif defined(OS_OPENBSD) | |
22 #define bswap_16(x) swap16(x) | |
23 #define bswap_32(x) swap32(x) | |
24 #define bswap_64(x) swap64(x) | |
wtc
2011/10/18 21:50:26
Just curious: are swap16, swap32, and swap64 compi
Robert Nagy
2011/10/19 07:10:02
They are defined in sys/endian.h so I just include
| |
21 #else | 25 #else |
22 #include <byteswap.h> | 26 #include <byteswap.h> |
23 #endif | 27 #endif |
24 | 28 |
25 #if defined(ARCH_CPU_LITTLE_ENDIAN) | 29 #if defined(ARCH_CPU_LITTLE_ENDIAN) |
26 #define ntoh_64(x) bswap_64(x) | 30 #define ntoh_64(x) bswap_64(x) |
27 #define hton_64(x) bswap_64(x) | 31 #define hton_64(x) bswap_64(x) |
28 #else | 32 #else |
29 #define ntoh_64(x) (x) | 33 #define ntoh_64(x) (x) |
30 #define hton_64(x) (x) | 34 #define hton_64(x) (x) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 DCHECK_EQ(CTR, mode_); | 115 DCHECK_EQ(CTR, mode_); |
112 const uint8* plaintext_ptr = reinterpret_cast<const uint8*>(plaintext); | 116 const uint8* plaintext_ptr = reinterpret_cast<const uint8*>(plaintext); |
113 const uint8* mask_ptr = reinterpret_cast<const uint8*>(mask); | 117 const uint8* mask_ptr = reinterpret_cast<const uint8*>(mask); |
114 uint8* ciphertext_ptr = reinterpret_cast<uint8*>(ciphertext); | 118 uint8* ciphertext_ptr = reinterpret_cast<uint8*>(ciphertext); |
115 | 119 |
116 for (size_t i = 0; i < plaintext_len; ++i) | 120 for (size_t i = 0; i < plaintext_len; ++i) |
117 ciphertext_ptr[i] = plaintext_ptr[i] ^ mask_ptr[i]; | 121 ciphertext_ptr[i] = plaintext_ptr[i] ^ mask_ptr[i]; |
118 } | 122 } |
119 | 123 |
120 } // namespace crypto | 124 } // namespace crypto |
OLD | NEW |