summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-01-10 11:12:35 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-01-10 14:41:50 +0100
commitb3a4ad197f84b22883c2c2f4114b0e3472af60ee (patch)
tree470a64ce9d057ff5aa2f29619b6bd008c6fabcdb
parent14856cf73c4fe0afb7b6b6d752aab81ff7f94b74 (diff)
ffi: New module openpgp/crypto.
-rw-r--r--ffi/include/sequoia/openpgp.h2
-rw-r--r--ffi/include/sequoia/openpgp/crypto.h50
-rw-r--r--ffi/src/openpgp/crypto.rs56
-rw-r--r--ffi/src/openpgp/mod.rs1
4 files changed, 109 insertions, 0 deletions
diff --git a/ffi/include/sequoia/openpgp.h b/ffi/include/sequoia/openpgp.h
index 5900d565..40c45d55 100644
--- a/ffi/include/sequoia/openpgp.h
+++ b/ffi/include/sequoia/openpgp.h
@@ -4,6 +4,8 @@
#include <sequoia/core.h>
#include <time.h>
+#include <sequoia/openpgp/crypto.h>
+
/*/
/// A low-level OpenPGP message parser.
///
diff --git a/ffi/include/sequoia/openpgp/crypto.h b/ffi/include/sequoia/openpgp/crypto.h
new file mode 100644
index 00000000..1c30fe3f
--- /dev/null
+++ b/ffi/include/sequoia/openpgp/crypto.h
@@ -0,0 +1,50 @@
+#ifndef SEQUOIA_OPENPGP_CRYPTO_H
+#define SEQUOIA_OPENPGP_CRYPTO_H
+
+typedef struct sq_mpi *sq_mpi_t;
+
+/*/
+/// Creates a signature.
+///
+/// This is a low-level mechanism to produce an arbitrary OpenPGP
+/// signature. Using this trait allows Sequoia to perform all
+/// operations involving signing to use a variety of secret key
+/// storage mechanisms (e.g. smart cards).
+/*/
+typedef struct sq_signer *sq_signer_t;
+
+/*/
+/// Frees a signer.
+/*/
+void sq_signer_free (sq_signer_t s);
+
+/*/
+/// A cryptographic key pair.
+///
+/// A `KeyPair` is a combination of public and secret key. If both
+/// are available in memory, a `KeyPair` is a convenient
+/*/
+typedef struct sq_key_pair *sq_key_pair_t;
+
+/* Forward declaration. */
+typedef struct sq_p_key *sq_p_key_t;
+
+/*/
+/// Creates a new key pair.
+/*/
+void sq_key_pair_new (sq_p_key_t public, sq_mpi_t secret);
+
+/*/
+/// Frees a key pair.
+/*/
+void sq_key_pair_free (sq_key_pair_t kp);
+
+/*/
+/// Creates a signer from a key pair.
+///
+/// Note that the returned object merely references the key pair, and
+/// must not outlive the key pair.
+/*/
+sq_signer_t sq_key_pair_as_signer (sq_key_pair_t kp);
+
+#endif /* SEQUOIA_OPENPGP_CRYPTO_H */
diff --git a/ffi/src/openpgp/crypto.rs b/ffi/src/openpgp/crypto.rs
new file mode 100644
index 00000000..4236568f
--- /dev/null
+++ b/ffi/src/openpgp/crypto.rs
@@ -0,0 +1,56 @@
+//! Cryptographic primitives.
+//!
+//! Wraps [`sequoia-openpgp::crypto`].
+//!
+//! [`sequoia-openpgp::crypto`]: ../../../sequoia_openpgp/crypto/index.html
+
+use ::core::Context;
+
+extern crate sequoia_openpgp;
+use self::sequoia_openpgp::{
+ crypto,
+ packet::Key,
+};
+
+/// Frees a signer.
+#[no_mangle]
+pub extern "system" fn sq_signer_free
+ (s: Option<&mut &'static mut crypto::Signer>)
+{
+ ffi_free!(s)
+}
+
+/// Creates a new key pair.
+#[no_mangle]
+pub extern "system" fn sq_key_pair_new
+ (ctx: *mut Context, public: *mut Key, secret: *mut crypto::mpis::SecretKey)
+ -> *mut crypto::KeyPair
+{
+ let ctx = ffi_param_ref_mut!(ctx);
+ let public = ffi_param_move!(public);
+ let secret = ffi_param_move!(secret);
+ fry_box!(ctx, crypto::KeyPair::new(*public, *secret))
+}
+
+/// Frees a key pair.
+#[no_mangle]
+pub extern "system" fn sq_key_pair_free
+ (kp: Option<&mut crypto::KeyPair>)
+{
+ ffi_free!(kp)
+}
+
+/// Creates a signer from a key pair.
+///
+/// Note that the returned object merely references the key pair, and
+/// must not outlive the key pair.
+#[no_mangle]
+pub extern "system" fn sq_key_pair_as_signer
+ (kp: *mut crypto::KeyPair)
+ -> *mut &'static mut crypto::Signer
+{
+ let kp = ffi_param_ref_mut!(kp);
+ let signer: &mut crypto::Signer = kp;
+ box_raw!(signer)
+ //box_raw!(kp)
+}
diff --git a/ffi/src/openpgp/mod.rs b/ffi/src/openpgp/mod.rs
index 2a663763..1f5081e6 100644
--- a/ffi/src/openpgp/mod.rs
+++ b/ffi/src/openpgp/mod.rs
@@ -54,6 +54,7 @@ use super::error::Status;
use super::core::Context;
pub mod armor;
+pub mod crypto;
pub mod fingerprint;
pub mod keyid;
pub mod packet_pile;