From fcda95a60737ea15d9ba389af83e5cfc92a8017f Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 13 Jan 2005 22:14:14 +0000 Subject: [PATCH] remove unused stuff --- stepmania/src/crypto51/filters.cpp | 266 +--------------------------- stepmania/src/crypto51/filters.h | 105 ----------- stepmania/src/crypto51/modes.cpp | 54 ------ stepmania/src/crypto51/modes.h | 8 - stepmania/src/crypto51/osrng.h | 72 -------- stepmania/src/crypto51/pkcspad.cpp | 21 --- stepmania/src/crypto51/pkcspad.h | 7 - stepmania/src/crypto51/randpool.cpp | 3 +- stepmania/src/crypto51/rsa.cpp | 10 +- stepmania/src/crypto51/rsa.h | 9 - stepmania/src/crypto51/sha.cpp | 194 -------------------- stepmania/src/crypto51/sha.h | 47 ----- 12 files changed, 11 insertions(+), 785 deletions(-) diff --git a/stepmania/src/crypto51/filters.cpp b/stepmania/src/crypto51/filters.cpp index 09d135be40..7139451610 100644 --- a/stepmania/src/crypto51/filters.cpp +++ b/stepmania/src/crypto51/filters.cpp @@ -226,8 +226,9 @@ FilterWithBufferedInput::FilterWithBufferedInput(unsigned int firstSize, unsigne : Filter(attachment), m_firstSize(firstSize), m_blockSize(blockSize), m_lastSize(lastSize) , m_firstInputDone(false) { - if (m_firstSize < 0 || m_blockSize < 1 || m_lastSize < 0) - throw InvalidArgument("FilterWithBufferedInput: invalid buffer size"); + ASSERT( m_firstSize >= 0 ); + ASSERT( m_blockSize >= 1 ); + ASSERT( m_lastSize >= 0 ); m_queue.ResetQueue(1, m_firstSize); } @@ -235,8 +236,9 @@ FilterWithBufferedInput::FilterWithBufferedInput(unsigned int firstSize, unsigne void FilterWithBufferedInput::IsolatedInitialize(const NameValuePairs ¶meters) { InitializeDerivedAndReturnNewSizes(parameters, m_firstSize, m_blockSize, m_lastSize); - if (m_firstSize < 0 || m_blockSize < 1 || m_lastSize < 0) - throw InvalidArgument("FilterWithBufferedInput: invalid buffer size"); + ASSERT( m_firstSize >= 0 ); + ASSERT( m_blockSize >= 1 ); + ASSERT( m_lastSize >= 0 ); m_queue.ResetQueue(1, m_firstSize); m_firstInputDone = false; } @@ -389,38 +391,6 @@ void Redirector::ChannelInitialize(const std::string &channel, const NameValuePa // ************************************************************* -ProxyFilter::ProxyFilter(BufferedTransformation *filter, unsigned int firstSize, unsigned int lastSize, BufferedTransformation *attachment) - : FilterWithBufferedInput(firstSize, 1, lastSize, attachment), m_filter(filter) -{ - if (m_filter.get()) - m_filter->Attach(new OutputProxy(*this, false)); -} - -bool ProxyFilter::IsolatedFlush(bool hardFlush, bool blocking) -{ - return m_filter.get() ? m_filter->Flush(hardFlush, -1, blocking) : false; -} - -void ProxyFilter::SetFilter(Filter *filter) -{ - m_filter.reset(filter); - if (filter) - { - OutputProxy *proxy; - std::auto_ptr temp(proxy = new OutputProxy(*this, false)); - m_filter->TransferAllTo(*proxy); - m_filter->Attach(temp.release()); - } -} - -void ProxyFilter::NextPutMultiple(const byte *s, unsigned int len) -{ - if (m_filter.get()) - m_filter->Put(s, len); -} - -// ************************************************************* - unsigned int ArraySink::Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking) { memcpy(m_buf+m_total, begin, STDMIN(length, SaturatingSubtract(m_size, m_total))); @@ -453,171 +423,6 @@ unsigned int ArrayXorSink::Put2(const byte *begin, unsigned int length, int mess // ************************************************************* -unsigned int StreamTransformationFilter::LastBlockSize(StreamTransformation &c, BlockPaddingScheme padding) -{ - if (c.MinLastBlockSize() > 0) - return c.MinLastBlockSize(); - else if (c.MandatoryBlockSize() > 1 && !c.IsForwardTransformation() && padding != NO_PADDING && padding != ZEROS_PADDING) - return c.MandatoryBlockSize(); - else - return 0; -} - -StreamTransformationFilter::StreamTransformationFilter(StreamTransformation &c, BufferedTransformation *attachment, BlockPaddingScheme padding) - : FilterWithBufferedInput(0, c.MandatoryBlockSize(), LastBlockSize(c, padding), attachment) - , m_cipher(c) -{ - assert(c.MinLastBlockSize() == 0 || c.MinLastBlockSize() > c.MandatoryBlockSize()); - - bool isBlockCipher = (c.MandatoryBlockSize() > 1 && c.MinLastBlockSize() == 0); - - if (padding == DEFAULT_PADDING) - { - if (isBlockCipher) - m_padding = PKCS_PADDING; - else - m_padding = NO_PADDING; - } - else - m_padding = padding; - - if (!isBlockCipher && (m_padding == PKCS_PADDING || m_padding == ONE_AND_ZEROS_PADDING)) - throw InvalidArgument("StreamTransformationFilter: PKCS_PADDING and ONE_AND_ZEROS_PADDING cannot be used with " + c.AlgorithmName()); -} - -void StreamTransformationFilter::FirstPut(const byte *inString) -{ - m_optimalBufferSize = m_cipher.OptimalBlockSize(); - m_optimalBufferSize = STDMAX(m_optimalBufferSize, RoundDownToMultipleOf(4096U, m_optimalBufferSize)); -} - -void StreamTransformationFilter::NextPutMultiple(const byte *inString, unsigned int length) -{ - if (!length) - return; - - unsigned int s = m_cipher.MandatoryBlockSize(); - - do - { - unsigned int len = m_optimalBufferSize; - byte *space = HelpCreatePutSpace(*AttachedTransformation(), NULL_CHANNEL, s, length, len); - if (len < length) - { - if (len == m_optimalBufferSize) - len -= m_cipher.GetOptimalBlockSizeUsed(); - len = RoundDownToMultipleOf(len, s); - } - else - len = length; - m_cipher.ProcessString(space, inString, len); - AttachedTransformation()->PutModifiable(space, len); - inString += len; - length -= len; - } - while (length > 0); -} - -void StreamTransformationFilter::NextPutModifiable(byte *inString, unsigned int length) -{ - m_cipher.ProcessString(inString, length); - AttachedTransformation()->PutModifiable(inString, length); -} - -void StreamTransformationFilter::LastPut(const byte *inString, unsigned int length) -{ - byte *space = NULL; - - switch (m_padding) - { - case NO_PADDING: - case ZEROS_PADDING: - if (length > 0) - { - unsigned int minLastBlockSize = m_cipher.MinLastBlockSize(); - bool isForwardTransformation = m_cipher.IsForwardTransformation(); - - if (isForwardTransformation && m_padding == ZEROS_PADDING && (minLastBlockSize == 0 || length < minLastBlockSize)) - { - // do padding - unsigned int blockSize = STDMAX(minLastBlockSize, m_cipher.MandatoryBlockSize()); - space = HelpCreatePutSpace(*AttachedTransformation(), NULL_CHANNEL, blockSize); - memcpy(space, inString, length); - memset(space + length, 0, blockSize - length); - m_cipher.ProcessLastBlock(space, space, blockSize); - AttachedTransformation()->Put(space, blockSize); - } - else - { - if (minLastBlockSize == 0) - { - if (isForwardTransformation) - throw InvalidDataFormat("StreamTransformationFilter: plaintext length is not a multiple of block size and NO_PADDING is specified"); - else - throw InvalidCiphertext("StreamTransformationFilter: ciphertext length is not a multiple of block size"); - } - - space = HelpCreatePutSpace(*AttachedTransformation(), NULL_CHANNEL, length, m_optimalBufferSize); - m_cipher.ProcessLastBlock(space, inString, length); - AttachedTransformation()->Put(space, length); - } - } - break; - - case PKCS_PADDING: - case ONE_AND_ZEROS_PADDING: - unsigned int s; - s = m_cipher.MandatoryBlockSize(); - assert(s > 1); - space = HelpCreatePutSpace(*AttachedTransformation(), NULL_CHANNEL, s, m_optimalBufferSize); - if (m_cipher.IsForwardTransformation()) - { - assert(length < s); - memcpy(space, inString, length); - if (m_padding == PKCS_PADDING) - { - assert(s < 256); - byte pad = s-length; - memset(space+length, pad, s-length); - } - else - { - space[length] = 1; - memset(space+length+1, 0, s-length-1); - } - m_cipher.ProcessData(space, space, s); - AttachedTransformation()->Put(space, s); - } - else - { - if (length != s) - throw InvalidCiphertext("StreamTransformationFilter: ciphertext length is not a multiple of block size"); - m_cipher.ProcessData(space, inString, s); - if (m_padding == PKCS_PADDING) - { - byte pad = space[s-1]; - if (pad < 1 || pad > s || std::find_if(space+s-pad, space+s, std::bind2nd(std::not_equal_to(), pad)) != space+s) - throw InvalidCiphertext("StreamTransformationFilter: invalid PKCS #7 block padding found"); - length = s-pad; - } - else - { - while (length > 1 && space[length-1] == '\0') - --length; - if (space[--length] != '\1') - throw InvalidCiphertext("StreamTransformationFilter: invalid ones-and-zeros padding found"); - } - AttachedTransformation()->Put(space, length); - } - break; - - default: - assert(false); - } -} - -// ************************************************************* - void HashFilter::IsolatedInitialize(const NameValuePairs ¶meters) { m_putMessage = parameters.GetValueWithDefault(Name::PutMessage(), false); @@ -644,65 +449,6 @@ unsigned int HashFilter::Put2(const byte *inString, unsigned int length, int mes // ************************************************************* -HashVerificationFilter::HashVerificationFilter(HashTransformation &hm, BufferedTransformation *attachment, word32 flags) - : FilterWithBufferedInput(attachment) - , m_hashModule(hm) -{ - IsolatedInitialize(MakeParameters(Name::HashVerificationFilterFlags(), flags)); -} - -void HashVerificationFilter::InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, unsigned int &firstSize, unsigned int &blockSize, unsigned int &lastSize) -{ - m_flags = parameters.GetValueWithDefault(Name::HashVerificationFilterFlags(), (word32)DEFAULT_FLAGS); - m_hashModule.Restart(); - unsigned int size = m_hashModule.DigestSize(); - m_verified = false; - firstSize = m_flags & HASH_AT_BEGIN ? size : 0; - blockSize = 1; - lastSize = m_flags & HASH_AT_BEGIN ? 0 : size; -} - -void HashVerificationFilter::FirstPut(const byte *inString) -{ - if (m_flags & HASH_AT_BEGIN) - { - m_expectedHash.New(m_hashModule.DigestSize()); - memcpy(m_expectedHash, inString, m_expectedHash.size()); - if (m_flags & PUT_HASH) - AttachedTransformation()->Put(inString, m_expectedHash.size()); - } -} - -void HashVerificationFilter::NextPutMultiple(const byte *inString, unsigned int length) -{ - m_hashModule.Update(inString, length); - if (m_flags & PUT_MESSAGE) - AttachedTransformation()->Put(inString, length); -} - -void HashVerificationFilter::LastPut(const byte *inString, unsigned int length) -{ - if (m_flags & HASH_AT_BEGIN) - { - assert(length == 0); - m_verified = m_hashModule.Verify(m_expectedHash); - } - else - { - m_verified = (length==m_hashModule.DigestSize() && m_hashModule.Verify(inString)); - if (m_flags & PUT_HASH) - AttachedTransformation()->Put(inString, length); - } - - if (m_flags & PUT_RESULT) - AttachedTransformation()->Put(m_verified); - - if ((m_flags & THROW_EXCEPTION) && !m_verified) - throw HashVerificationFailed(); -} - -// ************************************************************* - void SignerFilter::IsolatedInitialize(const NameValuePairs ¶meters) { m_putMessage = parameters.GetValueWithDefault(Name::PutMessage(), false); diff --git a/stepmania/src/crypto51/filters.h b/stepmania/src/crypto51/filters.h index b2ddec2a36..29c0e593dd 100644 --- a/stepmania/src/crypto51/filters.h +++ b/stepmania/src/crypto51/filters.h @@ -233,33 +233,6 @@ protected: ByteQueue m_inQueue; }; -//! Filter Wrapper for StreamTransformation -class StreamTransformationFilter : public FilterWithBufferedInput, private FilterPutSpaceHelper -{ -public: - enum BlockPaddingScheme {NO_PADDING, ZEROS_PADDING, PKCS_PADDING, ONE_AND_ZEROS_PADDING, DEFAULT_PADDING}; - /*! DEFAULT_PADDING means PKCS_PADDING if c.MandatoryBlockSize() > 1 && c.MinLastBlockSize() == 0 (e.g. ECB or CBC mode), - otherwise NO_PADDING (OFB, CFB, CTR, CBC-CTS modes) */ - StreamTransformationFilter(StreamTransformation &c, BufferedTransformation *attachment = NULL, BlockPaddingScheme padding = DEFAULT_PADDING); - - void FirstPut(const byte *inString); - void NextPutMultiple(const byte *inString, unsigned int length); - void NextPutModifiable(byte *inString, unsigned int length); - void LastPut(const byte *inString, unsigned int length); -// byte * CreatePutSpace(unsigned int &size); - -protected: - static unsigned int LastBlockSize(StreamTransformation &c, BlockPaddingScheme padding); - - StreamTransformation &m_cipher; - BlockPaddingScheme m_padding; - unsigned int m_optimalBufferSize; -}; - -#ifdef CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY -typedef StreamTransformationFilter StreamCipherFilter; -#endif - //! Filter Wrapper for HashTransformation class HashFilter : public Bufferless, private FilterPutSpaceHelper { @@ -278,40 +251,6 @@ private: byte *m_space; }; -//! Filter Wrapper for HashTransformation -class HashVerificationFilter : public FilterWithBufferedInput -{ -public: - class HashVerificationFailed : public Exception - { - public: - HashVerificationFailed() - : Exception(DATA_INTEGRITY_CHECK_FAILED, "HashVerifier: message hash not valid") {} - }; - - enum Flags {HASH_AT_BEGIN=1, PUT_MESSAGE=2, PUT_HASH=4, PUT_RESULT=8, THROW_EXCEPTION=16, DEFAULT_FLAGS = HASH_AT_BEGIN | PUT_RESULT}; - HashVerificationFilter(HashTransformation &hm, BufferedTransformation *attachment = NULL, word32 flags = DEFAULT_FLAGS); - - bool GetLastResult() const {return m_verified;} - -protected: - void InitializeDerivedAndReturnNewSizes(const NameValuePairs ¶meters, unsigned int &firstSize, unsigned int &blockSize, unsigned int &lastSize); - void FirstPut(const byte *inString); - void NextPutMultiple(const byte *inString, unsigned int length); - void LastPut(const byte *inString, unsigned int length); - -private: - static inline unsigned int FirstSize(word32 flags, HashTransformation &hm) {return flags & HASH_AT_BEGIN ? hm.DigestSize() : 0;} - static inline unsigned int LastSize(word32 flags, HashTransformation &hm) {return flags & HASH_AT_BEGIN ? 0 : hm.DigestSize();} - - HashTransformation &m_hashModule; - word32 m_flags; - SecByteBlock m_expectedHash; - bool m_verified; -}; - -typedef HashVerificationFilter HashVerifier; // for backwards compatibility - //! Filter Wrapper for PK_Signer class SignerFilter : public Unflushable { @@ -434,50 +373,6 @@ private: bool m_passSignal; }; -//! Base class for Filter classes that are proxies for a chain of other filters. -class ProxyFilter : public FilterWithBufferedInput -{ -public: - ProxyFilter(BufferedTransformation *filter, unsigned int firstSize, unsigned int lastSize, BufferedTransformation *attachment); - - bool IsolatedFlush(bool hardFlush, bool blocking); - - void SetFilter(Filter *filter); - void NextPutMultiple(const byte *s, unsigned int len); - -protected: - member_ptr m_filter; -}; - -//! simple proxy filter that doesn't modify the underlying filter's input or output -class SimpleProxyFilter : public ProxyFilter -{ -public: - SimpleProxyFilter(BufferedTransformation *filter, BufferedTransformation *attachment) - : ProxyFilter(filter, 0, 0, attachment) {} - - void FirstPut(const byte *) {} - void LastPut(const byte *, unsigned int) {m_filter->MessageEnd();} -}; - -//! proxy for the filter created by PK_Encryptor::CreateEncryptionFilter -/*! This class is here just to provide symmetry with VerifierFilter. */ -class PK_EncryptorFilter : public SimpleProxyFilter -{ -public: - PK_EncryptorFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment = NULL) - : SimpleProxyFilter(encryptor.CreateEncryptionFilter(rng), attachment) {} -}; - -//! proxy for the filter created by PK_Decryptor::CreateDecryptionFilter -/*! This class is here just to provide symmetry with SignerFilter. */ -class PK_DecryptorFilter : public SimpleProxyFilter -{ -public: - PK_DecryptorFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment = NULL) - : SimpleProxyFilter(decryptor.CreateDecryptionFilter(rng), attachment) {} -}; - //! Append input to a string object template class StringSinkTemplate : public Bufferless diff --git a/stepmania/src/crypto51/modes.cpp b/stepmania/src/crypto51/modes.cpp index 86f5650e29..0ff000f14a 100644 --- a/stepmania/src/crypto51/modes.cpp +++ b/stepmania/src/crypto51/modes.cpp @@ -102,58 +102,4 @@ void BlockOrientedCipherModeBase::ProcessData(byte *outString, const byte *inStr } } -void CBC_Encryption::ProcessBlocks(byte *outString, const byte *inString, unsigned int numberOfBlocks) -{ - unsigned int blockSize = BlockSize(); - while (numberOfBlocks--) - { - xorbuf(m_register, inString, blockSize); - m_cipher->ProcessBlock(m_register); - memcpy(outString, m_register, blockSize); - inString += blockSize; - outString += blockSize; - } -} - -void CBC_CTS_Encryption::ProcessLastBlock(byte *outString, const byte *inString, unsigned int length) -{ - if (length <= BlockSize()) - { - if (!m_stolenIV) - throw InvalidArgument("CBC_Encryption: message is too short for ciphertext stealing"); - - // steal from IV - memcpy(outString, m_register, length); - outString = m_stolenIV; - } - else - { - // steal from next to last block - xorbuf(m_register, inString, BlockSize()); - m_cipher->ProcessBlock(m_register); - inString += BlockSize(); - length -= BlockSize(); - memcpy(outString+BlockSize(), m_register, length); - } - - // output last full ciphertext block - xorbuf(m_register, inString, length); - m_cipher->ProcessBlock(m_register); - memcpy(outString, m_register, BlockSize()); -} - -void CBC_Decryption::ProcessBlocks(byte *outString, const byte *inString, unsigned int numberOfBlocks) -{ - unsigned int blockSize = BlockSize(); - while (numberOfBlocks--) - { - memcpy(m_temp, inString, blockSize); - m_cipher->ProcessBlock(m_temp, outString); - xorbuf(outString, m_register, blockSize); - m_register.swap(m_temp); - inString += blockSize; - outString += blockSize; - } -} - NAMESPACE_END diff --git a/stepmania/src/crypto51/modes.h b/stepmania/src/crypto51/modes.h index 5905de283d..3585c82178 100644 --- a/stepmania/src/crypto51/modes.h +++ b/stepmania/src/crypto51/modes.h @@ -211,14 +211,6 @@ struct CFB_Mode : public CipherModeDocumentation typedef CipherModeFinalTemplate_CipherHolder > > > Decryption; }; -//! CBC mode -template -struct CBC_Mode : public CipherModeDocumentation -{ - typedef CipherModeFinalTemplate_CipherHolder Encryption; - typedef CipherModeFinalTemplate_CipherHolder Decryption; -}; - NAMESPACE_END #endif diff --git a/stepmania/src/crypto51/osrng.h b/stepmania/src/crypto51/osrng.h index b6b1c39fef..9fcc21db67 100644 --- a/stepmania/src/crypto51/osrng.h +++ b/stepmania/src/crypto51/osrng.h @@ -90,78 +90,6 @@ public: void Reseed(bool blocking = false, unsigned int seedSize = 32); }; -//! RNG from ANSI X9.17 Appendix C, seeded using an OS provided RNG -template -class AutoSeededX917RNG : public RandomNumberGenerator -{ -public: - //! blocking will be ignored if the prefered RNG isn't available - explicit AutoSeededX917RNG(bool blocking = false) - {Reseed(blocking);} - void Reseed(bool blocking = false); - // exposed for testing - void Reseed(const byte *key, unsigned int keylength, const byte *seed, unsigned long timeVector); - - byte GenerateByte(); - -private: - member_ptr m_rng; - SecByteBlock m_lastBlock; - bool m_isDifferent; - unsigned int m_counter; -}; - -template -void AutoSeededX917RNG::Reseed(const byte *key, unsigned int keylength, const byte *seed, unsigned long timeVector) -{ - m_rng.reset(new X917RNG(new typename BLOCK_CIPHER::Encryption(key, keylength), seed, timeVector)); - - // for FIPS 140-2 - m_lastBlock.resize(16); - m_rng->GenerateBlock(m_lastBlock, m_lastBlock.size()); - m_counter = 0; - m_isDifferent = false; -} - -template -void AutoSeededX917RNG::Reseed(bool blocking) -{ - SecByteBlock seed(BLOCK_CIPHER::BLOCKSIZE + BLOCK_CIPHER::DEFAULT_KEYLENGTH); - const byte *key; - do - { - OS_GenerateRandomBlock(blocking, seed, seed.size()); - key = seed + BLOCK_CIPHER::BLOCKSIZE; - } // check that seed and key don't have same value - while (memcmp(key, seed, STDMIN((unsigned int)BLOCK_CIPHER::BLOCKSIZE, (unsigned int)BLOCK_CIPHER::DEFAULT_KEYLENGTH)) == 0); - - Reseed(key, BLOCK_CIPHER::DEFAULT_KEYLENGTH, seed, 0); -} - -template -byte AutoSeededX917RNG::GenerateByte() -{ - byte b = m_rng->GenerateByte(); - - // for FIPS 140-2 - m_isDifferent = m_isDifferent || b != m_lastBlock[m_counter]; - m_lastBlock[m_counter] = b; - ++m_counter; - if (m_counter == m_lastBlock.size()) - { - if (!m_isDifferent) - // This originally threw a SelfTestFailure, which is - // only available from fips140.h, which I figure - // probably was excluded for a good reason. Here's - // my workaround. - throw Exception(Exception::OTHER_ERROR, "AutoSeededX917RNG: Continuous random number generator test failed."); - m_counter = 0; - m_isDifferent = false; - } - - return b; -} - NAMESPACE_END #endif diff --git a/stepmania/src/crypto51/pkcspad.cpp b/stepmania/src/crypto51/pkcspad.cpp index e04ac9ddee..574baf9e69 100644 --- a/stepmania/src/crypto51/pkcspad.cpp +++ b/stepmania/src/crypto51/pkcspad.cpp @@ -9,27 +9,6 @@ NAMESPACE_BEGIN(CryptoPP) template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2B,0x0E,0x03,0x02,0x1A,0x05,0x00,0x04,0x14}; template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x20,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x02,0x05,0x00,0x04,0x10}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x20,0x30,0x0c,0x06,0x08,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x02,0x05,0x05,0x00,0x04,0x10}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x21,0x30,0x09,0x06,0x05,0x2b,0x24,0x03,0x02,0x01,0x05,0x00,0x04,0x14}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x29,0x30,0x0D,0x06,0x09,0x2B,0x06,0x01,0x04,0x01,0xDA,0x47,0x0C,0x02,0x05,0x00,0x04,0x18}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x31,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x01,0x05,0x00,0x04,0x20}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x41,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x02,0x05,0x00,0x04,0x30}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - -template<> const byte PKCS_DigestDecoration::decoration[] = {0x30,0x51,0x30,0x0d,0x06,0x09,0x60,0x86,0x48,0x01,0x65,0x03,0x04,0x02,0x03,0x05,0x00,0x04,0x40}; -template<> const unsigned int PKCS_DigestDecoration::length = sizeof(PKCS_DigestDecoration::decoration); - unsigned int PKCS_EncryptionPaddingScheme::MaxUnpaddedLength(unsigned int paddedLength) const { return SaturatingSubtract(paddedLength/8, 10U); diff --git a/stepmania/src/crypto51/pkcspad.h b/stepmania/src/crypto51/pkcspad.h index 2e14a5e00d..611aa07ab1 100644 --- a/stepmania/src/crypto51/pkcspad.h +++ b/stepmania/src/crypto51/pkcspad.h @@ -57,13 +57,6 @@ struct PKCS1v15 : public SignatureStandard, public EncryptionStandard // PKCS_DecoratedHashModule can be instantiated with the following // classes as specified in PKCS#1 v2.0 and P1363a class SHA; -class MD2; -class MD5; -class RIPEMD160; -class Tiger; -class SHA256; -class SHA384; -class SHA512; NAMESPACE_END diff --git a/stepmania/src/crypto51/randpool.cpp b/stepmania/src/crypto51/randpool.cpp index 9fa0b4beec..b22c401d75 100644 --- a/stepmania/src/crypto51/randpool.cpp +++ b/stepmania/src/crypto51/randpool.cpp @@ -61,8 +61,7 @@ unsigned int RandomPool::Put2(const byte *inString, unsigned int length, int mes unsigned int RandomPool::TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel, bool blocking) { - if (!blocking) - throw NotImplemented("RandomPool: nonblocking transfer is not implemented by this object"); + ASSERT( blocking ); unsigned int t; unsigned long size = transferBytes; diff --git a/stepmania/src/crypto51/rsa.cpp b/stepmania/src/crypto51/rsa.cpp index 1e4177e96e..8ca748c8d6 100644 --- a/stepmania/src/crypto51/rsa.cpp +++ b/stepmania/src/crypto51/rsa.cpp @@ -84,13 +84,12 @@ void InvertibleRSAFunction::GenerateRandom(RandomNumberGenerator &rng, const Nam int modulusSize = 2048; alg.GetIntValue("ModulusSize", modulusSize) || alg.GetIntValue("KeySize", modulusSize); - if (modulusSize < 16) - throw InvalidArgument("InvertibleRSAFunction: specified modulus size is too small"); + ASSERT( modulusSize >= 16 ); m_e = alg.GetValueWithDefault("PublicExponent", Integer(17)); - if (m_e < 3 || m_e.IsEven()) - throw InvalidArgument("InvertibleRSAFunction: invalid public exponent"); + ASSERT( m_e >= 3 ); + ASSERT( !m_e.IsEven() ); RSAPrimeSelector selector(m_e); const NameValuePairs &primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize) @@ -188,8 +187,7 @@ Integer InvertibleRSAFunction::CalculateInverse(RandomNumberGenerator &rng, cons // but in ModRoot, u=p inverse mod q, so we reverse the order of p and q Integer y = ModularRoot(re, m_dq, m_dp, m_q, m_p, m_u); y = modn.Divide(y, r); // unblind - if (modn.Exponentiate(y, m_e) != x) // check - throw Exception(Exception::OTHER_ERROR, "InvertibleRSAFunction: computational error during private key operation"); + ASSERT( modn.Exponentiate(y, m_e) == x ); // check return y; } diff --git a/stepmania/src/crypto51/rsa.h b/stepmania/src/crypto51/rsa.h index 7f82134088..2c1713b7ea 100644 --- a/stepmania/src/crypto51/rsa.h +++ b/stepmania/src/crypto51/rsa.h @@ -122,9 +122,6 @@ struct RSASS : public TF_SS }; // The two RSA encryption schemes defined in PKCS #1 v2.0 -typedef RSAES::Decryptor RSAES_PKCS1v15_Decryptor; -typedef RSAES::Encryptor RSAES_PKCS1v15_Encryptor; - typedef RSAES >::Decryptor RSAES_OAEP_SHA_Decryptor; typedef RSAES >::Encryptor RSAES_OAEP_SHA_Encryptor; @@ -132,12 +129,6 @@ typedef RSAES >::Encryptor RSAES_OAEP_SHA_Encryptor; typedef RSASS::Signer RSASSA_PKCS1v15_SHA_Signer; typedef RSASS::Verifier RSASSA_PKCS1v15_SHA_Verifier; -typedef RSASS::Signer RSASSA_PKCS1v15_MD2_Signer; -typedef RSASS::Verifier RSASSA_PKCS1v15_MD2_Verifier; - -typedef RSASS::Signer RSASSA_PKCS1v15_MD5_Signer; -typedef RSASS::Verifier RSASSA_PKCS1v15_MD5_Verifier; - NAMESPACE_END #endif diff --git a/stepmania/src/crypto51/sha.cpp b/stepmania/src/crypto51/sha.cpp index 958d9ea07b..2196f289e9 100644 --- a/stepmania/src/crypto51/sha.cpp +++ b/stepmania/src/crypto51/sha.cpp @@ -80,198 +80,4 @@ void SHA::Transform(word32 *state, const word32 *data) // ************************************************************* -void SHA256::Init() -{ - m_digest[0] = 0x6a09e667; - m_digest[1] = 0xbb67ae85; - m_digest[2] = 0x3c6ef372; - m_digest[3] = 0xa54ff53a; - m_digest[4] = 0x510e527f; - m_digest[5] = 0x9b05688c; - m_digest[6] = 0x1f83d9ab; - m_digest[7] = 0x5be0cd19; -} - -#define blk2(i) (W[i&15]+=s1(W[(i-2)&15])+W[(i-7)&15]+s0(W[(i-15)&15])) - -#define Ch(x,y,z) (z^(x&(y^z))) -#define Maj(x,y,z) ((x&y)|(z&(x|y))) - -#define a(i) T[(0-i)&7] -#define b(i) T[(1-i)&7] -#define c(i) T[(2-i)&7] -#define d(i) T[(3-i)&7] -#define e(i) T[(4-i)&7] -#define f(i) T[(5-i)&7] -#define g(i) T[(6-i)&7] -#define h(i) T[(7-i)&7] - -#define R(i) h(i)+=S1(e(i))+Ch(e(i),f(i),g(i))+K[i+j]+(j?blk2(i):blk0(i));\ - d(i)+=h(i);h(i)+=S0(a(i))+Maj(a(i),b(i),c(i)) - -// for SHA256 -#define S0(x) (rotrFixed(x,2)^rotrFixed(x,13)^rotrFixed(x,22)) -#define S1(x) (rotrFixed(x,6)^rotrFixed(x,11)^rotrFixed(x,25)) -#define s0(x) (rotrFixed(x,7)^rotrFixed(x,18)^(x>>3)) -#define s1(x) (rotrFixed(x,17)^rotrFixed(x,19)^(x>>10)) - -void SHA256::Transform(word32 *state, const word32 *data) -{ - word32 W[16]; - word32 T[8]; - /* Copy context->state[] to working vars */ - memcpy(T, state, sizeof(T)); - /* 64 operations, partially loop unrolled */ - for (unsigned int j=0; j<64; j+=16) - { - R( 0); R( 1); R( 2); R( 3); - R( 4); R( 5); R( 6); R( 7); - R( 8); R( 9); R(10); R(11); - R(12); R(13); R(14); R(15); - } - /* Add the working vars back into context.state[] */ - state[0] += a(0); - state[1] += b(0); - state[2] += c(0); - state[3] += d(0); - state[4] += e(0); - state[5] += f(0); - state[6] += g(0); - state[7] += h(0); - /* Wipe variables */ - memset(W, 0, sizeof(W)); - memset(T, 0, sizeof(T)); -} - -const word32 SHA256::K[64] = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -}; - -#undef S0 -#undef S1 -#undef s0 -#undef s1 - -// ************************************************************* - -#ifdef WORD64_AVAILABLE - -void SHA512::Init() -{ - m_digest[0] = W64LIT(0x6a09e667f3bcc908); - m_digest[1] = W64LIT(0xbb67ae8584caa73b); - m_digest[2] = W64LIT(0x3c6ef372fe94f82b); - m_digest[3] = W64LIT(0xa54ff53a5f1d36f1); - m_digest[4] = W64LIT(0x510e527fade682d1); - m_digest[5] = W64LIT(0x9b05688c2b3e6c1f); - m_digest[6] = W64LIT(0x1f83d9abfb41bd6b); - m_digest[7] = W64LIT(0x5be0cd19137e2179); -} - -// for SHA512 -#define S0(x) (rotrFixed(x,28)^rotrFixed(x,34)^rotrFixed(x,39)) -#define S1(x) (rotrFixed(x,14)^rotrFixed(x,18)^rotrFixed(x,41)) -#define s0(x) (rotrFixed(x,1)^rotrFixed(x,8)^(x>>7)) -#define s1(x) (rotrFixed(x,19)^rotrFixed(x,61)^(x>>6)) - -void SHA512::Transform(word64 *state, const word64 *data) -{ - word64 W[16]; - word64 T[8]; - /* Copy context->state[] to working vars */ - memcpy(T, state, sizeof(T)); - /* 80 operations, partially loop unrolled */ - for (unsigned int j=0; j<80; j+=16) - { - R( 0); R( 1); R( 2); R( 3); - R( 4); R( 5); R( 6); R( 7); - R( 8); R( 9); R(10); R(11); - R(12); R(13); R(14); R(15); - } - /* Add the working vars back into context.state[] */ - state[0] += a(0); - state[1] += b(0); - state[2] += c(0); - state[3] += d(0); - state[4] += e(0); - state[5] += f(0); - state[6] += g(0); - state[7] += h(0); - /* Wipe variables */ - memset(W, 0, sizeof(W)); - memset(T, 0, sizeof(T)); -} - -const word64 SHA512::K[80] = { - W64LIT(0x428a2f98d728ae22), W64LIT(0x7137449123ef65cd), - W64LIT(0xb5c0fbcfec4d3b2f), W64LIT(0xe9b5dba58189dbbc), - W64LIT(0x3956c25bf348b538), W64LIT(0x59f111f1b605d019), - W64LIT(0x923f82a4af194f9b), W64LIT(0xab1c5ed5da6d8118), - W64LIT(0xd807aa98a3030242), W64LIT(0x12835b0145706fbe), - W64LIT(0x243185be4ee4b28c), W64LIT(0x550c7dc3d5ffb4e2), - W64LIT(0x72be5d74f27b896f), W64LIT(0x80deb1fe3b1696b1), - W64LIT(0x9bdc06a725c71235), W64LIT(0xc19bf174cf692694), - W64LIT(0xe49b69c19ef14ad2), W64LIT(0xefbe4786384f25e3), - W64LIT(0x0fc19dc68b8cd5b5), W64LIT(0x240ca1cc77ac9c65), - W64LIT(0x2de92c6f592b0275), W64LIT(0x4a7484aa6ea6e483), - W64LIT(0x5cb0a9dcbd41fbd4), W64LIT(0x76f988da831153b5), - W64LIT(0x983e5152ee66dfab), W64LIT(0xa831c66d2db43210), - W64LIT(0xb00327c898fb213f), W64LIT(0xbf597fc7beef0ee4), - W64LIT(0xc6e00bf33da88fc2), W64LIT(0xd5a79147930aa725), - W64LIT(0x06ca6351e003826f), W64LIT(0x142929670a0e6e70), - W64LIT(0x27b70a8546d22ffc), W64LIT(0x2e1b21385c26c926), - W64LIT(0x4d2c6dfc5ac42aed), W64LIT(0x53380d139d95b3df), - W64LIT(0x650a73548baf63de), W64LIT(0x766a0abb3c77b2a8), - W64LIT(0x81c2c92e47edaee6), W64LIT(0x92722c851482353b), - W64LIT(0xa2bfe8a14cf10364), W64LIT(0xa81a664bbc423001), - W64LIT(0xc24b8b70d0f89791), W64LIT(0xc76c51a30654be30), - W64LIT(0xd192e819d6ef5218), W64LIT(0xd69906245565a910), - W64LIT(0xf40e35855771202a), W64LIT(0x106aa07032bbd1b8), - W64LIT(0x19a4c116b8d2d0c8), W64LIT(0x1e376c085141ab53), - W64LIT(0x2748774cdf8eeb99), W64LIT(0x34b0bcb5e19b48a8), - W64LIT(0x391c0cb3c5c95a63), W64LIT(0x4ed8aa4ae3418acb), - W64LIT(0x5b9cca4f7763e373), W64LIT(0x682e6ff3d6b2b8a3), - W64LIT(0x748f82ee5defb2fc), W64LIT(0x78a5636f43172f60), - W64LIT(0x84c87814a1f0ab72), W64LIT(0x8cc702081a6439ec), - W64LIT(0x90befffa23631e28), W64LIT(0xa4506cebde82bde9), - W64LIT(0xbef9a3f7b2c67915), W64LIT(0xc67178f2e372532b), - W64LIT(0xca273eceea26619c), W64LIT(0xd186b8c721c0c207), - W64LIT(0xeada7dd6cde0eb1e), W64LIT(0xf57d4f7fee6ed178), - W64LIT(0x06f067aa72176fba), W64LIT(0x0a637dc5a2c898a6), - W64LIT(0x113f9804bef90dae), W64LIT(0x1b710b35131c471b), - W64LIT(0x28db77f523047d84), W64LIT(0x32caab7b40c72493), - W64LIT(0x3c9ebe0a15c9bebc), W64LIT(0x431d67c49c100d4c), - W64LIT(0x4cc5d4becb3e42b6), W64LIT(0x597f299cfc657e2a), - W64LIT(0x5fcb6fab3ad6faec), W64LIT(0x6c44198c4a475817) -}; - -void SHA384::Init() -{ - m_digest[0] = W64LIT(0xcbbb9d5dc1059ed8); - m_digest[1] = W64LIT(0x629a292a367cd507); - m_digest[2] = W64LIT(0x9159015a3070dd17); - m_digest[3] = W64LIT(0x152fecd8f70e5939); - m_digest[4] = W64LIT(0x67332667ffc00b31); - m_digest[5] = W64LIT(0x8eb44a8768581511); - m_digest[6] = W64LIT(0xdb0c2e0d64f98fa7); - m_digest[7] = W64LIT(0x47b5481dbefa4fa4); -} - -#endif - NAMESPACE_END diff --git a/stepmania/src/crypto51/sha.h b/stepmania/src/crypto51/sha.h index 9c1cce5ae2..9f77ae7c63 100644 --- a/stepmania/src/crypto51/sha.h +++ b/stepmania/src/crypto51/sha.h @@ -20,53 +20,6 @@ protected: typedef SHA SHA1; -//! implements the SHA-256 standard -class SHA256 : public IteratedHashWithStaticTransform -{ -public: - enum {DIGESTSIZE = 32}; - SHA256() : IteratedHashWithStaticTransform(DIGESTSIZE) {Init();} - static void Transform(word32 *digest, const word32 *data); - static const char *StaticAlgorithmName() {return "SHA-256";} - -protected: - void Init(); - - static const word32 K[64]; -}; - -#ifdef WORD64_AVAILABLE - -//! implements the SHA-512 standard -class SHA512 : public IteratedHashWithStaticTransform -{ -public: - enum {DIGESTSIZE = 64}; - SHA512() : IteratedHashWithStaticTransform(DIGESTSIZE) {Init();} - static void Transform(word64 *digest, const word64 *data); - static const char *StaticAlgorithmName() {return "SHA-512";} - -protected: - void Init(); - - static const word64 K[80]; -}; - -//! implements the SHA-384 standard -class SHA384 : public IteratedHashWithStaticTransform -{ -public: - enum {DIGESTSIZE = 48}; - SHA384() : IteratedHashWithStaticTransform(64) {Init();} - unsigned int DigestSize() const {return DIGESTSIZE;}; - static const char *StaticAlgorithmName() {return "SHA-384";} - -protected: - void Init(); -}; - -#endif - NAMESPACE_END #endif