aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-04 01:53:35 +0000
committerlloyd <[email protected]>2010-03-04 01:53:35 +0000
commitf109029f5f1cc33512091e228e6ee6532058c42f (patch)
tree203d32fec16d05a2fc6c6f72346cb13a2796c71e
parent547e295717780c28878f17b7273a7d60c1bf39c6 (diff)
Add a new function to Public_Key, algorithm_identifier(), which just
returns the AlgorithmIdentifier representing this scheme (OID + domain params if any).
-rw-r--r--src/cert/x509/x509_ca.cpp8
-rw-r--r--src/pubkey/dl_algo/dl_algo.cpp16
-rw-r--r--src/pubkey/dl_algo/dl_algo.h2
-rw-r--r--src/pubkey/ecc_key/ecc_key.cpp11
-rw-r--r--src/pubkey/ecc_key/ecc_key.h2
-rw-r--r--src/pubkey/if_algo/if_algo.cpp12
-rw-r--r--src/pubkey/if_algo/if_algo.h2
-rw-r--r--src/pubkey/pk_keys.h6
8 files changed, 36 insertions, 23 deletions
diff --git a/src/cert/x509/x509_ca.cpp b/src/cert/x509/x509_ca.cpp
index 16b7b3b9b..9af5aa449 100644
--- a/src/cert/x509/x509_ca.cpp
+++ b/src/cert/x509/x509_ca.cpp
@@ -274,13 +274,7 @@ PK_Signer* choose_sig_format(const Private_Key& key,
padding = padding + '(' + proto_hash->name() + ')';
sig_algo.oid = OIDS::lookup(algo_name + "/" + padding);
-
- std::auto_ptr<X509_Encoder> encoding(key.x509_encoder());
- if(!encoding.get())
- throw Encoding_Error("Key " + algo_name + " does not support "
- "X.509 encoding");
-
- sig_algo.parameters = encoding->alg_id().parameters;
+ sig_algo.parameters = key.algorithm_identifier().parameters;
const PK_Signing_Key& sig_key = dynamic_cast<const PK_Signing_Key&>(key);
diff --git a/src/pubkey/dl_algo/dl_algo.cpp b/src/pubkey/dl_algo/dl_algo.cpp
index 8ce34465a..beaf10695 100644
--- a/src/pubkey/dl_algo/dl_algo.cpp
+++ b/src/pubkey/dl_algo/dl_algo.cpp
@@ -12,6 +12,12 @@
namespace Botan {
+AlgorithmIdentifier DL_Scheme_PublicKey::algorithm_identifier() const
+ {
+ return AlgorithmIdentifier(get_oid(),
+ group.DER_encode(group_format()));
+ }
+
/*
* Return the X.509 public key encoder
*/
@@ -22,10 +28,7 @@ X509_Encoder* DL_Scheme_PublicKey::x509_encoder() const
public:
AlgorithmIdentifier alg_id() const
{
- MemoryVector<byte> group =
- key->group.DER_encode(key->group_format());
-
- return AlgorithmIdentifier(key->get_oid(), group);
+ return key->algorithm_identifier();
}
MemoryVector<byte> key_bits() const
@@ -79,10 +82,7 @@ PKCS8_Encoder* DL_Scheme_PrivateKey::pkcs8_encoder() const
public:
AlgorithmIdentifier alg_id() const
{
- MemoryVector<byte> group =
- key->group.DER_encode(key->group_format());
-
- return AlgorithmIdentifier(key->get_oid(), group);
+ return key->algorithm_identifier();
}
MemoryVector<byte> key_bits() const
diff --git a/src/pubkey/dl_algo/dl_algo.h b/src/pubkey/dl_algo/dl_algo.h
index 256ce96ee..1fa99a49b 100644
--- a/src/pubkey/dl_algo/dl_algo.h
+++ b/src/pubkey/dl_algo/dl_algo.h
@@ -23,6 +23,8 @@ class BOTAN_DLL DL_Scheme_PublicKey : public virtual Public_Key
public:
bool check_key(RandomNumberGenerator& rng, bool) const;
+ AlgorithmIdentifier algorithm_identifier() const;
+
/**
* Get the DL domain parameters of this key.
* @return the DL domain parameters of this key
diff --git a/src/pubkey/ecc_key/ecc_key.cpp b/src/pubkey/ecc_key/ecc_key.cpp
index 22d7aceb4..4a0b20d2f 100644
--- a/src/pubkey/ecc_key/ecc_key.cpp
+++ b/src/pubkey/ecc_key/ecc_key.cpp
@@ -35,6 +35,11 @@ EC_PublicKey::EC_PublicKey(const EC_Domain_Params& dom_par,
}
}
+AlgorithmIdentifier EC_PublicKey::algorithm_identifier() const
+ {
+ return AlgorithmIdentifier(get_oid(), DER_domain());
+ }
+
void EC_PublicKey::X509_load_hook()
{
try
@@ -54,8 +59,7 @@ X509_Encoder* EC_PublicKey::x509_encoder() const
public:
AlgorithmIdentifier alg_id() const
{
- return AlgorithmIdentifier(key->get_oid(),
- key->DER_domain());
+ return key->algorithm_identifier();
}
MemoryVector<byte> key_bits() const
@@ -161,8 +165,7 @@ PKCS8_Encoder* EC_PrivateKey::pkcs8_encoder() const
public:
AlgorithmIdentifier alg_id() const
{
- return AlgorithmIdentifier(key->get_oid(),
- key->domain().DER_encode(EC_DOMPAR_ENC_EXPLICIT));
+ return key->algorithm_identifier();
}
MemoryVector<byte> key_bits() const
diff --git a/src/pubkey/ecc_key/ecc_key.h b/src/pubkey/ecc_key/ecc_key.h
index 1c41e5a1b..29a08fba6 100644
--- a/src/pubkey/ecc_key/ecc_key.h
+++ b/src/pubkey/ecc_key/ecc_key.h
@@ -40,6 +40,8 @@ class BOTAN_DLL EC_PublicKey : public virtual Public_Key
*/
const PointGFp& public_point() const { return public_key; }
+ AlgorithmIdentifier algorithm_identifier() const;
+
/**
* Get the domain parameters of this key.
* @throw Invalid_State is thrown if the
diff --git a/src/pubkey/if_algo/if_algo.cpp b/src/pubkey/if_algo/if_algo.cpp
index 556c86f6f..ee34b1418 100644
--- a/src/pubkey/if_algo/if_algo.cpp
+++ b/src/pubkey/if_algo/if_algo.cpp
@@ -12,6 +12,12 @@
namespace Botan {
+AlgorithmIdentifier IF_Scheme_PublicKey::algorithm_identifier() const
+ {
+ return AlgorithmIdentifier(get_oid(),
+ AlgorithmIdentifier::USE_NULL_PARAM);
+ }
+
/*
* Return the X.509 public key encoder
*/
@@ -22,8 +28,7 @@ X509_Encoder* IF_Scheme_PublicKey::x509_encoder() const
public:
AlgorithmIdentifier alg_id() const
{
- return AlgorithmIdentifier(key->get_oid(),
- AlgorithmIdentifier::USE_NULL_PARAM);
+ return key->algorithm_identifier();
}
MemoryVector<byte> key_bits() const
@@ -84,8 +89,7 @@ PKCS8_Encoder* IF_Scheme_PrivateKey::pkcs8_encoder() const
public:
AlgorithmIdentifier alg_id() const
{
- return AlgorithmIdentifier(key->get_oid(),
- AlgorithmIdentifier::USE_NULL_PARAM);
+ return key->algorithm_identifier();
}
MemoryVector<byte> key_bits() const
diff --git a/src/pubkey/if_algo/if_algo.h b/src/pubkey/if_algo/if_algo.h
index 32a29be49..98ae070c9 100644
--- a/src/pubkey/if_algo/if_algo.h
+++ b/src/pubkey/if_algo/if_algo.h
@@ -23,6 +23,8 @@ class BOTAN_DLL IF_Scheme_PublicKey : public virtual Public_Key
public:
bool check_key(RandomNumberGenerator& rng, bool) const;
+ AlgorithmIdentifier algorithm_identifier() const;
+
/**
* Get n = p * q.
* @return n
diff --git a/src/pubkey/pk_keys.h b/src/pubkey/pk_keys.h
index 5b612577d..33341b513 100644
--- a/src/pubkey/pk_keys.h
+++ b/src/pubkey/pk_keys.h
@@ -10,6 +10,7 @@
#include <botan/secmem.h>
#include <botan/asn1_oid.h>
+#include <botan/alg_id.h>
#include <botan/rng.h>
namespace Botan {
@@ -61,6 +62,11 @@ class BOTAN_DLL Public_Key
virtual u32bit max_input_bits() const = 0;
/**
+ * @return X.509 AlgorithmIdentifier for this key
+ */
+ virtual AlgorithmIdentifier algorithm_identifier() const = 0;
+
+ /**
* Get an X509 encoder that can be used to encode this key in X509 format.
* @return an X509 encoder for this key
*/