summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2022-05-11 13:29:08 +0200
committerJustus Winter <justus@sequoia-pgp.org>2022-05-11 15:55:59 +0200
commit119b59a2c8403ee69f788106f8192949e3b40c34 (patch)
tree4c583be724a5e61b60c2199c7e5acc4584c56e53
parent523cfd7845fd8141293b5dbe63e630428e9ac90d (diff)
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.
-rw-r--r--openpgp/NEWS1
-rw-r--r--openpgp/src/crypto/backend/cng.rs6
-rw-r--r--openpgp/src/crypto/backend/nettle.rs7
-rw-r--r--openpgp/src/crypto/backend/rust.rs6
-rw-r--r--openpgp/src/crypto/mod.rs9
5 files changed, 29 insertions, 0 deletions
diff --git a/openpgp/NEWS b/openpgp/NEWS
index c458e9bc..416e51f7 100644
--- a/openpgp/NEWS
+++ b/openpgp/NEWS
@@ -4,6 +4,7 @@
* Changes in 1.9.0
** New functionality
+ - crypto::backend
- packet::Any
- Packet::version
- SignatureBuilder::set_reference_time
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;
diff --git a/openpgp/src/crypto/mod.rs b/openpgp/src/crypto/mod.rs
index e3cfa197..6dc2002d 100644
--- a/openpgp/src/crypto/mod.rs
+++ b/openpgp/src/crypto/mod.rs
@@ -43,6 +43,15 @@ pub(crate) mod symmetric;
#[cfg(test)]
mod tests;
+/// Returns a short, human-readable description of the backend.
+///
+/// This starts with the name of the backend, possibly a version, and
+/// any optional features that are available. This is meant for
+/// inclusion in version strings to improve bug reports.
+pub fn backend() -> String {
+ backend::backend()
+}
+
/// Fills the given buffer with random data.
///
/// Fills the given buffer with random data produced by a