From 119b59a2c8403ee69f788106f8192949e3b40c34 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 11 May 2022 13:29:08 +0200 Subject: openpgp: Add crypto::backend that identifies the backend. - This returns a short, human-readable description of the cryptographic backend for use in version strings to improve bug reports. - Fixes #818. --- openpgp/src/crypto/backend/cng.rs | 6 ++++++ openpgp/src/crypto/backend/nettle.rs | 7 +++++++ openpgp/src/crypto/backend/rust.rs | 6 ++++++ 3 files changed, 19 insertions(+) (limited to 'openpgp/src/crypto/backend') diff --git a/openpgp/src/crypto/backend/cng.rs b/openpgp/src/crypto/backend/cng.rs index f964756a..89f56e31 100644 --- a/openpgp/src/crypto/backend/cng.rs +++ b/openpgp/src/crypto/backend/cng.rs @@ -10,6 +10,12 @@ pub mod ecdh; pub mod hash; pub mod symmetric; +/// Returns a short, human-readable description of the backend. +pub fn backend() -> String { + // XXX: can we include features and the version? + "Windows CNG".to_string() +} + /// Fills the given buffer with random data. pub fn random(buf: &mut [u8]) { RandomNumberGenerator::system_preferred() diff --git a/openpgp/src/crypto/backend/nettle.rs b/openpgp/src/crypto/backend/nettle.rs index 79497a66..3de8a6a9 100644 --- a/openpgp/src/crypto/backend/nettle.rs +++ b/openpgp/src/crypto/backend/nettle.rs @@ -10,6 +10,13 @@ pub mod ecdh; pub mod hash; pub mod symmetric; +/// Returns a short, human-readable description of the backend. +pub fn backend() -> String { + // XXX: Once we depend on nettle-rs 7.1, add cv448 feature + // XXX: Once we depend on nettle-rs 7.2, add nettle::version + "Nettle".to_string() +} + /// Fills the given buffer with random data. pub fn random(buf: &mut [u8]) { Yarrow::default().random(buf); diff --git a/openpgp/src/crypto/backend/rust.rs b/openpgp/src/crypto/backend/rust.rs index 06b1da03..dc4773ed 100644 --- a/openpgp/src/crypto/backend/rust.rs +++ b/openpgp/src/crypto/backend/rust.rs @@ -9,6 +9,12 @@ pub mod ecdh; pub mod hash; pub mod symmetric; +/// Returns a short, human-readable description of the backend. +pub fn backend() -> String { + // XXX: can we include features and the version? + "RustCrypto".to_string() +} + /// Fills the given buffer with random data. pub fn random(buf: &mut [u8]) { use rand07::rngs::OsRng; -- cgit v1.2.3