Skip to content

Commit c3b714e

Browse files
committed
Add support for aws-lc-sys or aws-lc-fips-sys
1 parent a5419bc commit c3b714e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+484
-405
lines changed

openssl-sys/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ rust-version = "1.63.0"
1818
[features]
1919
vendored = ['openssl-src']
2020
unstable_boringssl = ['bssl-sys']
21+
aws-lc = ['aws-lc-sys']
22+
aws-lc-fips = ['aws-lc-fips-sys']
2123

2224
[dependencies]
2325
libc = "0.2"
2426
bssl-sys = { version = "0.1.0", optional = true }
27+
aws-lc-sys = { version = "0", features = ["ssl"], optional = true }
28+
aws-lc-fips-sys = { version = "0", features = ["ssl", "bindgen"], optional = true }
2529

2630
[build-dependencies]
2731
bindgen = { version = "0.69.0", optional = true, features = ["experimental"] }

openssl-sys/build/main.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,47 @@ fn check_ssl_kind() {
7171
// BoringSSL does not have any build logic, exit early
7272
std::process::exit(0);
7373
}
74+
75+
let is_aws_lc = cfg!(feature = "aws-lc");
76+
let is_aws_lc_fips = cfg!(feature = "aws-lc-fips");
77+
78+
if is_aws_lc || is_aws_lc_fips {
79+
println!("cargo:rustc-cfg=awslc");
80+
println!("cargo:awslc=true");
81+
82+
let env_var_prefix = match (is_aws_lc, is_aws_lc_fips) {
83+
(true, false) => "DEP_AWS_LC_",
84+
(false, true) => "DEP_AWS_LC_FIPS_",
85+
_ => {
86+
panic!("aws-lc and aws-lc-fips are mutually exclusive features!");
87+
}
88+
};
89+
90+
let mut version = None;
91+
for (name, _) in std::env::vars() {
92+
if let Some(name) = name.strip_prefix(env_var_prefix) {
93+
if let Some(name) = name.strip_suffix("_INCLUDE") {
94+
version = Some(name.to_owned());
95+
break;
96+
}
97+
}
98+
}
99+
let version = version.expect("aws-lc version detected");
100+
101+
if let Ok(vars) = std::env::var(format!("{env_var_prefix}{version}_CONF")) {
102+
for var in vars.split(',') {
103+
println!("cargo:rustc-cfg=osslconf=\"{var}\"");
104+
}
105+
println!("cargo:conf={vars}");
106+
}
107+
108+
if let Ok(val) = std::env::var(format!("{env_var_prefix}{version}_INCLUDE")) {
109+
println!("cargo:include={val}");
110+
}
111+
112+
// AWS-LC does not have any build logic, exit early
113+
std::process::exit(0);
114+
}
74115
}
75116

76117
fn main() {
@@ -79,6 +120,7 @@ fn main() {
79120
println!("cargo:rustc-check-cfg=cfg(openssl)");
80121
println!("cargo:rustc-check-cfg=cfg(libressl)");
81122
println!("cargo:rustc-check-cfg=cfg(boringssl)");
123+
println!("cargo:rustc-check-cfg=cfg(awslc)");
82124

83125
println!("cargo:rustc-check-cfg=cfg(libressl250)");
84126
println!("cargo:rustc-check-cfg=cfg(libressl251)");

openssl-sys/src/evp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub const PKCS5_SALT_LEN: c_int = 8;
77
pub const PKCS12_DEFAULT_ITER: c_int = 2048;
88

99
pub const EVP_PKEY_RSA: c_int = NID_rsaEncryption;
10-
#[cfg(any(ossl111, libressl310, boringssl))]
10+
#[cfg(any(ossl111, libressl310, boringssl, awslc))]
1111
pub const EVP_PKEY_RSA_PSS: c_int = NID_rsassaPss;
1212
pub const EVP_PKEY_DSA: c_int = NID_dsa;
1313
pub const EVP_PKEY_DH: c_int = NID_dhKeyAgreement;
@@ -313,7 +313,7 @@ pub unsafe fn EVP_PKEY_CTX_add1_hkdf_info(
313313
)
314314
}
315315

316-
#[cfg(all(not(ossl300), not(boringssl)))]
316+
#[cfg(not(any(ossl300, boringssl, awslc)))]
317317
pub unsafe fn EVP_PKEY_CTX_set_signature_md(cxt: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int {
318318
EVP_PKEY_CTX_ctrl(
319319
cxt,

openssl-sys/src/handwritten/ec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ extern "C" {
103103

104104
pub fn EC_POINT_dup(p: *const EC_POINT, group: *const EC_GROUP) -> *mut EC_POINT;
105105

106-
#[cfg(any(ossl111, boringssl, libressl350))]
106+
#[cfg(any(ossl111, boringssl, libressl350, awslc))]
107107
pub fn EC_POINT_get_affine_coordinates(
108108
group: *const EC_GROUP,
109109
p: *const EC_POINT,

openssl-sys/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ mod boringssl {
2929
#[cfg(boringssl)]
3030
pub use boringssl::*;
3131

32+
#[cfg(any(feature = "aws-lc", feature = "aws-lc-fips-sys"))]
33+
mod aws_lc {
34+
#[cfg(feature = "aws-lc-fips")]
35+
extern crate aws_lc_fips_sys as aws_lc;
36+
#[cfg(feature = "aws-lc")]
37+
extern crate aws_lc_sys as aws_lc;
38+
pub use aws_lc::*;
39+
40+
// TODO: AWS-LC doesn't currently expose this in it's public headers
41+
extern "C" {
42+
pub fn OCSP_ONEREQ_free(r: *mut OCSP_ONEREQ);
43+
}
44+
}
45+
#[cfg(any(feature = "aws-lc", feature = "aws-lc-fips-sys"))]
46+
pub use aws_lc::*;
47+
3248
#[cfg(openssl)]
3349
#[path = "."]
3450
mod openssl {

openssl-sys/src/ocsp.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ pub const OCSP_REVOKED_STATUS_CESSATIONOFOPERATION: c_int = 5;
1010
pub const OCSP_REVOKED_STATUS_CERTIFICATEHOLD: c_int = 6;
1111
pub const OCSP_REVOKED_STATUS_REMOVEFROMCRL: c_int = 8;
1212

13-
pub const OCSP_NOCERTS: c_ulong = 0x1;
14-
pub const OCSP_NOINTERN: c_ulong = 0x2;
15-
pub const OCSP_NOSIGS: c_ulong = 0x4;
16-
pub const OCSP_NOCHAIN: c_ulong = 0x8;
17-
pub const OCSP_NOVERIFY: c_ulong = 0x10;
18-
pub const OCSP_NOEXPLICIT: c_ulong = 0x20;
19-
pub const OCSP_NOCASIGN: c_ulong = 0x40;
20-
pub const OCSP_NODELEGATED: c_ulong = 0x80;
21-
pub const OCSP_NOCHECKS: c_ulong = 0x100;
22-
pub const OCSP_TRUSTOTHER: c_ulong = 0x200;
23-
pub const OCSP_RESPID_KEY: c_ulong = 0x400;
24-
pub const OCSP_NOTIME: c_ulong = 0x800;
13+
pub const OCSP_NOCERTS: c_int = 0x1;
14+
pub const OCSP_NOINTERN: c_int = 0x2;
15+
pub const OCSP_NOSIGS: c_int = 0x4;
16+
pub const OCSP_NOCHAIN: c_int = 0x8;
17+
pub const OCSP_NOVERIFY: c_int = 0x10;
18+
pub const OCSP_NOEXPLICIT: c_int = 0x20;
19+
pub const OCSP_NOCASIGN: c_int = 0x40;
20+
pub const OCSP_NODELEGATED: c_int = 0x80;
21+
pub const OCSP_NOCHECKS: c_int = 0x100;
22+
pub const OCSP_TRUSTOTHER: c_int = 0x200;
23+
pub const OCSP_RESPID_KEY: c_int = 0x400;
24+
pub const OCSP_NOTIME: c_int = 0x800;
2525

2626
pub const OCSP_RESPONSE_STATUS_SUCCESSFUL: c_int = 0;
2727
pub const OCSP_RESPONSE_STATUS_MALFORMEDREQUEST: c_int = 1;

openssl/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ v111 = []
2121
vendored = ['ffi/vendored']
2222
bindgen = ['ffi/bindgen']
2323
unstable_boringssl = ["ffi/unstable_boringssl"]
24+
aws-lc = ["ffi/aws-lc"]
25+
aws-lc-fips = ["ffi/aws-lc-fips"]
2426
default = []
2527

2628
[dependencies]

openssl/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fn main() {
1111

1212
println!("cargo:rustc-check-cfg=cfg(libressl)");
1313
println!("cargo:rustc-check-cfg=cfg(boringssl)");
14+
println!("cargo:rustc-check-cfg=cfg(awslc)");
1415

1516
println!("cargo:rustc-check-cfg=cfg(libressl250)");
1617
println!("cargo:rustc-check-cfg=cfg(libressl251)");
@@ -53,6 +54,10 @@ fn main() {
5354
println!("cargo:rustc-cfg=boringssl");
5455
}
5556

57+
if env::var("DEP_OPENSSL_AWSLC").is_ok() {
58+
println!("cargo:rustc-cfg=awslc");
59+
}
60+
5661
if let Ok(v) = env::var("DEP_OPENSSL_LIBRESSL_VERSION_NUMBER") {
5762
let version = u64::from_str_radix(&v, 16).unwrap();
5863

openssl/src/aes.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//! # Examples
2424
2525
#![cfg_attr(
26-
all(not(boringssl), not(osslconf = "OPENSSL_NO_DEPRECATED_3_0")),
26+
all(not(boringssl), not(awslc), not(osslconf = "OPENSSL_NO_DEPRECATED_3_0")),
2727
doc = r#"\
2828
## AES IGE
2929
```rust
@@ -65,7 +65,7 @@ use libc::{c_int, c_uint};
6565
use std::mem::MaybeUninit;
6666
use std::ptr;
6767

68-
#[cfg(not(boringssl))]
68+
#[cfg(not(any(boringssl, awslc)))]
6969
use crate::symm::Mode;
7070
use openssl_macros::corresponds;
7171

@@ -77,7 +77,7 @@ pub struct KeyError(());
7777
pub struct AesKey(ffi::AES_KEY);
7878

7979
cfg_if! {
80-
if #[cfg(boringssl)] {
80+
if #[cfg(any(boringssl, awslc))] {
8181
type AesBitType = c_uint;
8282
type AesSizeType = usize;
8383
} else {
@@ -155,7 +155,7 @@ impl AesKey {
155155
///
156156
/// Panics if `in_` is not the same length as `out`, if that length is not a multiple of 16, or if
157157
/// `iv` is not at least 32 bytes.
158-
#[cfg(not(boringssl))]
158+
#[cfg(not(any(boringssl, awslc)))]
159159
#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
160160
#[corresponds(AES_ige_encrypt)]
161161
pub fn aes_ige(in_: &[u8], out: &mut [u8], key: &AesKey, iv: &mut [u8], mode: Mode) {
@@ -263,12 +263,12 @@ mod test {
263263
use hex::FromHex;
264264

265265
use super::*;
266-
#[cfg(not(boringssl))]
266+
#[cfg(not(any(boringssl, awslc)))]
267267
use crate::symm::Mode;
268268

269269
// From https://www.mgp25.com/AESIGE/
270270
#[test]
271-
#[cfg(not(boringssl))]
271+
#[cfg(not(any(boringssl, awslc)))]
272272
#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
273273
fn ige_vector_1() {
274274
let raw_key = "000102030405060708090A0B0C0D0E0F";

openssl/src/asn1.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl Asn1Type {
165165
/// [`diff`]: struct.Asn1TimeRef.html#method.diff
166166
/// [`Asn1TimeRef`]: struct.Asn1TimeRef.html
167167
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
168-
#[cfg(any(ossl102, boringssl))]
168+
#[cfg(any(ossl102, boringssl, awslc))]
169169
pub struct TimeDiff {
170170
/// Difference in days
171171
pub days: c_int,
@@ -198,7 +198,7 @@ foreign_type_and_impl_send_sync! {
198198
impl Asn1TimeRef {
199199
/// Find difference between two times
200200
#[corresponds(ASN1_TIME_diff)]
201-
#[cfg(any(ossl102, boringssl))]
201+
#[cfg(any(ossl102, boringssl, awslc))]
202202
pub fn diff(&self, compare: &Self) -> Result<TimeDiff, ErrorStack> {
203203
let mut days = 0;
204204
let mut secs = 0;
@@ -214,7 +214,7 @@ impl Asn1TimeRef {
214214

215215
/// Compare two times
216216
#[corresponds(ASN1_TIME_compare)]
217-
#[cfg(any(ossl102, boringssl))]
217+
#[cfg(any(ossl102, boringssl, awslc))]
218218
pub fn compare(&self, other: &Self) -> Result<Ordering, ErrorStack> {
219219
let d = self.diff(other)?;
220220
if d.days > 0 || d.secs > 0 {
@@ -228,7 +228,7 @@ impl Asn1TimeRef {
228228
}
229229
}
230230

231-
#[cfg(any(ossl102, boringssl))]
231+
#[cfg(any(ossl102, boringssl, awslc))]
232232
impl PartialEq for Asn1TimeRef {
233233
fn eq(&self, other: &Asn1TimeRef) -> bool {
234234
self.diff(other)
@@ -237,7 +237,7 @@ impl PartialEq for Asn1TimeRef {
237237
}
238238
}
239239

240-
#[cfg(any(ossl102, boringssl))]
240+
#[cfg(any(ossl102, boringssl, awslc))]
241241
impl PartialEq<Asn1Time> for Asn1TimeRef {
242242
fn eq(&self, other: &Asn1Time) -> bool {
243243
self.diff(other)
@@ -246,7 +246,7 @@ impl PartialEq<Asn1Time> for Asn1TimeRef {
246246
}
247247
}
248248

249-
#[cfg(any(ossl102, boringssl))]
249+
#[cfg(any(ossl102, boringssl, awslc))]
250250
impl PartialEq<Asn1Time> for &Asn1TimeRef {
251251
fn eq(&self, other: &Asn1Time) -> bool {
252252
self.diff(other)
@@ -255,21 +255,21 @@ impl PartialEq<Asn1Time> for &Asn1TimeRef {
255255
}
256256
}
257257

258-
#[cfg(any(ossl102, boringssl))]
258+
#[cfg(any(ossl102, boringssl, awslc))]
259259
impl PartialOrd for Asn1TimeRef {
260260
fn partial_cmp(&self, other: &Asn1TimeRef) -> Option<Ordering> {
261261
self.compare(other).ok()
262262
}
263263
}
264264

265-
#[cfg(any(ossl102, boringssl))]
265+
#[cfg(any(ossl102, boringssl, awslc))]
266266
impl PartialOrd<Asn1Time> for Asn1TimeRef {
267267
fn partial_cmp(&self, other: &Asn1Time) -> Option<Ordering> {
268268
self.compare(other).ok()
269269
}
270270
}
271271

272-
#[cfg(any(ossl102, boringssl))]
272+
#[cfg(any(ossl102, boringssl, awslc))]
273273
impl PartialOrd<Asn1Time> for &Asn1TimeRef {
274274
fn partial_cmp(&self, other: &Asn1Time) -> Option<Ordering> {
275275
self.compare(other).ok()
@@ -353,7 +353,7 @@ impl Asn1Time {
353353
///
354354
/// Requires BoringSSL or OpenSSL 1.1.1 or newer.
355355
#[corresponds(ASN1_TIME_set_string_X509)]
356-
#[cfg(any(ossl111, boringssl))]
356+
#[cfg(any(ossl111, boringssl, awslc))]
357357
pub fn from_str_x509(s: &str) -> Result<Asn1Time, ErrorStack> {
358358
unsafe {
359359
let s = CString::new(s).unwrap();
@@ -366,7 +366,7 @@ impl Asn1Time {
366366
}
367367
}
368368

369-
#[cfg(any(ossl102, boringssl))]
369+
#[cfg(any(ossl102, boringssl, awslc))]
370370
impl PartialEq for Asn1Time {
371371
fn eq(&self, other: &Asn1Time) -> bool {
372372
self.diff(other)
@@ -375,7 +375,7 @@ impl PartialEq for Asn1Time {
375375
}
376376
}
377377

378-
#[cfg(any(ossl102, boringssl))]
378+
#[cfg(any(ossl102, boringssl, awslc))]
379379
impl PartialEq<Asn1TimeRef> for Asn1Time {
380380
fn eq(&self, other: &Asn1TimeRef) -> bool {
381381
self.diff(other)
@@ -384,7 +384,7 @@ impl PartialEq<Asn1TimeRef> for Asn1Time {
384384
}
385385
}
386386

387-
#[cfg(any(ossl102, boringssl))]
387+
#[cfg(any(ossl102, boringssl, awslc))]
388388
impl<'a> PartialEq<&'a Asn1TimeRef> for Asn1Time {
389389
fn eq(&self, other: &&'a Asn1TimeRef) -> bool {
390390
self.diff(other)
@@ -393,21 +393,21 @@ impl<'a> PartialEq<&'a Asn1TimeRef> for Asn1Time {
393393
}
394394
}
395395

396-
#[cfg(any(ossl102, boringssl))]
396+
#[cfg(any(ossl102, boringssl, awslc))]
397397
impl PartialOrd for Asn1Time {
398398
fn partial_cmp(&self, other: &Asn1Time) -> Option<Ordering> {
399399
self.compare(other).ok()
400400
}
401401
}
402402

403-
#[cfg(any(ossl102, boringssl))]
403+
#[cfg(any(ossl102, boringssl, awslc))]
404404
impl PartialOrd<Asn1TimeRef> for Asn1Time {
405405
fn partial_cmp(&self, other: &Asn1TimeRef) -> Option<Ordering> {
406406
self.compare(other).ok()
407407
}
408408
}
409409

410-
#[cfg(any(ossl102, boringssl))]
410+
#[cfg(any(ossl102, boringssl, awslc))]
411411
impl<'a> PartialOrd<&'a Asn1TimeRef> for Asn1Time {
412412
fn partial_cmp(&self, other: &&'a Asn1TimeRef) -> Option<Ordering> {
413413
self.compare(other).ok()
@@ -737,7 +737,7 @@ impl fmt::Debug for Asn1ObjectRef {
737737
}
738738

739739
cfg_if! {
740-
if #[cfg(any(ossl110, libressl273, boringssl))] {
740+
if #[cfg(any(ossl110, libressl273, boringssl, awslc))] {
741741
use ffi::ASN1_STRING_get0_data;
742742
} else {
743743
#[allow(bad_style)]
@@ -808,7 +808,7 @@ mod tests {
808808
}
809809

810810
#[test]
811-
#[cfg(any(ossl102, boringssl))]
811+
#[cfg(any(ossl102, boringssl, awslc))]
812812
fn time_eq() {
813813
let a = Asn1Time::from_str("99991231235959Z").unwrap();
814814
let b = Asn1Time::from_str("99991231235959Z").unwrap();
@@ -827,7 +827,7 @@ mod tests {
827827
}
828828

829829
#[test]
830-
#[cfg(any(ossl102, boringssl))]
830+
#[cfg(any(ossl102, boringssl, awslc))]
831831
fn time_ord() {
832832
let a = Asn1Time::from_str("99991231235959Z").unwrap();
833833
let b = Asn1Time::from_str("99991231235959Z").unwrap();

0 commit comments

Comments
 (0)