aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/block/aes_ssse3/aes_ssse3.cpp58
-rw-r--r--src/block/idea_sse2/idea_sse2.cpp20
-rw-r--r--src/build-data/cc/gcc.txt2
-rw-r--r--src/cms/cms_algo.cpp2
-rw-r--r--src/cms/cms_dec.cpp4
-rw-r--r--src/cms/cms_enc.cpp2
-rw-r--r--src/codec/hex/hex.cpp2
-rw-r--r--src/constructs/fpe/fpe.cpp8
-rw-r--r--src/hash/sha2_32/sha2_32.cpp4
-rw-r--r--src/hash/sha2_64/sha2_64.cpp4
-rw-r--r--src/hash/skein/skein_512.cpp12
-rw-r--r--src/ssl/hello.cpp5
-rw-r--r--src/utils/cpuid.cpp2
-rw-r--r--src/utils/mlock.cpp4
-rw-r--r--src/utils/simd_32/simd_sse.h6
15 files changed, 77 insertions, 58 deletions
diff --git a/src/block/aes_ssse3/aes_ssse3.cpp b/src/block/aes_ssse3/aes_ssse3.cpp
index c5869f899..774ccbabb 100644
--- a/src/block/aes_ssse3/aes_ssse3.cpp
+++ b/src/block/aes_ssse3/aes_ssse3.cpp
@@ -339,10 +339,10 @@ __m128i aes_ssse3_decrypt(__m128i B, const __m128i* keys, size_t rounds)
*/
void AES_128_SSSE3::encrypt_n(const byte in[], byte out[], size_t blocks) const
{
- const __m128i* in_mm = (const __m128i*)in;
- __m128i* out_mm = (__m128i*)out;
+ const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
+ __m128i* out_mm = reinterpret_cast<__m128i*>(out);
- const __m128i* keys = (const __m128i*)&EK[0];
+ const __m128i* keys = reinterpret_cast<const __m128i*>(&EK[0]);
for(size_t i = 0; i != blocks; ++i)
{
@@ -356,10 +356,10 @@ void AES_128_SSSE3::encrypt_n(const byte in[], byte out[], size_t blocks) const
*/
void AES_128_SSSE3::decrypt_n(const byte in[], byte out[], size_t blocks) const
{
- const __m128i* in_mm = (const __m128i*)in;
- __m128i* out_mm = (__m128i*)out;
+ const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
+ __m128i* out_mm = reinterpret_cast<__m128i*>(out);
- const __m128i* keys = (const __m128i*)&DK[0];
+ const __m128i* keys = reinterpret_cast<const __m128i*>(&DK[0]);
for(size_t i = 0; i != blocks; ++i)
{
@@ -376,10 +376,10 @@ void AES_128_SSSE3::key_schedule(const byte keyb[], size_t)
__m128i rcon = _mm_set_epi32(0x702A9808, 0x4D7C7D81,
0x1F8391B9, 0xAF9DEEB6);
- __m128i key = _mm_loadu_si128((const __m128i*)keyb);
+ __m128i key = _mm_loadu_si128(reinterpret_cast<const __m128i*>(keyb));
- __m128i* EK_mm = (__m128i*)&EK[0];
- __m128i* DK_mm = (__m128i*)&DK[0];
+ __m128i* EK_mm = reinterpret_cast<__m128i*>(&EK[0]);
+ __m128i* DK_mm = reinterpret_cast<__m128i*>(&DK[0]);
_mm_storeu_si128(DK_mm + 10, _mm_shuffle_epi8(key, sr[2]));
@@ -408,10 +408,10 @@ void AES_128_SSSE3::key_schedule(const byte keyb[], size_t)
*/
void AES_192_SSSE3::encrypt_n(const byte in[], byte out[], size_t blocks) const
{
- const __m128i* in_mm = (const __m128i*)in;
- __m128i* out_mm = (__m128i*)out;
+ const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
+ __m128i* out_mm = reinterpret_cast<__m128i*>(out);
- const __m128i* keys = (const __m128i*)&EK[0];
+ const __m128i* keys = reinterpret_cast<const __m128i*>(&EK[0]);
for(size_t i = 0; i != blocks; ++i)
{
@@ -425,10 +425,10 @@ void AES_192_SSSE3::encrypt_n(const byte in[], byte out[], size_t blocks) const
*/
void AES_192_SSSE3::decrypt_n(const byte in[], byte out[], size_t blocks) const
{
- const __m128i* in_mm = (const __m128i*)in;
- __m128i* out_mm = (__m128i*)out;
+ const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
+ __m128i* out_mm = reinterpret_cast<__m128i*>(out);
- const __m128i* keys = (const __m128i*)&DK[0];
+ const __m128i* keys = reinterpret_cast<const __m128i*>(&DK[0]);
for(size_t i = 0; i != blocks; ++i)
{
@@ -445,11 +445,11 @@ void AES_192_SSSE3::key_schedule(const byte keyb[], size_t)
__m128i rcon = _mm_set_epi32(0x702A9808, 0x4D7C7D81,
0x1F8391B9, 0xAF9DEEB6);
- __m128i* EK_mm = (__m128i*)&EK[0];
- __m128i* DK_mm = (__m128i*)&DK[0];
+ __m128i* EK_mm = reinterpret_cast<__m128i*>(&EK[0]);
+ __m128i* DK_mm = reinterpret_cast<__m128i*>(&DK[0]);
- __m128i key1 = _mm_loadu_si128((const __m128i*)keyb);
- __m128i key2 = _mm_loadu_si128((const __m128i*)(keyb + 8));
+ __m128i key1 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(keyb));
+ __m128i key2 = _mm_loadu_si128(reinterpret_cast<const __m128i*>((keyb + 8)));
_mm_storeu_si128(DK_mm + 12, _mm_shuffle_epi8(key1, sr[0]));
@@ -507,10 +507,10 @@ void AES_192_SSSE3::key_schedule(const byte keyb[], size_t)
*/
void AES_256_SSSE3::encrypt_n(const byte in[], byte out[], size_t blocks) const
{
- const __m128i* in_mm = (const __m128i*)in;
- __m128i* out_mm = (__m128i*)out;
+ const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
+ __m128i* out_mm = reinterpret_cast<__m128i*>(out);
- const __m128i* keys = (const __m128i*)&EK[0];
+ const __m128i* keys = reinterpret_cast<const __m128i*>(&EK[0]);
for(size_t i = 0; i != blocks; ++i)
{
@@ -524,10 +524,10 @@ void AES_256_SSSE3::encrypt_n(const byte in[], byte out[], size_t blocks) const
*/
void AES_256_SSSE3::decrypt_n(const byte in[], byte out[], size_t blocks) const
{
- const __m128i* in_mm = (const __m128i*)in;
- __m128i* out_mm = (__m128i*)out;
+ const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
+ __m128i* out_mm = reinterpret_cast<__m128i*>(out);
- const __m128i* keys = (const __m128i*)&DK[0];
+ const __m128i* keys = reinterpret_cast<const __m128i*>(&DK[0]);
for(size_t i = 0; i != blocks; ++i)
{
@@ -544,11 +544,11 @@ void AES_256_SSSE3::key_schedule(const byte keyb[], size_t)
__m128i rcon = _mm_set_epi32(0x702A9808, 0x4D7C7D81,
0x1F8391B9, 0xAF9DEEB6);
- __m128i* EK_mm = (__m128i*)&EK[0];
- __m128i* DK_mm = (__m128i*)&DK[0];
+ __m128i* EK_mm = reinterpret_cast<__m128i*>(&EK[0]);
+ __m128i* DK_mm = reinterpret_cast<__m128i*>(&DK[0]);
- __m128i key1 = _mm_loadu_si128((const __m128i*)keyb);
- __m128i key2 = _mm_loadu_si128((const __m128i*)(keyb + 16));
+ __m128i key1 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(keyb));
+ __m128i key2 = _mm_loadu_si128(reinterpret_cast<const __m128i*>((keyb + 16)));
_mm_storeu_si128(DK_mm + 14, _mm_shuffle_epi8(key1, sr[2]));
diff --git a/src/block/idea_sse2/idea_sse2.cpp b/src/block/idea_sse2/idea_sse2.cpp
index f2c770103..b92f51ac3 100644
--- a/src/block/idea_sse2/idea_sse2.cpp
+++ b/src/block/idea_sse2/idea_sse2.cpp
@@ -131,10 +131,12 @@ void transpose_out(__m128i& B0, __m128i& B1, __m128i& B2, __m128i& B3)
*/
void idea_op_8(const byte in[64], byte out[64], const u16bit EK[52])
{
- __m128i B0 = _mm_loadu_si128((const __m128i*)in);
- __m128i B1 = _mm_loadu_si128((const __m128i*)in + 1);
- __m128i B2 = _mm_loadu_si128((const __m128i*)in + 2);
- __m128i B3 = _mm_loadu_si128((const __m128i*)in + 3);
+ const __m128i* in_mm = reinterpret_cast<const __m128i*>(in);
+
+ __m128i B0 = _mm_loadu_si128(in_mm + 0);
+ __m128i B1 = _mm_loadu_si128(in_mm + 1);
+ __m128i B2 = _mm_loadu_si128(in_mm + 2);
+ __m128i B3 = _mm_loadu_si128(in_mm + 3);
transpose_in(B0, B1, B2, B3);
@@ -183,10 +185,12 @@ void idea_op_8(const byte in[64], byte out[64], const u16bit EK[52])
transpose_out(B0, B2, B1, B3);
- _mm_storeu_si128((__m128i*)out, B0);
- _mm_storeu_si128((__m128i*)out + 1, B2);
- _mm_storeu_si128((__m128i*)out + 2, B1);
- _mm_storeu_si128((__m128i*)out + 3, B3);
+ __m128i* out_mm = reinterpret_cast<__m128i*>(out);
+
+ _mm_storeu_si128(out_mm + 0, B0);
+ _mm_storeu_si128(out_mm + 1, B2);
+ _mm_storeu_si128(out_mm + 2, B1);
+ _mm_storeu_si128(out_mm + 3, B3);
}
}
diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt
index 01fae60d1..4751a6a28 100644
--- a/src/build-data/cc/gcc.txt
+++ b/src/build-data/cc/gcc.txt
@@ -13,7 +13,7 @@ add_lib_option -l
lang_flags "-D_REENTRANT -Wno-long-long"
warning_flags "-W -Wall"
-maintainer_warning_flags "-Werror -Wall -Wextra -Wstrict-aliasing -Wstrict-overflow=5 -Wcast-align -Wmissing-declarations -Wpointer-arith -Wcast-qual"
+maintainer_warning_flags "-Werror -Wall -Wextra -Wstrict-aliasing -Wstrict-overflow=5 -Wcast-align -Wmissing-declarations -Wpointer-arith -Wcast-qual -Wold-style-cast"
lib_opt_flags "-O3"
check_opt_flags "-O2"
diff --git a/src/cms/cms_algo.cpp b/src/cms/cms_algo.cpp
index 50384d85a..3c245cc6f 100644
--- a/src/cms/cms_algo.cpp
+++ b/src/cms/cms_algo.cpp
@@ -99,7 +99,7 @@ SecureVector<byte> CMS_Encoder::wrap_key(RandomNumberGenerator& rng,
throw Encoding_Error("CMS: 128-bit KEKs must be used with " + cipher);
SecureVector<byte> lcekpad;
- lcekpad.push_back((byte)cek.length());
+ lcekpad.push_back(static_cast<byte>(cek.length()));
lcekpad += cek.bits_of();
while(lcekpad.size() % 8)
lcekpad.push_back(rng.next_byte());
diff --git a/src/cms/cms_dec.cpp b/src/cms/cms_dec.cpp
index c86e1d0ae..a9f4e69d9 100644
--- a/src/cms/cms_dec.cpp
+++ b/src/cms/cms_dec.cpp
@@ -86,7 +86,9 @@ std::string CMS_Decoder::get_data() const
{
if(layer_type() != DATA)
throw Invalid_State("CMS: Cannot retrieve data from non-DATA layer");
- return std::string((const char*)&data[0], data.size());
+
+ return std::string(reinterpret_cast<const char*>(&data[0]),
+ data.size());
}
/*
diff --git a/src/cms/cms_enc.cpp b/src/cms/cms_enc.cpp
index cd739ef08..1a45a6a46 100644
--- a/src/cms/cms_enc.cpp
+++ b/src/cms/cms_enc.cpp
@@ -30,7 +30,7 @@ void CMS_Encoder::set_data(const byte buf[], size_t length)
*/
void CMS_Encoder::set_data(const std::string& str)
{
- set_data((const byte*)str.c_str(), str.length());
+ set_data(reinterpret_cast<const byte*>(str.c_str()), str.length());
}
/*
diff --git a/src/codec/hex/hex.cpp b/src/codec/hex/hex.cpp
index 596e0e235..49d6e7190 100644
--- a/src/codec/hex/hex.cpp
+++ b/src/codec/hex/hex.cpp
@@ -101,7 +101,7 @@ size_t hex_decode(byte output[],
for(size_t i = 0; i != input_length; ++i)
{
- const byte bin = HEX_TO_BIN[(byte)input[i]];
+ const byte bin = HEX_TO_BIN[static_cast<byte>(input[i])];
if(bin >= 0x10)
{
diff --git a/src/constructs/fpe/fpe.cpp b/src/constructs/fpe/fpe.cpp
index 1023b067c..5491af133 100644
--- a/src/constructs/fpe/fpe.cpp
+++ b/src/constructs/fpe/fpe.cpp
@@ -105,10 +105,10 @@ FPE_Encryptor::FPE_Encryptor(const SymmetricKey& key,
if(n_bin.size() > MAX_N_BYTES)
throw std::runtime_error("N is too large for FPE encryption");
- mac->update_be((u32bit)n_bin.size());
+ mac->update_be(static_cast<u32bit>(n_bin.size()));
mac->update(&n_bin[0], n_bin.size());
- mac->update_be((u32bit)tweak.size());
+ mac->update_be(static_cast<u32bit>(tweak.size()));
mac->update(&tweak[0], tweak.size());
mac_n_t = mac->final();
@@ -119,9 +119,9 @@ BigInt FPE_Encryptor::operator()(size_t round_no, const BigInt& R)
SecureVector<byte> r_bin = BigInt::encode(R);
mac->update(mac_n_t);
- mac->update_be((u32bit)round_no);
+ mac->update_be(static_cast<u32bit>(round_no));
- mac->update_be((u32bit)r_bin.size());
+ mac->update_be(static_cast<u32bit>(r_bin.size()));
mac->update(&r_bin[0], r_bin.size());
SecureVector<byte> X = mac->final();
diff --git a/src/hash/sha2_32/sha2_32.cpp b/src/hash/sha2_32/sha2_32.cpp
index 475ec8aee..6dd780e64 100644
--- a/src/hash/sha2_32/sha2_32.cpp
+++ b/src/hash/sha2_32/sha2_32.cpp
@@ -12,6 +12,8 @@
namespace Botan {
+namespace {
+
namespace SHA2_32 {
/*
@@ -154,6 +156,8 @@ void compress(MemoryRegion<u32bit>& digest,
}
+}
+
/*
* SHA-224 compression function
*/
diff --git a/src/hash/sha2_64/sha2_64.cpp b/src/hash/sha2_64/sha2_64.cpp
index b58e042d3..3026c3a39 100644
--- a/src/hash/sha2_64/sha2_64.cpp
+++ b/src/hash/sha2_64/sha2_64.cpp
@@ -11,6 +11,8 @@
namespace Botan {
+namespace {
+
namespace SHA2_64 {
/*
@@ -169,6 +171,8 @@ void compress(MemoryRegion<u64bit>& digest,
}
+}
+
/*
* SHA-384 compression function
*/
diff --git a/src/hash/skein/skein_512.cpp b/src/hash/skein/skein_512.cpp
index 3ed3e32a7..f85968e84 100644
--- a/src/hash/skein/skein_512.cpp
+++ b/src/hash/skein/skein_512.cpp
@@ -43,7 +43,7 @@ void ubi_512(MemoryRegion<u64bit>& H,
if(to_proc % 8)
{
for(size_t j = 0; j != to_proc % 8; ++j)
- M[to_proc/8] |= ((u64bit)msg[8*(to_proc/8)+j] << (8*j));
+ M[to_proc/8] |= static_cast<u64bit>(msg[8*(to_proc/8)+j]) << (8*j);
}
H[8] = H[0] ^ H[1] ^ H[2] ^ H[3] ^
@@ -117,7 +117,8 @@ void ubi_512(MemoryRegion<u64bit>& H,
H[6] = X6 ^ M[6];
H[7] = X7 ^ M[7];
- T[1] &= ~((u64bit)1 << 62); // clear first flag if set
+ // clear first flag if set
+ T[1] &= ~(static_cast<u64bit>(1) << 62);
msg_len -= to_proc;
msg += to_proc;
@@ -128,7 +129,10 @@ void reset_tweak(MemoryRegion<u64bit>& T,
type_code type, bool final)
{
T[0] = 0;
- T[1] = ((u64bit)type << 56) | ((u64bit)1 << 62) | ((u64bit)final << 63);
+
+ T[1] = (static_cast<u64bit>(type) << 56) |
+ (static_cast<u64bit>(1) << 62) |
+ (static_cast<u64bit>(final) << 63);
}
void initial_block(MemoryRegion<u64bit>& H,
@@ -227,7 +231,7 @@ void Skein_512::add_data(const byte input[], size_t length)
void Skein_512::final_result(byte out[])
{
- T[1] |= ((u64bit)1 << 63); // final block flag
+ T[1] |= (static_cast<u64bit>(1) << 63); // final block flag
for(size_t i = buf_pos; i != buffer.size(); ++i)
buffer[i] = 0;
diff --git a/src/ssl/hello.cpp b/src/ssl/hello.cpp
index bec316bb1..2c5a9d2ea 100644
--- a/src/ssl/hello.cpp
+++ b/src/ssl/hello.cpp
@@ -177,8 +177,9 @@ void Client_Hello::deserialize(const MemoryRegion<byte>& buf)
std::vector<byte> name =
reader.get_range_vector<byte>(2, 1, 65535);
- requested_hostname.assign((const char*)&name[0],
- name.size());
+ requested_hostname.assign(
+ reinterpret_cast<const char*>(&name[0]),
+ name.size());
name_bytes -= (2 + name.size());
}
diff --git a/src/utils/cpuid.cpp b/src/utils/cpuid.cpp
index ce3822d55..468ae9d3d 100644
--- a/src/utils/cpuid.cpp
+++ b/src/utils/cpuid.cpp
@@ -162,7 +162,7 @@ void CPUID::initialize()
u32bit cpuid[4] = { 0 };
CALL_CPUID(1, cpuid);
- x86_processor_flags = ((u64bit)cpuid[2] << 32) | cpuid[3];
+ x86_processor_flags = (static_cast<u64bit>(cpuid[2]) << 32) | cpuid[3];
#if defined(BOTAN_TARGET_ARCH_IS_AMD64)
/*
diff --git a/src/utils/mlock.cpp b/src/utils/mlock.cpp
index cd92860df..800425665 100644
--- a/src/utils/mlock.cpp
+++ b/src/utils/mlock.cpp
@@ -31,7 +31,7 @@ bool has_mlock()
bool lock_mem(void* ptr, size_t bytes)
{
#if defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK)
- return (::mlock((char*)ptr, bytes) == 0);
+ return (::mlock(static_cast<char*>(ptr), bytes) == 0);
#elif defined(BOTAN_TARGET_OS_HAS_WIN32_VIRTUAL_LOCK)
return (::VirtualLock(ptr, bytes) != 0);
#else
@@ -45,7 +45,7 @@ bool lock_mem(void* ptr, size_t bytes)
void unlock_mem(void* ptr, size_t bytes)
{
#if defined(BOTAN_TARGET_OS_HAS_POSIX_MLOCK)
- ::munlock((char*)ptr, bytes);
+ ::munlock(static_cast<char*>(ptr), bytes);
#elif defined(BOTAN_TARGET_OS_HAS_WIN32_VIRTUAL_LOCK)
::VirtualUnlock(ptr, bytes);
#endif
diff --git a/src/utils/simd_32/simd_sse.h b/src/utils/simd_32/simd_sse.h
index 1cb52105c..61fce99a9 100644
--- a/src/utils/simd_32/simd_sse.h
+++ b/src/utils/simd_32/simd_sse.h
@@ -22,7 +22,7 @@ class SIMD_SSE2
SIMD_SSE2(const u32bit B[4])
{
- reg = _mm_loadu_si128((const __m128i*)B);
+ reg = _mm_loadu_si128(reinterpret_cast<const __m128i*>(B));
}
SIMD_SSE2(u32bit B0, u32bit B1, u32bit B2, u32bit B3)
@@ -37,7 +37,7 @@ class SIMD_SSE2
static SIMD_SSE2 load_le(const void* in)
{
- return _mm_loadu_si128((const __m128i*)in);
+ return _mm_loadu_si128(reinterpret_cast<const __m128i*>(in));
}
static SIMD_SSE2 load_be(const void* in)
@@ -47,7 +47,7 @@ class SIMD_SSE2
void store_le(byte out[]) const
{
- _mm_storeu_si128((__m128i*)out, reg);
+ _mm_storeu_si128(reinterpret_cast<__m128i*>(out), reg);
}
void store_be(byte out[]) const