From bf3b80f25c6adedc05c876ad2e64589d8c9791ee Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 24 Jan 2016 23:09:28 -0500 Subject: [PATCH] Cleared -Wcast-align (Issue 122) --- randpool.cpp | 10 +++++----- randpool.h | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/randpool.cpp b/randpool.cpp index a9480cca..2eafb5bb 100644 --- a/randpool.cpp +++ b/randpool.cpp @@ -39,18 +39,18 @@ void RandomPool::GenerateIntoBufferedTransformation(BufferedTransformation &targ if (!m_keySet) m_pCipher->SetKey(m_key, 32); + CRYPTOPP_COMPILE_ASSERT(sizeof(TimerWord) <= 16); + CRYPTOPP_COMPILE_ASSERT(sizeof(time_t) <= 8); + Timer timer; TimerWord tw = timer.GetCurrentTimerValue(); - CRYPTOPP_COMPILE_ASSERT(sizeof(tw) <= 16); - *(TimerWord *)m_seed.data() += tw; + *(TimerWord *)(void*)m_seed.data() += tw; time_t t = time(NULL); - CRYPTOPP_COMPILE_ASSERT(sizeof(t) <= 8); // UBsan finding: signed integer overflow: 1876017710 + 1446085457 cannot be represented in type 'long int' // *(time_t *)(m_seed.data()+8) += t; - assert(m_seed.size() >= 16); - word64 tt1, tt2 = (word64)t; + word64 tt1 = 0, tt2 = (word64)t; memcpy(&tt1, m_seed.data()+8, 8); memcpy(m_seed.data()+8, &(tt2 += tt1), 8); diff --git a/randpool.h b/randpool.h index 9393ff92..79fa63f1 100644 --- a/randpool.h +++ b/randpool.h @@ -1,3 +1,8 @@ +// randpool.h - written and placed in the public domain by Wei Dai + +//! \file randpool.h +//! \brief Class file for Randomness Pool + #ifndef CRYPTOPP_RANDPOOL_H #define CRYPTOPP_RANDPOOL_H @@ -9,12 +14,18 @@ NAMESPACE_BEGIN(CryptoPP) -//! Randomness Pool -/*! This class can be used to generate cryptographic quality - pseudorandom bytes after seeding the pool with IncorporateEntropy() */ +//! \brief Randomness Pool +//! \details RandomPool can be used to generate cryptographic quality pseudorandom bytes +//! after seeding the pool with IncorporateEntropy(). Internally, the generator uses +//! AES-256 to produce the stream. Entropy is stirred in using SHA-256. +//! \details RandomPool used to follow the design of randpool in PGP 2.6.x, +//! but as of version 5.5 it has been redesigned to reduce the risk +//! of reusing random numbers after state rollback (which may occur +//! when running in a virtual machine like VMware). class CRYPTOPP_DLL RandomPool : public RandomNumberGenerator, public NotCopyable { public: + //! \brief Construct a RandomPool RandomPool(); bool CanIncorporateEntropy() const {return true;} @@ -25,8 +36,8 @@ public: void Put(const byte *input, size_t length) {IncorporateEntropy(input, length);} private: + FixedSizeAlignedSecBlock m_seed; FixedSizeAlignedSecBlock m_key; - FixedSizeAlignedSecBlock m_seed; member_ptr m_pCipher; bool m_keySet; };