From 42c3d8f3aa593c224174558fd6f3d2709e08f7d0 Mon Sep 17 00:00:00 2001 From: weidai Date: Wed, 16 Jul 2003 01:53:45 +0000 Subject: added support for using encoding parameters and key derivation parameters git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@98 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- cryptlib.cpp | 96 ++++++++++++++++++++++++------------------------------------ 1 file changed, 39 insertions(+), 57 deletions(-) (limited to 'cryptlib.cpp') diff --git a/cryptlib.cpp b/cryptlib.cpp index 1412ab9..f3b3fde 100644 --- a/cryptlib.cpp +++ b/cryptlib.cpp @@ -10,6 +10,7 @@ #include "algparam.h" #include "fips140.h" #include "argnames.h" +#include "fltrimpl.h" #include @@ -224,14 +225,6 @@ unsigned int BufferedTransformation::ChannelPutModifiable2(const std::string &ch return ChannelPut2(channel, begin, length, messageEnd, blocking); } -void BufferedTransformation::ChannelInitialize(const std::string &channel, const NameValuePairs ¶meters, int propagation) -{ - if (channel.empty()) - Initialize(parameters, propagation); - else - throw NoChannelSupport(); -} - bool BufferedTransformation::ChannelFlush(const std::string &channel, bool completeFlush, int propagation, bool blocking) { if (channel.empty()) @@ -527,100 +520,89 @@ void GeneratableCryptoMaterial::GenerateRandomWithKeySize(RandomNumberGenerator GenerateRandom(rng, MakeParameters("KeySize", (int)keySize)); } -BufferedTransformation * PK_Encryptor::CreateEncryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment) const +BufferedTransformation * PK_Encryptor::CreateEncryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment, const NameValuePairs ¶meters) const { - struct EncryptionFilter : public Unflushable + struct EncryptionFilter : public Unflushable { - // VC60 complains if this function is missing - EncryptionFilter(const EncryptionFilter &x) : Unflushable(NULL), m_rng(x.m_rng), m_encryptor(x.m_encryptor) {} - - EncryptionFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment) - : Unflushable(attachment), m_rng(rng), m_encryptor(encryptor) + EncryptionFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment, const NameValuePairs ¶meters) + : Unflushable(attachment), m_rng(rng), m_encryptor(encryptor), m_parameters(parameters) { } - bool IsolatedMessageEnd(bool blocking) + unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking) { - switch (m_continueAt) + FILTER_BEGIN; + m_plaintextQueue.Put(inString, length); + + if (messageEnd) { - case 0: { - unsigned int plaintextLength = m_inQueue.CurrentSize(); - m_ciphertextLength = m_encryptor.CiphertextLength(plaintextLength); + unsigned int plaintextLength = m_plaintextQueue.CurrentSize(); + unsigned int ciphertextLength = m_encryptor.CiphertextLength(plaintextLength); SecByteBlock plaintext(plaintextLength); - m_inQueue.Get(plaintext, plaintextLength); - m_ciphertext.resize(m_ciphertextLength); - m_encryptor.Encrypt(m_rng, plaintext, plaintextLength, m_ciphertext); + m_plaintextQueue.Get(plaintext, plaintextLength); + m_ciphertext.resize(ciphertextLength); + m_encryptor.Encrypt(m_rng, plaintext, plaintextLength, m_ciphertext, m_parameters); } - - case 1: - if (!Output(1, m_ciphertext, m_ciphertextLength, 0, blocking)) - return false; - }; - return true; + + FILTER_OUTPUT(1, m_ciphertext, m_ciphertext.size(), messageEnd); + } + FILTER_END_NO_MESSAGE_END; } RandomNumberGenerator &m_rng; const PK_Encryptor &m_encryptor; - unsigned int m_ciphertextLength; + const NameValuePairs &m_parameters; + ByteQueue m_plaintextQueue; SecByteBlock m_ciphertext; }; - return new EncryptionFilter(rng, *this, attachment); + return new EncryptionFilter(rng, *this, attachment, parameters); } -BufferedTransformation * PK_Decryptor::CreateDecryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment) const +BufferedTransformation * PK_Decryptor::CreateDecryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment, const NameValuePairs ¶meters) const { - struct DecryptionFilter : public Unflushable + struct DecryptionFilter : public Unflushable { - // VC60 complains if this function is missing - DecryptionFilter(const DecryptionFilter &x) : Unflushable(NULL), m_rng(x.m_rng), m_decryptor(x.m_decryptor) {} - - DecryptionFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment) - : Unflushable(attachment), m_rng(rng), m_decryptor(decryptor) + DecryptionFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment, const NameValuePairs ¶meters) + : Unflushable(attachment), m_rng(rng), m_decryptor(decryptor), m_parameters(parameters) { } - bool IsolatedMessageEnd(bool blocking) + unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking) { - switch (m_continueAt) + FILTER_BEGIN; + m_ciphertextQueue.Put(inString, length); + + if (messageEnd) { - case 0: { - unsigned int ciphertextLength = m_inQueue.CurrentSize(); + unsigned int ciphertextLength = m_ciphertextQueue.CurrentSize(); unsigned int maxPlaintextLength = m_decryptor.MaxPlaintextLength(ciphertextLength); SecByteBlock ciphertext(ciphertextLength); - m_inQueue.Get(ciphertext, ciphertextLength); + m_ciphertextQueue.Get(ciphertext, ciphertextLength); m_plaintext.resize(maxPlaintextLength); - m_result = m_decryptor.Decrypt(m_rng, ciphertext, ciphertextLength, m_plaintext); + m_result = m_decryptor.Decrypt(m_rng, ciphertext, ciphertextLength, m_plaintext, m_parameters); if (!m_result.isValidCoding) throw InvalidCiphertext(m_decryptor.AlgorithmName() + ": invalid ciphertext"); } - case 1: - if (!Output(1, m_plaintext, m_result.messageLength, 0, blocking)) - return false; + FILTER_OUTPUT(1, m_plaintext, m_result.messageLength, messageEnd); } - return true; + FILTER_END_NO_MESSAGE_END; } RandomNumberGenerator &m_rng; const PK_Decryptor &m_decryptor; + const NameValuePairs &m_parameters; + ByteQueue m_ciphertextQueue; SecByteBlock m_plaintext; DecodingResult m_result; }; - return new DecryptionFilter(rng, *this, attachment); -} - -DecodingResult PK_FixedLengthDecryptor::Decrypt(RandomNumberGenerator &rng, const byte *cipherText, unsigned int cipherTextLength, byte *plainText) const -{ - if (cipherTextLength != FixedCiphertextLength()) - return DecodingResult(); - - return FixedLengthDecrypt(rng, cipherText, plainText); + return new DecryptionFilter(rng, *this, attachment, parameters); } unsigned int PK_Signer::Sign(RandomNumberGenerator &rng, PK_MessageAccumulator *messageAccumulator, byte *signature) const -- cgit v1.2.1