summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/backend/botan.rs
diff options
context:
space:
mode:
Diffstat (limited to 'openpgp/src/crypto/backend/botan.rs')
-rw-r--r--openpgp/src/crypto/backend/botan.rs101
1 files changed, 101 insertions, 0 deletions
diff --git a/openpgp/src/crypto/backend/botan.rs b/openpgp/src/crypto/backend/botan.rs
new file mode 100644
index 00000000..30f42a67
--- /dev/null
+++ b/openpgp/src/crypto/backend/botan.rs
@@ -0,0 +1,101 @@
+//! Implementation of Sequoia crypto API using the Botan cryptographic library.
+
+use crate::types::*;
+
+pub mod aead;
+#[allow(unused_variables)]
+pub mod asymmetric;
+#[allow(unused_variables)]
+pub mod ecdh;
+pub mod hash;
+pub mod symmetric;
+
+/// Returns a short, human-readable description of the backend.
+pub fn backend() -> String {
+ "Botan".to_string()
+}
+
+/// Fills the given buffer with random data.
+pub fn random(buf: &mut [u8]) {
+ let mut rng = botan::RandomNumberGenerator::new_system().unwrap();
+ rng.fill(buf).unwrap();
+}
+
+impl PublicKeyAlgorithm {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use PublicKeyAlgorithm::*;
+ #[allow(deprecated)]
+ match &self {
+ RSAEncryptSign | RSAEncrypt | RSASign | DSA | ECDH | ECDSA | EdDSA |
+ ElGamalEncrypt | ElGamalEncryptSign
+ => true,
+ Private(_) | Unknown(_)
+ => false,
+ }
+ }
+}
+
+impl Curve {
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use self::Curve::*;
+ match &self {
+ NistP256 | NistP384 | NistP521 | Ed25519 | Cv25519 |
+ BrainpoolP256 | BrainpoolP512
+ => true,
+ Unknown(_) if self.is_brainpoolp384() // XXX
+ => true,
+ Unknown(_)
+ => false,
+ }
+ }
+}
+
+impl AEADAlgorithm {
+ /// Returns the best AEAD mode supported by the backend.
+ ///
+ /// This SHOULD return OCB, which is the mandatory-to-implement
+ /// algorithm and the most performing one, but fall back to any
+ /// supported algorithm.
+ pub(crate) const fn const_default() -> AEADAlgorithm {
+ AEADAlgorithm::OCB
+ }
+
+ pub(crate) fn is_supported_by_backend(&self) -> bool {
+ use self::AEADAlgorithm::*;
+ match &self {
+ EAX | OCB
+ => true,
+ Private(_) | Unknown(_)
+ => false,
+ }
+ }
+
+ #[cfg(test)]
+ pub(crate) fn supports_symmetric_algo(&self, algo: &SymmetricAlgorithm) -> bool {
+ match &self {
+ AEADAlgorithm::EAX =>
+ match algo {
+ SymmetricAlgorithm::AES128 |
+ SymmetricAlgorithm::AES192 |
+ SymmetricAlgorithm::AES256 |
+ SymmetricAlgorithm::Twofish |
+ SymmetricAlgorithm::Camellia128 |
+ SymmetricAlgorithm::Camellia192 |
+ SymmetricAlgorithm::Camellia256 => true,
+ _ => false,
+ },
+ AEADAlgorithm::OCB =>
+ match algo {
+ SymmetricAlgorithm::AES128 |
+ SymmetricAlgorithm::AES192 |
+ SymmetricAlgorithm::AES256 |
+ SymmetricAlgorithm::Twofish |
+ SymmetricAlgorithm::Camellia128 |
+ SymmetricAlgorithm::Camellia192 |
+ SymmetricAlgorithm::Camellia256 => true,
+ _ => false,
+ },
+ _ => false
+ }
+ }
+}