diff --git a/algparam.h b/algparam.h index 4870f59e..23a5f43f 100644 --- a/algparam.h +++ b/algparam.h @@ -28,7 +28,7 @@ public: ConstByteArrayParameter(const char *data = NULLPTR, bool deepCopy = false) : m_deepCopy(false), m_data(NULLPTR), m_size(0) { - Assign((const byte *)data, data ? strlen(data) : 0, deepCopy); + Assign(reinterpret_cast(data), data ? strlen(data) : 0, deepCopy); } /// \brief Construct a ConstByteArrayParameter @@ -53,7 +53,7 @@ public: : m_deepCopy(false), m_data(NULLPTR), m_size(0) { CRYPTOPP_COMPILE_ASSERT(sizeof(typename T::value_type) == 1); - Assign((const byte *)string.data(), string.size(), deepCopy); + Assign(reinterpret_cast(string.data()), string.size(), deepCopy); } /// \brief Assign contents from a memory buffer diff --git a/crc.h b/crc.h index f34715f6..505f88ca 100644 --- a/crc.h +++ b/crc.h @@ -34,7 +34,7 @@ public: std::string AlgorithmName() const {return StaticAlgorithmName();} void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);} - byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];} + byte GetCrcByte(size_t i) const {return reinterpret_cast(&m_crc)[i];} protected: void Reset() {m_crc = CRC32_NEGL;} @@ -59,7 +59,7 @@ public: std::string AlgorithmName() const {return StaticAlgorithmName();} void UpdateByte(byte b) {m_crc = m_tab[CRC32_INDEX(m_crc) ^ b] ^ CRC32_SHIFTED(m_crc);} - byte GetCrcByte(size_t i) const {return ((byte *)&(m_crc))[i];} + byte GetCrcByte(size_t i) const {return reinterpret_cast(&m_crc)[i];} protected: void Reset() {m_crc = CRC32_NEGL;} diff --git a/cryptlib.h b/cryptlib.h index 5f0be975..6445906a 100644 --- a/cryptlib.h +++ b/cryptlib.h @@ -131,7 +131,7 @@ const unsigned long INFINITE_TIME = ULONG_MAX; template struct EnumToType { - static ENUM_TYPE ToEnum() {return (ENUM_TYPE)VALUE;} + static ENUM_TYPE ToEnum() {return static_cast(VALUE);} }; /// \brief Provides the byte ordering diff --git a/filters.h b/filters.h index c9a4c092..9d39d4d9 100644 --- a/filters.h +++ b/filters.h @@ -865,12 +865,12 @@ public: /// \brief Stop redirecting input void StopRedirection() {m_target = NULLPTR;} - Behavior GetBehavior() {return (Behavior) m_behavior;} + Behavior GetBehavior() {return static_cast(m_behavior);} void SetBehavior(Behavior behavior) {m_behavior=behavior;} bool GetPassSignals() const {return (m_behavior & PASS_SIGNALS) != 0;} - void SetPassSignals(bool pass) { if (pass) m_behavior |= PASS_SIGNALS; else m_behavior &= ~(word32) PASS_SIGNALS; } + void SetPassSignals(bool pass) { if (pass) m_behavior |= PASS_SIGNALS; else m_behavior &= ~static_cast(PASS_SIGNALS); } bool GetPassWaitObjects() const {return (m_behavior & PASS_WAIT_OBJECTS) != 0;} - void SetPassWaitObjects(bool pass) { if (pass) m_behavior |= PASS_WAIT_OBJECTS; else m_behavior &= ~(word32) PASS_WAIT_OBJECTS; } + void SetPassWaitObjects(bool pass) { if (pass) m_behavior |= PASS_WAIT_OBJECTS; else m_behavior &= ~static_cast(PASS_WAIT_OBJECTS); } bool CanModifyInput() const {return m_target ? m_target->CanModifyInput() : false;} @@ -1293,7 +1293,7 @@ public: /// \details Internally, Pump() calls Pump2(). /// \note pumpMax is a \p lword, which is a 64-bit value that typically uses \p LWORD_MAX. The default /// argument is a \p size_t that uses \p SIZE_MAX, and it can be 32-bits or 64-bits. - lword Pump(lword pumpMax=(size_t)SIZE_MAX) + lword Pump(lword pumpMax=SIZE_MAX) {Pump2(pumpMax); return pumpMax;} /// \brief Pump messages to attached transformation diff --git a/iterhash.h b/iterhash.h index dae50d43..9526d4a7 100644 --- a/iterhash.h +++ b/iterhash.h @@ -168,7 +168,7 @@ public: /// \brief Provides the digest size of the hash /// \return the digest size of the hash, in bytes /// \details DigestSize() returns DIGESTSIZE. - unsigned int DigestSize() const {return DIGESTSIZE;}; + unsigned int DigestSize() const {return DIGESTSIZE;} protected: IteratedHashWithStaticTransform() {this->Init();} diff --git a/misc.h b/misc.h index 70351ae6..59b2646b 100644 --- a/misc.h +++ b/misc.h @@ -729,7 +729,7 @@ inline unsigned int TrailingZeros(word32 v) #elif defined(_MSC_VER) && (_MSC_VER >= 1400) unsigned long result; _BitScanForward(&result, v); - return (unsigned int)result; + return static_cast(result); #else // from http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup static const int MultiplyDeBruijnBitPosition[32] = @@ -760,7 +760,7 @@ inline unsigned int TrailingZeros(word64 v) #elif defined(_MSC_VER) && (_MSC_VER >= 1400) && (defined(_M_X64) || defined(_M_IA64)) unsigned long result; _BitScanForward64(&result, v); - return (unsigned int)result; + return static_cast(result); #else return word32(v) ? TrailingZeros(word32(v)) : 32 + TrailingZeros(word32(v>>32)); #endif @@ -1029,7 +1029,7 @@ inline unsigned int GetAlignmentOf() /// If not, then the function effectively performs a modular reduction and returns true if the residue is 0 inline bool IsAlignedOn(const void *ptr, unsigned int alignment) { - return alignment==1 || (IsPowerOf2(alignment) ? ModPowerOf2((size_t)ptr, alignment) == 0 : (size_t)ptr % alignment == 0); + return alignment==1 || (IsPowerOf2(alignment) ? ModPowerOf2(reinterpret_cast(ptr), alignment) == 0 : reinterpret_cast(ptr) % alignment == 0); } /// \brief Determines whether ptr is minimally aligned @@ -1184,7 +1184,7 @@ template<> inline void SecureWipeBuffer(byte *buf, size_t n) #ifdef __GNUC__ asm volatile("rep stosb" : "+c"(n), "+D"(p) : "a"(0) : "memory"); #else - __stosb((byte *)(size_t)p, 0, n); + __stosb(reinterpret_cast(reinterpret_cast(p)), 0, n); #endif } @@ -1198,7 +1198,7 @@ template<> inline void SecureWipeBuffer(word16 *buf, size_t n) #ifdef __GNUC__ asm volatile("rep stosw" : "+c"(n), "+D"(p) : "a"(0) : "memory"); #else - __stosw((word16 *)(size_t)p, 0, n); + __stosw(reinterpret_cast(reinterpret_cast(p)), 0, n); #endif } @@ -1212,7 +1212,7 @@ template<> inline void SecureWipeBuffer(word32 *buf, size_t n) #ifdef __GNUC__ asm volatile("rep stosl" : "+c"(n), "+D"(p) : "a"(0) : "memory"); #else - __stosd((unsigned long *)(size_t)p, 0, n); + __stosd(reinterpret_cast(reinterpret_cast(p)), 0, n); #endif } @@ -1227,10 +1227,10 @@ template<> inline void SecureWipeBuffer(word64 *buf, size_t n) #ifdef __GNUC__ asm volatile("rep stosq" : "+c"(n), "+D"(p) : "a"(0) : "memory"); #else - __stosq((word64 *)(size_t)p, 0, n); + __stosq(reinterpret_cast(reinterpret_cast(p)), 0, n); #endif #else - SecureWipeBuffer((word32 *)buf, 2*n); + SecureWipeBuffer(reinterpret_cast(buf), 2*n); #endif } @@ -1275,13 +1275,13 @@ template inline void SecureWipeArray(T *buf, size_t n) { if (sizeof(T) % 8 == 0 && GetAlignmentOf() % GetAlignmentOf() == 0) - SecureWipeBuffer((word64 *)(void *)buf, n * (sizeof(T)/8)); + SecureWipeBuffer(reinterpret_cast(static_cast(buf)), n * (sizeof(T)/8)); else if (sizeof(T) % 4 == 0 && GetAlignmentOf() % GetAlignmentOf() == 0) - SecureWipeBuffer((word32 *)(void *)buf, n * (sizeof(T)/4)); + SecureWipeBuffer(reinterpret_cast(static_cast(buf)), n * (sizeof(T)/4)); else if (sizeof(T) % 2 == 0 && GetAlignmentOf() % GetAlignmentOf() == 0) - SecureWipeBuffer((word16 *)(void *)buf, n * (sizeof(T)/2)); + SecureWipeBuffer(reinterpret_cast(static_cast(buf)), n * (sizeof(T)/2)); else - SecureWipeBuffer((byte *)(void *)buf, n * sizeof(T)); + SecureWipeBuffer(reinterpret_cast(static_cast(buf)), n * sizeof(T)); } /// \brief Converts a wide character C-string to a multibyte string @@ -2104,7 +2104,7 @@ inline word64 UnalignedGetWordNonTemplate(ByteOrder order, const byte *block, co inline void UnalignedbyteNonTemplate(ByteOrder order, byte *block, byte value, const byte *xorBlock) { CRYPTOPP_UNUSED(order); - block[0] = (byte)(xorBlock ? (value ^ xorBlock[0]) : value); + block[0] = static_cast(xorBlock ? (value ^ xorBlock[0]) : value); } inline void UnalignedbyteNonTemplate(ByteOrder order, byte *block, word16 value, const byte *xorBlock) diff --git a/modarith.h b/modarith.h index 740e581c..a00582eb 100644 --- a/modarith.h +++ b/modarith.h @@ -47,12 +47,12 @@ public: /// \brief Construct a ModularArithmetic /// \param modulus congruence class modulus ModularArithmetic(const Integer &modulus = Integer::One()) - : AbstractRing(), m_modulus(modulus), m_result((word)0, modulus.reg.size()) {} + : AbstractRing(), m_modulus(modulus), m_result(static_cast(0), modulus.reg.size()) {} /// \brief Copy construct a ModularArithmetic /// \param ma other ModularArithmetic ModularArithmetic(const ModularArithmetic &ma) - : AbstractRing(), m_modulus(ma.m_modulus), m_result((word)0, ma.m_modulus.reg.size()) {} + : AbstractRing(), m_modulus(ma.m_modulus), m_result(static_cast(0), ma.m_modulus.reg.size()) {} /// \brief Construct a ModularArithmetic /// \param bt BER encoded ModularArithmetic diff --git a/modes.h b/modes.h index b199ef6d..ca1c90f8 100644 --- a/modes.h +++ b/modes.h @@ -80,7 +80,7 @@ public: protected: CipherModeBase() : m_cipher(NULLPTR) {} - inline unsigned int BlockSize() const {CRYPTOPP_ASSERT(m_register.size() > 0); return (unsigned int)m_register.size();} + inline unsigned int BlockSize() const {CRYPTOPP_ASSERT(m_register.size() > 0); return static_cast(m_register.size());} virtual void SetFeedbackSize(unsigned int feedbackSize) { if (!(feedbackSize == 0 || feedbackSize == BlockSize())) @@ -251,7 +251,7 @@ protected: void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) { CBC_Encryption::UncheckedSetKey(key, length, params); - m_stolenIV = params.GetValueWithDefault(Name::StolenIV(), (byte *)NULLPTR); + m_stolenIV = params.GetValueWithDefault(Name::StolenIV(), static_cast(NULLPTR)); } byte *m_stolenIV; diff --git a/secblock.h b/secblock.h index 842f0298..d7cafb2d 100644 --- a/secblock.h +++ b/secblock.h @@ -198,10 +198,10 @@ public: #if CRYPTOPP_BOOL_ALIGN16 // TODO: Does this need the test 'size*sizeof(T) >= 16'? if (T_Align16 && size) - return (pointer)AlignedAllocate(size*sizeof(T)); + return reinterpret_cast(AlignedAllocate(size*sizeof(T))); #endif - return (pointer)UnalignedAllocate(size*sizeof(T)); + return reinterpret_cast(UnalignedAllocate(size*sizeof(T))); } /// \brief Deallocates a block of memory @@ -217,7 +217,7 @@ public: // This will fire if SetMark(0) was called in the SecBlock // Our self tests exercise it, disable it now. // CRYPTOPP_ASSERT((ptr && size) || !(ptr || size)); - SecureWipeArray((pointer)ptr, size); + SecureWipeArray(reinterpret_cast(ptr), size); #if CRYPTOPP_BOOL_ALIGN16 if (T_Align16 && size) diff --git a/strciphr.h b/strciphr.h index 3697ddf3..ea9ab6a5 100644 --- a/strciphr.h +++ b/strciphr.h @@ -130,7 +130,7 @@ struct CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AdditiveCipherAbstractPolicy /// \param iterationCount the number of iterations to generate the key stream /// \sa CanOperateKeystream(), OperateKeystream(), WriteKeystream() virtual void WriteKeystream(byte *keystream, size_t iterationCount) - {OperateKeystream(KeystreamOperation(INPUT_NULL | (KeystreamOperationFlags)IsAlignedOn(keystream, GetAlignment())), keystream, NULLPTR, iterationCount);} + {OperateKeystream(KeystreamOperation(INPUT_NULL | static_cast(IsAlignedOn(keystream, GetAlignment()))), keystream, NULLPTR, iterationCount);} /// \brief Flag indicating /// \returns true if the stream can be generated independent of the transformation input, false otherwise diff --git a/trap.h b/trap.h index f30ba293..a34be810 100644 --- a/trap.h +++ b/trap.h @@ -64,8 +64,8 @@ # define CRYPTOPP_ASSERT(exp) { \ if (!(exp)) { \ std::ostringstream oss; \ - oss << "Assertion failed: " << (char*)(__FILE__) << "(" \ - << (int)(__LINE__) << "): " << (char*)(__func__) \ + oss << "Assertion failed: " << __FILE__ << "(" \ + << __LINE__ << "): " << __func__ \ << std::endl; \ std::cerr << oss.str(); \ raise(SIGTRAP); \ @@ -75,8 +75,8 @@ # define CRYPTOPP_ASSERT(exp) { \ if (!(exp)) { \ std::ostringstream oss; \ - oss << "Assertion failed: " << (char*)(__FILE__) << "(" \ - << (int)(__LINE__) << "): " << (char*)(__FUNCTION__) \ + oss << "Assertion failed: " << __FILE__ << "(" \ + << __LINE__ << "): " << __FUNCTION__ \ << std::endl; \ std::cerr << oss.str(); \ if (IsDebuggerPresent()) {DebugBreak();} \