Skip to content

Commit

Permalink
Pick up OPENSSL_NO_* with BoringSSL
Browse files Browse the repository at this point in the history
BoringSSL defines OpenSSL-compatible OPENSSL_NO_* values to aid porting.
This removes a ton of boringssl cfg lines that weren't actually
necessary. This addresses part of issue sfackler#1944, though not the version
number half.
  • Loading branch information
davidben committed Jun 4, 2023
1 parent d5cc54b commit 931eb46
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 32 deletions.
10 changes: 5 additions & 5 deletions openssl-sys/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ See rust-openssl documentation for more information:
}
}

for enabled in &enabled {
println!("cargo:rustc-cfg=osslconf=\"{}\"", enabled);
}
println!("cargo:conf={}", enabled.join(","));

if is_boringssl {
println!("cargo:rustc-cfg=boringssl");
println!("cargo:boringssl=true");
Expand All @@ -236,11 +241,6 @@ See rust-openssl documentation for more information:
// We set this for any non-BoringSSL lib.
println!("cargo:rustc-cfg=openssl");

for enabled in &enabled {
println!("cargo:rustc-cfg=osslconf=\"{}\"", enabled);
}
println!("cargo:conf={}", enabled.join(","));

for cfg in cfgs::get(openssl_version, libressl_version) {
println!("cargo:rustc-cfg={}", cfg);
}
Expand Down
1 change: 0 additions & 1 deletion openssl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ fn main() {

if env::var("DEP_OPENSSL_BORINGSSL").is_ok() {
println!("cargo:rustc-cfg=boringssl");
return;
}

if let Ok(v) = env::var("DEP_OPENSSL_LIBRESSL_VERSION_NUMBER") {
Expand Down
20 changes: 10 additions & 10 deletions openssl/src/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,52 +329,52 @@ impl Cipher {
unsafe { CipherRef::from_ptr(ffi::EVP_rc4() as *mut _) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAMELLIA")))]
#[cfg(not(osslconf = "OPENSSL_NO_CAMELLIA"))]
pub fn camellia128_cfb128() -> &'static CipherRef {
unsafe { CipherRef::from_ptr(ffi::EVP_camellia_128_cfb128() as *mut _) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAMELLIA")))]
#[cfg(not(osslconf = "OPENSSL_NO_CAMELLIA"))]
pub fn camellia128_ecb() -> &'static CipherRef {
unsafe { CipherRef::from_ptr(ffi::EVP_camellia_128_ecb() as *mut _) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAMELLIA")))]
#[cfg(not(osslconf = "OPENSSL_NO_CAMELLIA"))]
pub fn camellia192_cfb128() -> &'static CipherRef {
unsafe { CipherRef::from_ptr(ffi::EVP_camellia_192_cfb128() as *mut _) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAMELLIA")))]
#[cfg(not(osslconf = "OPENSSL_NO_CAMELLIA"))]
pub fn camellia192_ecb() -> &'static CipherRef {
unsafe { CipherRef::from_ptr(ffi::EVP_camellia_192_ecb() as *mut _) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAMELLIA")))]
#[cfg(not(osslconf = "OPENSSL_NO_CAMELLIA"))]
pub fn camellia256_cfb128() -> &'static CipherRef {
unsafe { CipherRef::from_ptr(ffi::EVP_camellia_256_cfb128() as *mut _) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAMELLIA")))]
#[cfg(not(osslconf = "OPENSSL_NO_CAMELLIA"))]
pub fn camellia256_ecb() -> &'static CipherRef {
unsafe { CipherRef::from_ptr(ffi::EVP_camellia_256_ecb() as *mut _) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAST")))]
#[cfg(not(osslconf = "OPENSSL_NO_CAST"))]
pub fn cast5_cfb64() -> &'static CipherRef {
unsafe { CipherRef::from_ptr(ffi::EVP_cast5_cfb64() as *mut _) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAST")))]
#[cfg(not(osslconf = "OPENSSL_NO_CAST"))]
pub fn cast5_ecb() -> &'static CipherRef {
unsafe { CipherRef::from_ptr(ffi::EVP_cast5_ecb() as *mut _) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_IDEA")))]
#[cfg(not(osslconf = "OPENSSL_NO_IDEA"))]
pub fn idea_cfb64() -> &'static CipherRef {
unsafe { CipherRef::from_ptr(ffi::EVP_idea_cfb64() as *mut _) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_IDEA")))]
#[cfg(not(osslconf = "OPENSSL_NO_IDEA"))]
pub fn idea_ecb() -> &'static CipherRef {
unsafe { CipherRef::from_ptr(ffi::EVP_idea_ecb() as *mut _) }
}
Expand Down
6 changes: 3 additions & 3 deletions openssl/src/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl EcGroupRef {
/// a term in the polynomial. It will be set to 3 `1`s or 5 `1`s depending on
/// using a trinomial or pentanomial.
#[corresponds(EC_GROUP_get_curve_GF2m)]
#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_EC2M")))]
#[cfg(not(osslconf = "OPENSSL_NO_EC2M"))]
pub fn components_gf2m(
&self,
p: &mut BigNumRef,
Expand Down Expand Up @@ -552,7 +552,7 @@ impl EcPointRef {
/// Places affine coordinates of a curve over a binary field in the provided
/// `x` and `y` `BigNum`s
#[corresponds(EC_POINT_get_affine_coordinates_GF2m)]
#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_EC2M")))]
#[cfg(not(osslconf = "OPENSSL_NO_EC2M"))]
pub fn affine_coordinates_gf2m(
&self,
group: &EcGroupRef,
Expand Down Expand Up @@ -1255,7 +1255,7 @@ mod test {
}

#[test]
#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_EC2M")))]
#[cfg(not(osslconf = "OPENSSL_NO_EC2M"))]
fn is_on_curve() {
let group = EcGroup::from_curve_name(Nid::X9_62_PRIME256V1).unwrap();
let mut ctx = BigNumContext::new().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion openssl/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl MessageDigest {
unsafe { MessageDigest(ffi::EVP_shake256()) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_RMD160")))]
#[cfg(not(osslconf = "OPENSSL_NO_RMD160"))]
pub fn ripemd160() -> MessageDigest {
unsafe { MessageDigest(ffi::EVP_ripemd160()) }
}
Expand Down
4 changes: 2 additions & 2 deletions openssl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub mod base64;
pub mod bn;
pub mod cipher;
pub mod cipher_ctx;
#[cfg(all(not(boringssl), not(libressl), not(osslconf = "OPENSSL_NO_CMS")))]
#[cfg(all(not(libressl), not(osslconf = "OPENSSL_NO_CMS")))]
pub mod cms;
pub mod conf;
pub mod derive;
Expand All @@ -162,7 +162,7 @@ pub mod md;
pub mod md_ctx;
pub mod memcmp;
pub mod nid;
#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_OCSP")))]
#[cfg(not(osslconf = "OPENSSL_NO_OCSP"))]
pub mod ocsp;
pub mod pkcs12;
pub mod pkcs5;
Expand Down
20 changes: 10 additions & 10 deletions openssl/src/symm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ impl Cipher {
unsafe { Cipher(ffi::EVP_bf_ecb()) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_BF")))]
#[cfg(not(osslconf = "OPENSSL_NO_BF"))]
pub fn bf_cfb64() -> Cipher {
unsafe { Cipher(ffi::EVP_bf_cfb64()) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_BF")))]
#[cfg(not(osslconf = "OPENSSL_NO_BF"))]
pub fn bf_ofb() -> Cipher {
unsafe { Cipher(ffi::EVP_bf_ofb()) }
}
Expand Down Expand Up @@ -300,22 +300,22 @@ impl Cipher {
unsafe { Cipher(ffi::EVP_chacha20_poly1305()) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_SEED")))]
#[cfg(not(osslconf = "OPENSSL_NO_SEED"))]
pub fn seed_cbc() -> Cipher {
unsafe { Cipher(ffi::EVP_seed_cbc()) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_SEED")))]
#[cfg(not(osslconf = "OPENSSL_NO_SEED"))]
pub fn seed_cfb128() -> Cipher {
unsafe { Cipher(ffi::EVP_seed_cfb128()) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_SEED")))]
#[cfg(not(osslconf = "OPENSSL_NO_SEED"))]
pub fn seed_ecb() -> Cipher {
unsafe { Cipher(ffi::EVP_seed_ecb()) }
}

#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_SEED")))]
#[cfg(not(osslconf = "OPENSSL_NO_SEED"))]
pub fn seed_ofb() -> Cipher {
unsafe { Cipher(ffi::EVP_seed_ofb()) }
}
Expand Down Expand Up @@ -1534,7 +1534,7 @@ mod tests {
}

#[test]
#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_SEED", ossl300)))]
#[cfg(not(any(osslconf = "OPENSSL_NO_SEED", ossl300)))]
fn test_seed_cbc() {
#[cfg(ossl300)]
let _provider = crate::provider::Provider::try_load(None, "legacy", true).unwrap();
Expand All @@ -1548,7 +1548,7 @@ mod tests {
}

#[test]
#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_SEED", ossl300)))]
#[cfg(not(any(osslconf = "OPENSSL_NO_SEED", ossl300)))]
fn test_seed_cfb128() {
#[cfg(ossl300)]
let _provider = crate::provider::Provider::try_load(None, "legacy", true).unwrap();
Expand All @@ -1562,7 +1562,7 @@ mod tests {
}

#[test]
#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_SEED", ossl300)))]
#[cfg(not(any(osslconf = "OPENSSL_NO_SEED", ossl300)))]
fn test_seed_ecb() {
#[cfg(ossl300)]
let _provider = crate::provider::Provider::try_load(None, "legacy", true).unwrap();
Expand All @@ -1576,7 +1576,7 @@ mod tests {
}

#[test]
#[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_SEED", ossl300)))]
#[cfg(not(any(osslconf = "OPENSSL_NO_SEED", ossl300)))]
fn test_seed_ofb() {
#[cfg(ossl300)]
let _provider = crate::provider::Provider::try_load(None, "legacy", true).unwrap();
Expand Down

0 comments on commit 931eb46

Please sign in to comment.