summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/backend
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2021-09-09 15:14:20 +0200
committerJustus Winter <justus@sequoia-pgp.org>2021-09-16 12:51:19 +0200
commite939ea0fbc206856709955fe1937ff635749d4e7 (patch)
treeb4dab6c9d3fe2b9ed4bf4758f0a7fb9cca7ede71 /openpgp/src/crypto/backend
parent794d128c704934e828302a7f02df66c72fe7819e (diff)
openpgp: Make list of supported algorithms backend-dependent.
Diffstat (limited to 'openpgp/src/crypto/backend')
-rw-r--r--openpgp/src/crypto/backend/cng.rs39
-rw-r--r--openpgp/src/crypto/backend/nettle.rs39
2 files changed, 78 insertions, 0 deletions
diff --git a/openpgp/src/crypto/backend/cng.rs b/openpgp/src/crypto/backend/cng.rs
index 9947f3a2..8bf01b02 100644
--- a/openpgp/src/crypto/backend/cng.rs
+++ b/openpgp/src/crypto/backend/cng.rs
@@ -1,5 +1,7 @@
//! Implementation of crypto primitives using the Windows CNG (Cryptographic API: Next Generation).
+use crate::types::*;
+
use win_crypto_ng::random::RandomNumberGenerator;
pub mod aead;
@@ -14,3 +16,40 @@ pub fn random<B: AsMut<[u8]>>(mut buf: B) {
.gen_random(buf.as_mut())
.expect("system-preferred RNG not to fail")
}
+
+impl PublicKeyAlgorithm {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use PublicKeyAlgorithm::*;
+ #[allow(deprecated)]
+ match &self {
+ RSAEncryptSign | RSAEncrypt | RSASign | DSA | ECDH | ECDSA | EdDSA
+ => true,
+ ElGamalEncrypt | ElGamalEncryptSign | Private(_) | Unknown(_)
+ => false,
+ }
+ }
+}
+
+impl Curve {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use self::Curve::*;
+ match &self {
+ NistP256 | NistP384 | NistP521 | Ed25519 | Cv25519
+ => true,
+ BrainpoolP256 | BrainpoolP512 | Unknown(_)
+ => false,
+ }
+ }
+}
+
+impl AEADAlgorithm {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use self::AEADAlgorithm::*;
+ match &self {
+ EAX
+ => true,
+ OCB | Private(_) | Unknown(_)
+ => false,
+ }
+ }
+}
diff --git a/openpgp/src/crypto/backend/nettle.rs b/openpgp/src/crypto/backend/nettle.rs
index a07e7824..9bf737c0 100644
--- a/openpgp/src/crypto/backend/nettle.rs
+++ b/openpgp/src/crypto/backend/nettle.rs
@@ -1,5 +1,7 @@
//! Implementation of Sequoia crypto API using the Nettle cryptographic library.
+use crate::types::*;
+
use nettle::random::{Random, Yarrow};
pub mod aead;
@@ -20,3 +22,40 @@ pub mod symmetric;
pub fn random<B: AsMut<[u8]>>(mut buf: B) {
Yarrow::default().random(buf.as_mut());
}
+
+impl PublicKeyAlgorithm {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use PublicKeyAlgorithm::*;
+ #[allow(deprecated)]
+ match &self {
+ RSAEncryptSign | RSAEncrypt | RSASign | DSA | ECDH | ECDSA | EdDSA
+ => true,
+ ElGamalEncrypt | ElGamalEncryptSign | Private(_) | Unknown(_)
+ => false,
+ }
+ }
+}
+
+impl Curve {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use self::Curve::*;
+ match &self {
+ NistP256 | NistP384 | NistP521 | Ed25519 | Cv25519
+ => true,
+ BrainpoolP256 | BrainpoolP512 | Unknown(_)
+ => false,
+ }
+ }
+}
+
+impl AEADAlgorithm {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use self::AEADAlgorithm::*;
+ match &self {
+ EAX
+ => true,
+ OCB | Private(_) | Unknown(_)
+ => false,
+ }
+ }
+}