aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-04 05:20:59 +0000
committerlloyd <[email protected]>2010-03-04 05:20:59 +0000
commit2548328cc11d76036e8fc714172b130f2a8c3ebc (patch)
treea34b62ed0e5ca90b69f0a82ba8c00e41dc91b912 /src
parentd490c5bed4331a4336556e08873fe03a792ad127 (diff)
Quite the hack, here.
GOST 34.10 public keys use a funky encoding. There is no standard for PKCS #8 format private keys, so the obvious choice is to act exactly the same as ECDSA/ECDH (following the rule of thumb that if you're going to make up a random non-standard thing, at least try to copy something that's standard for something else). However the public key encoding uses a weird scheme for encoding the OID in the algorithm identifier, which we don't want to use for the PKCS #8 encoding. Add a new function to Private_Key, pkcs8_algorithm_identifier, which by default just calls algorithm_identifier(). However GOST_3410_PrivateKey overrides it, and calls EC_PublicKey::algorithm_identifier(), basically skipping over the virtual function hierarchy, so it doesn't pick up the funky format from the public key's version of algorithm_identifier().
Diffstat (limited to 'src')
-rw-r--r--src/pubkey/gost_3410/gost_3410.h3
-rw-r--r--src/pubkey/pk_keys.h7
-rw-r--r--src/pubkey/pkcs8.cpp2
3 files changed, 11 insertions, 1 deletions
diff --git a/src/pubkey/gost_3410/gost_3410.h b/src/pubkey/gost_3410/gost_3410.h
index 696daf0a7..669ed130f 100644
--- a/src/pubkey/gost_3410/gost_3410.h
+++ b/src/pubkey/gost_3410/gost_3410.h
@@ -103,6 +103,9 @@ class BOTAN_DLL GOST_3410_PrivateKey : public GOST_3410_PublicKey,
GOST_3410_PrivateKey(const EC_Domain_Params& domain, const BigInt& x) :
EC_PrivateKey(domain, x) {}
+ AlgorithmIdentifier pkcs8_algorithm_identifier() const
+ { return EC_PublicKey::algorithm_identifier(); }
+
/**
* Sign a message with this key.
* @param message the byte array representing the message to be signed
diff --git a/src/pubkey/pk_keys.h b/src/pubkey/pk_keys.h
index 4e0f58b38..8015c1076 100644
--- a/src/pubkey/pk_keys.h
+++ b/src/pubkey/pk_keys.h
@@ -87,6 +87,13 @@ class BOTAN_DLL Private_Key : public virtual Public_Key
*/
virtual MemoryVector<byte> pkcs8_private_key() const = 0;
+ /**
+ * @return PKCS #8 AlgorithmIdentifier for this key
+ * Might be different from the X.509 identifier, but normally is not
+ */
+ virtual AlgorithmIdentifier pkcs8_algorithm_identifier() const
+ { return algorithm_identifier(); }
+
protected:
void load_check(RandomNumberGenerator&) const;
void gen_check(RandomNumberGenerator&) const;
diff --git a/src/pubkey/pkcs8.cpp b/src/pubkey/pkcs8.cpp
index c89431fca..400fdbb48 100644
--- a/src/pubkey/pkcs8.cpp
+++ b/src/pubkey/pkcs8.cpp
@@ -144,7 +144,7 @@ void encode(const Private_Key& key, Pipe& pipe, X509_Encoding encoding)
DER_Encoder()
.start_cons(SEQUENCE)
.encode(PKCS8_VERSION)
- .encode(key.algorithm_identifier())
+ .encode(key.pkcs8_algorithm_identifier())
.encode(key.pkcs8_private_key(), OCTET_STRING)
.end_cons()
.get_contents();