summaryrefslogtreecommitdiffstats
path: root/openpgp/src/crypto/mpi.rs
diff options
context:
space:
mode:
Diffstat (limited to 'openpgp/src/crypto/mpi.rs')
-rw-r--r--openpgp/src/crypto/mpi.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/openpgp/src/crypto/mpi.rs b/openpgp/src/crypto/mpi.rs
index b2610810..1f19b382 100644
--- a/openpgp/src/crypto/mpi.rs
+++ b/openpgp/src/crypto/mpi.rs
@@ -71,6 +71,25 @@ impl MPI {
}
}
+ /// Creates new MPI encoding a compressed EC point using native
+ /// encoding.
+ ///
+ /// Encodes the given point on a elliptic curve (see [Section 13.2
+ /// of RFC4880bis] for details). This is used to encode public
+ /// keys and ciphertexts for the Bernstein curves (currently
+ /// `X25519`).
+ ///
+ /// [Section 13.2 of RFC4880bis]: https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-09#section-13.2
+ pub fn new_compressed_point(x: &[u8]) -> Self {
+ let mut val = vec![0; 1 + x.len()];
+ val[0] = 0x40;
+ val[1..].copy_from_slice(x);
+
+ MPI {
+ value: val.into_boxed_slice(),
+ }
+ }
+
/// Returns the length of the MPI in bits.
pub fn bits(&self) -> usize {
self.value.len() * 8