summaryrefslogtreecommitdiff
path: root/cryptlib.cpp
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-07-18 21:33:18 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2003-07-18 21:33:18 +0000
commit2c43c8505f12d744cd8d93c1ef692962bd8da849 (patch)
treec178635daa826ac0a4bd557eb59aa4f853dfb957 /cryptlib.cpp
parenta89df27c0f7ded0a673dc84ce0b0e24c6d05e0d0 (diff)
downloadcryptopp-2c43c8505f12d744cd8d93c1ef692962bd8da849.tar.gz
allow DLL to be built with VC++ .NET
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@104 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'cryptlib.cpp')
-rw-r--r--cryptlib.cpp130
1 files changed, 67 insertions, 63 deletions
diff --git a/cryptlib.cpp b/cryptlib.cpp
index cc1e3ce..cafaaa7 100644
--- a/cryptlib.cpp
+++ b/cryptlib.cpp
@@ -520,89 +520,93 @@ void GeneratableCryptoMaterial::GenerateRandomWithKeySize(RandomNumberGenerator
GenerateRandom(rng, MakeParameters("KeySize", (int)keySize));
}
-BufferedTransformation * PK_Encryptor::CreateEncryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment, const NameValuePairs &parameters) const
+class PK_DefaultEncryptionFilter : public Unflushable<Filter>
{
- struct EncryptionFilter : public Unflushable<Filter>
+public:
+ PK_DefaultEncryptionFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment, const NameValuePairs &parameters)
+ : m_rng(rng), m_encryptor(encryptor), m_parameters(parameters)
{
- EncryptionFilter(RandomNumberGenerator &rng, const PK_Encryptor &encryptor, BufferedTransformation *attachment, const NameValuePairs &parameters)
- : Unflushable<Filter>(attachment), m_rng(rng), m_encryptor(encryptor), m_parameters(parameters)
- {
- }
+ Detach(attachment);
+ }
- unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking)
- {
- FILTER_BEGIN;
- m_plaintextQueue.Put(inString, length);
+ unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking)
+ {
+ FILTER_BEGIN;
+ m_plaintextQueue.Put(inString, length);
- if (messageEnd)
+ if (messageEnd)
+ {
{
- {
- unsigned int plaintextLength = m_plaintextQueue.CurrentSize();
- unsigned int ciphertextLength = m_encryptor.CiphertextLength(plaintextLength);
-
- SecByteBlock plaintext(plaintextLength);
- m_plaintextQueue.Get(plaintext, plaintextLength);
- m_ciphertext.resize(ciphertextLength);
- m_encryptor.Encrypt(m_rng, plaintext, plaintextLength, m_ciphertext, m_parameters);
- }
-
- FILTER_OUTPUT(1, m_ciphertext, m_ciphertext.size(), messageEnd);
+ unsigned int plaintextLength = m_plaintextQueue.CurrentSize();
+ unsigned int ciphertextLength = m_encryptor.CiphertextLength(plaintextLength);
+
+ SecByteBlock plaintext(plaintextLength);
+ m_plaintextQueue.Get(plaintext, plaintextLength);
+ m_ciphertext.resize(ciphertextLength);
+ m_encryptor.Encrypt(m_rng, plaintext, plaintextLength, m_ciphertext, m_parameters);
}
- FILTER_END_NO_MESSAGE_END;
+
+ FILTER_OUTPUT(1, m_ciphertext, m_ciphertext.size(), messageEnd);
}
+ FILTER_END_NO_MESSAGE_END;
+ }
- RandomNumberGenerator &m_rng;
- const PK_Encryptor &m_encryptor;
- const NameValuePairs &m_parameters;
- ByteQueue m_plaintextQueue;
- SecByteBlock m_ciphertext;
- };
+ RandomNumberGenerator &m_rng;
+ const PK_Encryptor &m_encryptor;
+ const NameValuePairs &m_parameters;
+ ByteQueue m_plaintextQueue;
+ SecByteBlock m_ciphertext;
+};
- return new EncryptionFilter(rng, *this, attachment, parameters);
+BufferedTransformation * PK_Encryptor::CreateEncryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment, const NameValuePairs &parameters) const
+{
+ return new PK_DefaultEncryptionFilter(rng, *this, attachment, parameters);
}
-BufferedTransformation * PK_Decryptor::CreateDecryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment, const NameValuePairs &parameters) const
+class PK_DefaultDecryptionFilter : public Unflushable<Filter>
{
- struct DecryptionFilter : public Unflushable<Filter>
+public:
+ PK_DefaultDecryptionFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment, const NameValuePairs &parameters)
+ : m_rng(rng), m_decryptor(decryptor), m_parameters(parameters)
{
- DecryptionFilter(RandomNumberGenerator &rng, const PK_Decryptor &decryptor, BufferedTransformation *attachment, const NameValuePairs &parameters)
- : Unflushable<Filter>(attachment), m_rng(rng), m_decryptor(decryptor), m_parameters(parameters)
- {
- }
+ Detach(attachment);
+ }
- unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking)
- {
- FILTER_BEGIN;
- m_ciphertextQueue.Put(inString, length);
+ unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking)
+ {
+ FILTER_BEGIN;
+ m_ciphertextQueue.Put(inString, length);
- if (messageEnd)
+ if (messageEnd)
+ {
{
- {
- unsigned int ciphertextLength = m_ciphertextQueue.CurrentSize();
- unsigned int maxPlaintextLength = m_decryptor.MaxPlaintextLength(ciphertextLength);
-
- SecByteBlock ciphertext(ciphertextLength);
- m_ciphertextQueue.Get(ciphertext, ciphertextLength);
- m_plaintext.resize(maxPlaintextLength);
- m_result = m_decryptor.Decrypt(m_rng, ciphertext, ciphertextLength, m_plaintext, m_parameters);
- if (!m_result.isValidCoding)
- throw InvalidCiphertext(m_decryptor.AlgorithmName() + ": invalid ciphertext");
- }
-
- FILTER_OUTPUT(1, m_plaintext, m_result.messageLength, messageEnd);
+ unsigned int ciphertextLength = m_ciphertextQueue.CurrentSize();
+ unsigned int maxPlaintextLength = m_decryptor.MaxPlaintextLength(ciphertextLength);
+
+ SecByteBlock ciphertext(ciphertextLength);
+ m_ciphertextQueue.Get(ciphertext, ciphertextLength);
+ m_plaintext.resize(maxPlaintextLength);
+ m_result = m_decryptor.Decrypt(m_rng, ciphertext, ciphertextLength, m_plaintext, m_parameters);
+ if (!m_result.isValidCoding)
+ throw InvalidCiphertext(m_decryptor.AlgorithmName() + ": invalid ciphertext");
}
- FILTER_END_NO_MESSAGE_END;
+
+ FILTER_OUTPUT(1, m_plaintext, m_result.messageLength, messageEnd);
}
+ 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;
- };
+ 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, parameters);
+BufferedTransformation * PK_Decryptor::CreateDecryptionFilter(RandomNumberGenerator &rng, BufferedTransformation *attachment, const NameValuePairs &parameters) const
+{
+ return new PK_DefaultDecryptionFilter(rng, *this, attachment, parameters);
}
unsigned int PK_Signer::Sign(RandomNumberGenerator &rng, PK_MessageAccumulator *messageAccumulator, byte *signature) const