aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-01 23:15:07 +0000
committerlloyd <[email protected]>2010-03-01 23:15:07 +0000
commitfebcffc5b0430566600018efbc8608b1df3a54d8 (patch)
treeebecf719ef42b801ff9688d94c6e3947b538e20e
parent3fb831f2e24ec1e3d7f8902d4aa5adceaf366f01 (diff)
Add EC_Domain_Params::PEM_encode
-rw-r--r--src/pubkey/ec_dompar/ec_dompar.cpp69
-rw-r--r--src/pubkey/ec_dompar/ec_dompar.h6
-rw-r--r--src/pubkey/ec_dompar/info.txt1
3 files changed, 45 insertions, 31 deletions
diff --git a/src/pubkey/ec_dompar/ec_dompar.cpp b/src/pubkey/ec_dompar/ec_dompar.cpp
index 596edce83..6f284332a 100644
--- a/src/pubkey/ec_dompar/ec_dompar.cpp
+++ b/src/pubkey/ec_dompar/ec_dompar.cpp
@@ -10,8 +10,9 @@
#include <botan/ec_dompar.h>
#include <botan/pubkey_enums.h>
#include <botan/parsing.h>
-#include <botan/hex.h>
#include <botan/pipe.h>
+#include <botan/hex.h>
+#include <botan/pem.h>
namespace Botan {
@@ -506,38 +507,44 @@ EC_Domain_Params::EC_Domain_Params(const MemoryRegion<byte>& ber_data)
SecureVector<byte>
EC_Domain_Params::DER_encode(EC_Domain_Params_Encoding form) const
- {
- if(form == EC_DOMPAR_ENC_EXPLICIT)
- {
- u32bit ecpVers1 = 1;
- OID curve_type("1.2.840.10045.1.1");
+ {
+ if(form == EC_DOMPAR_ENC_EXPLICIT)
+ {
+ u32bit ecpVers1 = 1;
+ OID curve_type("1.2.840.10045.1.1");
- const u32bit p_bytes = curve.get_p().bytes();
+ const u32bit p_bytes = curve.get_p().bytes();
- return DER_Encoder()
- .start_cons(SEQUENCE)
- .encode(ecpVers1)
- .start_cons(SEQUENCE)
- .encode(curve_type)
- .encode(curve.get_p())
- .end_cons()
- .start_cons(SEQUENCE)
- .encode(BigInt::encode_1363(curve.get_a(), p_bytes), OCTET_STRING)
- .encode(BigInt::encode_1363(curve.get_b(), p_bytes), OCTET_STRING)
- .end_cons()
- .encode(EC2OSP(base_point, PointGFp::UNCOMPRESSED), OCTET_STRING)
- .encode(order)
- .encode(cofactor)
- .end_cons()
- .get_contents();
- }
- else if(form == EC_DOMPAR_ENC_OID)
- return DER_Encoder().encode(get_oid()).get_contents();
- else if(form == EC_DOMPAR_ENC_IMPLICITCA)
- return DER_Encoder().encode_null().get_contents();
-
- throw Internal_Error("EC_Domain_Params::encode_DER: Unknown encoding");
- }
+ return DER_Encoder()
+ .start_cons(SEQUENCE)
+ .encode(ecpVers1)
+ .start_cons(SEQUENCE)
+ .encode(curve_type)
+ .encode(curve.get_p())
+ .end_cons()
+ .start_cons(SEQUENCE)
+ .encode(BigInt::encode_1363(curve.get_a(), p_bytes), OCTET_STRING)
+ .encode(BigInt::encode_1363(curve.get_b(), p_bytes), OCTET_STRING)
+ .end_cons()
+ .encode(EC2OSP(base_point, PointGFp::UNCOMPRESSED), OCTET_STRING)
+ .encode(order)
+ .encode(cofactor)
+ .end_cons()
+ .get_contents();
+ }
+ else if(form == EC_DOMPAR_ENC_OID)
+ return DER_Encoder().encode(get_oid()).get_contents();
+ else if(form == EC_DOMPAR_ENC_IMPLICITCA)
+ return DER_Encoder().encode_null().get_contents();
+
+ throw Internal_Error("EC_Domain_Params::encode_DER: Unknown encoding");
+ }
+
+std::string EC_Domain_Params::PEM_encode() const
+ {
+ SecureVector<byte> der = DER_encode(EC_DOMPAR_ENC_EXPLICIT);
+ return PEM_Code::encode(der, "ECC DOMAIN PARAMETERS");
+ }
}
diff --git a/src/pubkey/ec_dompar/ec_dompar.h b/src/pubkey/ec_dompar/ec_dompar.h
index b2f1e5d7c..8700cf158 100644
--- a/src/pubkey/ec_dompar/ec_dompar.h
+++ b/src/pubkey/ec_dompar/ec_dompar.h
@@ -70,6 +70,12 @@ class BOTAN_DLL EC_Domain_Params
SecureVector<byte> DER_encode(EC_Domain_Params_Encoding form) const;
/**
+ * Return the PEM encoding (always in explicit form)
+ * @return string containing PEM data
+ */
+ std::string PEM_encode() const;
+
+ /**
* Return domain parameter curve
* @result domain parameter curve
*/
diff --git a/src/pubkey/ec_dompar/info.txt b/src/pubkey/ec_dompar/info.txt
index fd40b887d..4b23b5ca5 100644
--- a/src/pubkey/ec_dompar/info.txt
+++ b/src/pubkey/ec_dompar/info.txt
@@ -5,4 +5,5 @@ asn1
filters
numbertheory
hex
+pem
</requires>