aboutsummaryrefslogtreecommitdiffstats
path: root/src/cms
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-11 21:59:30 +0000
committerlloyd <[email protected]>2008-11-11 21:59:30 +0000
commitd4ec4e06936d2a993a81ab33c46201352f77b387 (patch)
treef0af295a0978b068cb2f9381372ecaa6073b49a5 /src/cms
parent8b5b9aa24741622c2010f6a03238891025058382 (diff)
Remove last uses of lookup.h in CMS code
Diffstat (limited to 'src/cms')
-rw-r--r--src/cms/cms_algo.cpp21
-rw-r--r--src/cms/cms_ealg.cpp28
2 files changed, 31 insertions, 18 deletions
diff --git a/src/cms/cms_algo.cpp b/src/cms/cms_algo.cpp
index b065676a8..8db27c65f 100644
--- a/src/cms/cms_algo.cpp
+++ b/src/cms/cms_algo.cpp
@@ -5,8 +5,10 @@
#include <botan/cms_enc.h>
#include <botan/der_enc.h>
-#include <botan/lookup.h>
+#include <botan/sha160.h>
+#include <botan/cbc.h>
#include <botan/filters.h>
+#include <botan/libstate.h>
#if defined(BOTAN_HAS_RC2)
#include <botan/rc2.h>
@@ -20,7 +22,7 @@ namespace {
* Wrap a key as specified in RFC 3217 *
*************************************************/
SecureVector<byte> do_rfc3217_wrap(RandomNumberGenerator& rng,
- const std::string& cipher,
+ const std::string& cipher_name,
const SymmetricKey& kek,
const SecureVector<byte>& input)
{
@@ -42,18 +44,23 @@ SecureVector<byte> do_rfc3217_wrap(RandomNumberGenerator& rng,
SecureVector<byte> buf;
};
- if(block_size_of(cipher) != 8)
- throw Encoding_Error("do_rfc3217_wrap: Bad cipher: " + cipher);
+ Algorithm_Factory& af = global_state().algorithm_factory();
- Pipe icv(new Hash_Filter("SHA-160", 8));
+ const BlockCipher* cipher = af.prototype_block_cipher(cipher_name);
+
+ if(!cipher || cipher->BLOCK_SIZE != 8)
+ throw Encoding_Error("do_rfc3217_wrap: Bad cipher: " + cipher_name);
+
+ Pipe icv(new Hash_Filter(new SHA_160, 8));
icv.process_msg(input);
InitializationVector iv(rng, 8);
InitializationVector fixed("4ADDA22C79E82105");
- Pipe pipe(get_cipher(cipher + "/CBC/NoPadding", kek, iv, ENCRYPTION),
+ Pipe pipe(new CBC_Encryption(cipher->clone(), new Null_Padding, kek, iv),
new Flip_Bytes(iv.bits_of()),
- get_cipher(cipher + "/CBC/NoPadding", kek, fixed, ENCRYPTION));
+ new CBC_Encryption(cipher->clone(), new Null_Padding, kek, iv));
+
pipe.start_msg();
pipe.write(input);
pipe.write(icv.read_all());
diff --git a/src/cms/cms_ealg.cpp b/src/cms/cms_ealg.cpp
index 36641753b..85b933197 100644
--- a/src/cms/cms_ealg.cpp
+++ b/src/cms/cms_ealg.cpp
@@ -8,7 +8,8 @@
#include <botan/x509find.h>
#include <botan/bigint.h>
#include <botan/oids.h>
-#include <botan/lookup.h>
+#include <botan/cbc.h>
+#include <botan/hash.h>
#include <botan/look_pk.h>
#include <botan/libstate.h>
#include <botan/pipe.h>
@@ -248,21 +249,26 @@ void CMS_Encoder::encrypt(RandomNumberGenerator&,
*************************************************/
SecureVector<byte> CMS_Encoder::do_encrypt(RandomNumberGenerator& rng,
const SymmetricKey& key,
- const std::string& cipher)
+ const std::string& cipher_name)
{
- if(!have_block_cipher(cipher))
- throw Invalid_Argument("CMS: Can't encrypt with non-existent cipher " +
- cipher);
- if(!OIDS::have_oid(cipher + "/CBC"))
- throw Encoding_Error("CMS: No OID assigned for " + cipher + "/CBC");
+ Algorithm_Factory& af = global_state().algorithm_factory();
+
+ const BlockCipher* cipher = af.prototype_block_cipher(cipher_name);
+
+ if(!cipher)
+ throw Invalid_Argument("CMS: Can't encrypt with non-existent cipher " + cipher_name);
- InitializationVector iv(rng, block_size_of(cipher));
+ if(!OIDS::have_oid(cipher->name() + "/CBC"))
+ throw Encoding_Error("CMS: No OID assigned for " + cipher_name + "/CBC");
+
+ InitializationVector iv(rng, cipher->BLOCK_SIZE);
AlgorithmIdentifier content_cipher;
- content_cipher.oid = OIDS::lookup(cipher + "/CBC");
- content_cipher.parameters = encode_params(cipher, key, iv);
+ content_cipher.oid = OIDS::lookup(cipher->name() + "/CBC");
+ content_cipher.parameters = encode_params(cipher->name(), key, iv);
+
+ Pipe pipe(new CBC_Encryption(cipher->clone(), new PKCS7_Padding, key, iv));
- Pipe pipe(get_cipher(cipher + "/CBC/PKCS7", key, iv, ENCRYPTION));
pipe.process_msg(data);
DER_Encoder encoder;