summaryrefslogtreecommitdiff
path: root/openssl/src/pkey.rs
diff options
context:
space:
mode:
authorSebastian Sturm <25849945+sturmsebastian@users.noreply.github.com>2019-08-16 11:10:29 +0200
committerSebastian Sturm <25849945+sturmsebastian@users.noreply.github.com>2019-08-16 11:15:04 +0200
commitbdede43afe5485aeeeb01737ff9c2800df11759c (patch)
treea2961d84f340e1e22490ba5745f93845722757b1 /openssl/src/pkey.rs
parent8b2c370b866807ecdba4f3ae53daf4625b828e0b (diff)
downloadrust-openssl-bdede43afe5485aeeeb01737ff9c2800df11759c.zip
Added support for Ed25519 and Ed448 signatures
Diffstat (limited to 'openssl/src/pkey.rs')
-rw-r--r--openssl/src/pkey.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/openssl/src/pkey.rs b/openssl/src/pkey.rs
index 0b562d74..f05f5f15 100644
--- a/openssl/src/pkey.rs
+++ b/openssl/src/pkey.rs
@@ -90,6 +90,11 @@ impl Id {
pub const DSA: Id = Id(ffi::EVP_PKEY_DSA);
pub const DH: Id = Id(ffi::EVP_PKEY_DH);
pub const EC: Id = Id(ffi::EVP_PKEY_EC);
+
+ #[cfg(ossl111)]
+ pub const ED25519: Id = Id(ffi::EVP_PKEY_ED25519);
+ #[cfg(ossl111)]
+ pub const ED448: Id = Id(ffi::EVP_PKEY_ED448);
}
/// A trait indicating that a key has parameters.
@@ -426,6 +431,40 @@ impl PKey<Private> {
}
}
+ #[cfg(ossl110)]
+ fn generate_eddsa(nid: c_int) -> Result<PKey<Private>, ErrorStack> {
+ unsafe {
+ let kctx = cvt_p(ffi::EVP_PKEY_CTX_new_id(nid, ptr::null_mut()))?;
+ let ret = cvt(ffi::EVP_PKEY_keygen_init(kctx));
+ if let Err(e) = ret {
+ ffi::EVP_PKEY_CTX_free(kctx);
+ return Err(e);
+ }
+ let mut key = ptr::null_mut();
+ let ret = cvt(ffi::EVP_PKEY_keygen(kctx, &mut key));
+
+ ffi::EVP_PKEY_CTX_free(kctx);
+
+ if let Err(e) = ret {
+ return Err(e);
+ }
+
+ Ok(PKey::from_ptr(key))
+ }
+ }
+
+ /// Generates a new private Ed25519 key
+ #[cfg(ossl111)]
+ pub fn generate_ed25519() -> Result<PKey<Private>, ErrorStack> {
+ PKey::generate_eddsa(ffi::EVP_PKEY_ED25519)
+ }
+
+ /// Generates a new private Ed448 key
+ #[cfg(ossl111)]
+ pub fn generate_ed448() -> Result<PKey<Private>, ErrorStack> {
+ PKey::generate_eddsa(ffi::EVP_PKEY_ED448)
+ }
+
private_key_from_pem! {
/// Deserializes a private key from a PEM-encoded key type specific format.
///