Skip to content

Commit 9ea51ec

Browse files
authored
Merge pull request #1846 from alex/25519-is-libre
Enable X/Ed25519 support on LibreSSL 3.7.0
2 parents 39d1436 + 0d44062 commit 9ea51ec

File tree

5 files changed

+32
-28
lines changed

5 files changed

+32
-28
lines changed

openssl-sys/src/evp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ pub const EVP_PKEY_RSA: c_int = NID_rsaEncryption;
1010
pub const EVP_PKEY_DSA: c_int = NID_dsa;
1111
pub const EVP_PKEY_DH: c_int = NID_dhKeyAgreement;
1212
pub const EVP_PKEY_EC: c_int = NID_X9_62_id_ecPublicKey;
13-
#[cfg(ossl111)]
13+
#[cfg(any(ossl111, libressl370))]
1414
pub const EVP_PKEY_X25519: c_int = NID_X25519;
15-
#[cfg(ossl111)]
15+
#[cfg(any(ossl111, libressl370))]
1616
pub const EVP_PKEY_ED25519: c_int = NID_ED25519;
1717
#[cfg(ossl111)]
1818
pub const EVP_PKEY_X448: c_int = NID_X448;

openssl-sys/src/handwritten/evp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ cfg_if! {
230230
}
231231
}
232232
cfg_if! {
233-
if #[cfg(ossl111)] {
233+
if #[cfg(any(ossl111, libressl370))] {
234234
extern "C" {
235235
pub fn EVP_DigestSign(
236236
ctx: *mut EVP_MD_CTX,
@@ -566,7 +566,7 @@ const_ptr_api! {
566566
}
567567

568568
cfg_if! {
569-
if #[cfg(any(ossl111))] {
569+
if #[cfg(any(ossl111, libressl370))] {
570570
extern "C" {
571571
pub fn EVP_PKEY_get_raw_public_key(
572572
pkey: *const EVP_PKEY,

openssl-sys/src/obj_mac.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,12 +920,16 @@ pub const NID_aes_192_cbc_hmac_sha1: c_int = 917;
920920
pub const NID_aes_256_cbc_hmac_sha1: c_int = 918;
921921
#[cfg(ossl111)]
922922
pub const NID_X25519: c_int = 1034;
923+
#[cfg(libressl370)]
924+
pub const NID_X25519: c_int = 950;
923925
#[cfg(ossl111)]
924926
pub const NID_X448: c_int = 1035;
925927
#[cfg(ossl110)]
926928
pub const NID_hkdf: c_int = 1036;
927929
#[cfg(ossl111)]
928930
pub const NID_ED25519: c_int = 1087;
931+
#[cfg(libressl370)]
932+
pub const NID_ED25519: c_int = 952;
929933
#[cfg(ossl111)]
930934
pub const NID_ED448: c_int = 1088;
931935
#[cfg(ossl111)]

openssl/src/pkey.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use crate::dh::Dh;
4747
use crate::dsa::Dsa;
4848
use crate::ec::EcKey;
4949
use crate::error::ErrorStack;
50-
#[cfg(any(ossl110, boringssl))]
50+
#[cfg(any(ossl110, boringssl, libressl370))]
5151
use crate::pkey_ctx::PkeyCtx;
5252
use crate::rsa::Rsa;
5353
use crate::symm::Cipher;
@@ -89,11 +89,11 @@ impl Id {
8989
#[cfg(ossl110)]
9090
pub const HKDF: Id = Id(ffi::EVP_PKEY_HKDF);
9191

92-
#[cfg(any(ossl111, boringssl))]
92+
#[cfg(any(ossl111, boringssl, libressl370))]
9393
pub const ED25519: Id = Id(ffi::EVP_PKEY_ED25519);
9494
#[cfg(ossl111)]
9595
pub const ED448: Id = Id(ffi::EVP_PKEY_ED448);
96-
#[cfg(any(ossl111, boringssl))]
96+
#[cfg(any(ossl111, boringssl, libressl370))]
9797
pub const X25519: Id = Id(ffi::EVP_PKEY_X25519);
9898
#[cfg(ossl111)]
9999
pub const X448: Id = Id(ffi::EVP_PKEY_X448);
@@ -252,7 +252,7 @@ where
252252
/// This function only works for algorithms that support raw public keys.
253253
/// Currently this is: [`Id::X25519`], [`Id::ED25519`], [`Id::X448`] or [`Id::ED448`].
254254
#[corresponds(EVP_PKEY_get_raw_public_key)]
255-
#[cfg(any(ossl111, boringssl))]
255+
#[cfg(any(ossl111, boringssl, libressl370))]
256256
pub fn raw_public_key(&self) -> Result<Vec<u8>, ErrorStack> {
257257
unsafe {
258258
let mut len = 0;
@@ -303,7 +303,7 @@ where
303303
/// This function only works for algorithms that support raw private keys.
304304
/// Currently this is: [`Id::HMAC`], [`Id::X25519`], [`Id::ED25519`], [`Id::X448`] or [`Id::ED448`].
305305
#[corresponds(EVP_PKEY_get_raw_private_key)]
306-
#[cfg(any(ossl111, boringssl))]
306+
#[cfg(any(ossl111, boringssl, libressl370))]
307307
pub fn raw_private_key(&self) -> Result<Vec<u8>, ErrorStack> {
308308
unsafe {
309309
let mut len = 0;
@@ -503,7 +503,7 @@ impl PKey<Private> {
503503
ctx.keygen()
504504
}
505505

506-
#[cfg(any(ossl111, boringssl))]
506+
#[cfg(any(ossl111, boringssl, libressl370))]
507507
fn generate_eddsa(id: Id) -> Result<PKey<Private>, ErrorStack> {
508508
let mut ctx = PkeyCtx::new_id(id)?;
509509
ctx.keygen_init()?;
@@ -533,7 +533,7 @@ impl PKey<Private> {
533533
/// assert_eq!(secret.len(), 32);
534534
/// # Ok(()) }
535535
/// ```
536-
#[cfg(any(ossl111, boringssl))]
536+
#[cfg(any(ossl111, boringssl, libressl370))]
537537
pub fn generate_x25519() -> Result<PKey<Private>, ErrorStack> {
538538
PKey::generate_eddsa(Id::X25519)
539539
}
@@ -587,7 +587,7 @@ impl PKey<Private> {
587587
/// assert_eq!(signature.len(), 64);
588588
/// # Ok(()) }
589589
/// ```
590-
#[cfg(any(ossl111, boringssl))]
590+
#[cfg(any(ossl111, boringssl, libressl370))]
591591
pub fn generate_ed25519() -> Result<PKey<Private>, ErrorStack> {
592592
PKey::generate_eddsa(Id::ED25519)
593593
}
@@ -737,7 +737,7 @@ impl PKey<Private> {
737737
///
738738
/// Algorithm types that support raw private keys are HMAC, X25519, ED25519, X448 or ED448
739739
#[corresponds(EVP_PKEY_new_raw_private_key)]
740-
#[cfg(any(ossl111, boringssl))]
740+
#[cfg(any(ossl111, boringssl, libressl370))]
741741
pub fn private_key_from_raw_bytes(
742742
bytes: &[u8],
743743
key_type: Id,
@@ -778,7 +778,7 @@ impl PKey<Public> {
778778
///
779779
/// Algorithm types that support raw public keys are X25519, ED25519, X448 or ED448
780780
#[corresponds(EVP_PKEY_new_raw_public_key)]
781-
#[cfg(any(ossl111, boringssl))]
781+
#[cfg(any(ossl111, boringssl, libressl370))]
782782
pub fn public_key_from_raw_bytes(
783783
bytes: &[u8],
784784
key_type: Id,
@@ -1084,7 +1084,7 @@ mod tests {
10841084
assert_eq!(&g, dh_.generator());
10851085
}
10861086

1087-
#[cfg(any(ossl111, boringssl))]
1087+
#[cfg(any(ossl111, boringssl, libressl370))]
10881088
fn test_raw_public_key(gen: fn() -> Result<PKey<Private>, ErrorStack>, key_type: Id) {
10891089
// Generate a new key
10901090
let key = gen().unwrap();
@@ -1100,7 +1100,7 @@ mod tests {
11001100
);
11011101
}
11021102

1103-
#[cfg(any(ossl111, boringssl))]
1103+
#[cfg(any(ossl111, boringssl, libressl370))]
11041104
fn test_raw_private_key(gen: fn() -> Result<PKey<Private>, ErrorStack>, key_type: Id) {
11051105
// Generate a new key
11061106
let key = gen().unwrap();
@@ -1116,25 +1116,25 @@ mod tests {
11161116
);
11171117
}
11181118

1119-
#[cfg(any(ossl111, boringssl))]
1119+
#[cfg(any(ossl111, boringssl, libressl370))]
11201120
#[test]
11211121
fn test_raw_public_key_bytes() {
11221122
test_raw_public_key(PKey::generate_x25519, Id::X25519);
11231123
test_raw_public_key(PKey::generate_ed25519, Id::ED25519);
1124-
#[cfg(not(boringssl))]
1124+
#[cfg(all(not(boringssl), not(libressl370)))]
11251125
test_raw_public_key(PKey::generate_x448, Id::X448);
1126-
#[cfg(not(boringssl))]
1126+
#[cfg(all(not(boringssl), not(libressl370)))]
11271127
test_raw_public_key(PKey::generate_ed448, Id::ED448);
11281128
}
11291129

1130-
#[cfg(any(ossl111, boringssl))]
1130+
#[cfg(any(ossl111, boringssl, libressl370))]
11311131
#[test]
11321132
fn test_raw_private_key_bytes() {
11331133
test_raw_private_key(PKey::generate_x25519, Id::X25519);
11341134
test_raw_private_key(PKey::generate_ed25519, Id::ED25519);
1135-
#[cfg(not(boringssl))]
1135+
#[cfg(all(not(boringssl), not(libressl370)))]
11361136
test_raw_private_key(PKey::generate_x448, Id::X448);
1137-
#[cfg(not(boringssl))]
1137+
#[cfg(all(not(boringssl), not(libressl370)))]
11381138
test_raw_private_key(PKey::generate_ed448, Id::ED448);
11391139
}
11401140

openssl/src/sign.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl<'a> Signer<'a> {
290290
self.len_intern()
291291
}
292292

293-
#[cfg(all(not(ossl111), not(boringssl)))]
293+
#[cfg(all(not(ossl111), not(boringssl), not(libressl370)))]
294294
fn len_intern(&self) -> Result<usize, ErrorStack> {
295295
unsafe {
296296
let mut len = 0;
@@ -303,7 +303,7 @@ impl<'a> Signer<'a> {
303303
}
304304
}
305305

306-
#[cfg(any(ossl111, boringssl))]
306+
#[cfg(any(ossl111, boringssl, libressl370))]
307307
fn len_intern(&self) -> Result<usize, ErrorStack> {
308308
unsafe {
309309
let mut len = 0;
@@ -360,7 +360,7 @@ impl<'a> Signer<'a> {
360360
/// OpenSSL documentation at [`EVP_DigestSign`].
361361
///
362362
/// [`EVP_DigestSign`]: https://www.openssl.org/docs/man1.1.1/man3/EVP_DigestSign.html
363-
#[cfg(any(ossl111, boringssl))]
363+
#[cfg(any(ossl111, boringssl, libressl370))]
364364
pub fn sign_oneshot(
365365
&mut self,
366366
sig_buf: &mut [u8],
@@ -382,7 +382,7 @@ impl<'a> Signer<'a> {
382382
/// Returns the signature.
383383
///
384384
/// This is a simple convenience wrapper over `len` and `sign_oneshot`.
385-
#[cfg(any(ossl111, boringssl))]
385+
#[cfg(any(ossl111, boringssl, libressl370))]
386386
pub fn sign_oneshot_to_vec(&mut self, data_buf: &[u8]) -> Result<Vec<u8>, ErrorStack> {
387387
let mut sig_buf = vec![0; self.len()?];
388388
let len = self.sign_oneshot(&mut sig_buf, data_buf)?;
@@ -596,7 +596,7 @@ impl<'a> Verifier<'a> {
596596
/// OpenSSL documentation at [`EVP_DigestVerify`].
597597
///
598598
/// [`EVP_DigestVerify`]: https://www.openssl.org/docs/man1.1.1/man3/EVP_DigestVerify.html
599-
#[cfg(any(ossl111, boringssl))]
599+
#[cfg(any(ossl111, boringssl, libressl370))]
600600
pub fn verify_oneshot(&mut self, signature: &[u8], buf: &[u8]) -> Result<bool, ErrorStack> {
601601
unsafe {
602602
let r = ffi::EVP_DigestVerify(
@@ -846,7 +846,7 @@ mod test {
846846
}
847847

848848
#[test]
849-
#[cfg(any(ossl111, boringssl))]
849+
#[cfg(any(ossl111, boringssl, libressl370))]
850850
fn eddsa() {
851851
let key = PKey::generate_ed25519().unwrap();
852852

0 commit comments

Comments
 (0)