Skip to content

Commit 688321b

Browse files
authored
Add support for AWS Libcrypto (AWS-LC) (pyca#12681)
* Add support for AWS-LC * Add GitHub CI Integration * Fix flake * Remove some untested functions since we don't support DH fully at the moment * Bindgen on Ubuntu 22.04 should work fine now * Feedback: Update Cargo.toml directly * Feeback: multi-line C comments, fixed similar spot * Combine logic * Feedback: HMAC hash check * cleanup * Indentation correction * Update aws-lc CI testing to use v1.49.0 tag * Rebased
1 parent 5161fb2 commit 688321b

File tree

42 files changed

+389
-138
lines changed

Some content is hidden

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

42 files changed

+389
-138
lines changed

.github/bin/build_openssl.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,14 @@ elif [[ "${TYPE}" == "boringssl" ]]; then
6161
rm -rf "${OSSL_PATH}/bin"
6262
popd
6363
rm -rf boringssl/
64+
elif [[ "${TYPE}" == "aws-lc" ]]; then
65+
git clone https://github.com/aws/aws-lc.git
66+
pushd aws-lc
67+
git checkout "${VERSION}"
68+
cmake -B build -DCMAKE_INSTALL_PREFIX="${OSSL_PATH}"
69+
make -C build -j"$(nproc)" install
70+
# delete binaries we don't need
71+
rm -rf "${OSSL_PATH:?}/bin"
72+
popd # aws-lc
73+
rm -rf aws-lc/
6474
fi

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ jobs:
4747
- {VERSION: "3.12", NOXSESSION: "tests-randomorder"}
4848
# Latest commit on the BoringSSL main branch, as of Apr 16, 2025.
4949
- {VERSION: "3.12", NOXSESSION: "rust,tests", OPENSSL: {TYPE: "boringssl", VERSION: "23018360710de333b3343e63cbb3bd2dceb3287d"}}
50+
# Latest tag of AWS-LC main branch, as of March 28, 2025.
51+
- {VERSION: "3.12", NOXSESSION: "rust,tests", OPENSSL: {TYPE: "aws-lc", VERSION: "v1.49.0"}}
5052
# Latest commit on the OpenSSL master branch, as of Apr 16, 2025.
5153
- {VERSION: "3.12", NOXSESSION: "tests", OPENSSL: {TYPE: "openssl", VERSION: "24bc185439a950dc4427be10ec60231a923840ad"}}
5254
# Builds with various Rust versions. Includes MSRV and next
@@ -121,7 +123,7 @@ jobs:
121123
echo "RUSTFLAGS=-Clink-arg=-Wl,-rpath=${OSSL_PATH}/lib -Clink-arg=-Wl,-rpath=${OSSL_PATH}/lib64" >> $GITHUB_ENV
122124
if: matrix.PYTHON.OPENSSL
123125
- run: sudo apt-get install -y bindgen
124-
if: matrix.PYTHON.OPENSSL.TYPE == 'boringssl'
126+
if: matrix.PYTHON.OPENSSL.TYPE == 'boringssl' || matrix.PYTHON.OPENSSL.TYPE == 'aws-lc'
125127
- name: Cache rust and pip
126128
uses: ./.github/actions/cache
127129
timeout-minutes: 2

src/_cffi_src/openssl/bignum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"""
3636

3737
CUSTOMIZATIONS = """
38-
#if CRYPTOGRAPHY_IS_BORINGSSL
38+
#if CRYPTOGRAPHY_IS_BORINGSSL || CRYPTOGRAPHY_IS_AWSLC
3939
static const long Cryptography_HAS_PRIME_CHECKS = 0;
4040
int (*BN_prime_checks_for_size)(int) = NULL;
4141
#else

src/_cffi_src/openssl/bio.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"""
3636

3737
CUSTOMIZATIONS = """
38-
#if CRYPTOGRAPHY_IS_LIBRESSL || CRYPTOGRAPHY_IS_BORINGSSL
38+
#if CRYPTOGRAPHY_IS_LIBRESSL || CRYPTOGRAPHY_IS_BORINGSSL \
39+
|| CRYPTOGRAPHY_IS_AWSLC
3940
4041
#if !defined(_WIN32)
4142
#include <sys/socket.h>

src/_cffi_src/openssl/cryptography.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
#define CRYPTOGRAPHY_IS_BORINGSSL 0
4343
#endif
4444
45+
#if defined(OPENSSL_IS_AWSLC)
46+
#define CRYPTOGRAPHY_IS_AWSLC 1
47+
#else
48+
#define CRYPTOGRAPHY_IS_AWSLC 0
49+
#endif
50+
51+
4552
#if OPENSSL_VERSION_NUMBER < 0x10101050
4653
#error "pyca/cryptography MUST be linked with Openssl 1.1.1e or later"
4754
#endif

src/_cffi_src/openssl/engine.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
int ENGINE_free(ENGINE *);
2929
const char *ENGINE_get_name(const ENGINE *);
3030
31-
// These bindings are unused by cryptography or pyOpenSSL but are present
32-
// for advanced users who need them.
31+
/*
32+
These bindings are unused by cryptography or pyOpenSSL but are present
33+
for advanced users who need them.
34+
*/
3335
int ENGINE_ctrl_cmd_string(ENGINE *, const char *, const char *, int);
3436
void ENGINE_load_builtin_engines(void);
3537
EVP_PKEY *ENGINE_load_private_key(ENGINE *, const char *, UI_METHOD *, void *);
@@ -40,12 +42,16 @@
4042
#ifdef OPENSSL_NO_ENGINE
4143
static const long Cryptography_HAS_ENGINE = 0;
4244
43-
#if CRYPTOGRAPHY_IS_BORINGSSL
45+
#if CRYPTOGRAPHY_IS_BORINGSSL || CRYPTOGRAPHY_IS_AWSLC
4446
typedef void UI_METHOD;
4547
#endif
4648
47-
/* Despite being OPENSSL_NO_ENGINE, BoringSSL/LibreSSL define these symbols. */
48-
#if !CRYPTOGRAPHY_IS_BORINGSSL && !CRYPTOGRAPHY_IS_LIBRESSL
49+
/*
50+
Despite being OPENSSL_NO_ENGINE,
51+
BoringSSL/LibreSSL/AWS-LC define these symbols.
52+
*/
53+
#if !CRYPTOGRAPHY_IS_BORINGSSL && !CRYPTOGRAPHY_IS_LIBRESSL \
54+
&& !CRYPTOGRAPHY_IS_AWSLC
4955
int (*ENGINE_free)(ENGINE *) = NULL;
5056
void (*ENGINE_load_builtin_engines)(void) = NULL;
5157
#endif

src/_cffi_src/openssl/err.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"""
3737

3838
CUSTOMIZATIONS = """
39-
#if CRYPTOGRAPHY_IS_BORINGSSL
39+
#if CRYPTOGRAPHY_IS_BORINGSSL || CRYPTOGRAPHY_IS_AWSLC
4040
static const int EVP_F_EVP_ENCRYPTFINAL_EX = 0;
4141
static const int EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH = 0;
4242
#endif

src/_cffi_src/openssl/ssl.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
static const long Cryptography_HAS_SSL_ST;
1313
static const long Cryptography_HAS_TLS_ST;
1414
static const long Cryptography_HAS_TLSv1_3_FUNCTIONS;
15+
static const long Cryptography_HAS_TLSv1_3_HS_FUNCTIONS;
1516
static const long Cryptography_HAS_SIGALGS;
1617
static const long Cryptography_HAS_PSK;
1718
static const long Cryptography_HAS_PSK_TLSv1_3;
@@ -477,7 +478,8 @@
477478
478479
/* in OpenSSL 1.1.0 the SSL_ST values were renamed to TLS_ST and several were
479480
removed */
480-
#if CRYPTOGRAPHY_IS_LIBRESSL || CRYPTOGRAPHY_IS_BORINGSSL
481+
#if CRYPTOGRAPHY_IS_LIBRESSL || CRYPTOGRAPHY_IS_BORINGSSL \
482+
|| CRYPTOGRAPHY_IS_AWSLC
481483
static const long Cryptography_HAS_SSL_ST = 1;
482484
#else
483485
static const long Cryptography_HAS_SSL_ST = 0;
@@ -494,7 +496,8 @@
494496
static const long TLS_ST_OK = 0;
495497
#endif
496498
497-
#if CRYPTOGRAPHY_IS_LIBRESSL || CRYPTOGRAPHY_IS_BORINGSSL
499+
#if CRYPTOGRAPHY_IS_LIBRESSL || CRYPTOGRAPHY_IS_BORINGSSL \
500+
|| CRYPTOGRAPHY_IS_AWSLC
498501
static const long Cryptography_HAS_DTLS_GET_DATA_MTU = 0;
499502
size_t (*DTLS_get_data_mtu)(SSL *) = NULL;
500503
#else
@@ -589,9 +592,15 @@
589592
590593
#if CRYPTOGRAPHY_IS_BORINGSSL
591594
static const long Cryptography_HAS_TLSv1_3_FUNCTIONS = 0;
595+
int (*SSL_CTX_set_ciphersuites)(SSL_CTX *, const char *) = NULL;
596+
#else
597+
static const long Cryptography_HAS_TLSv1_3_FUNCTIONS = 1;
598+
#endif
592599
600+
#if CRYPTOGRAPHY_IS_BORINGSSL || CRYPTOGRAPHY_IS_AWSLC
601+
static const long Cryptography_HAS_TLSv1_3_HS_FUNCTIONS = 0;
593602
static const long SSL_VERIFY_POST_HANDSHAKE = 0;
594-
int (*SSL_CTX_set_ciphersuites)(SSL_CTX *, const char *) = NULL;
603+
595604
int (*SSL_verify_client_post_handshake)(SSL *) = NULL;
596605
void (*SSL_CTX_set_post_handshake_auth)(SSL_CTX *, int) = NULL;
597606
void (*SSL_set_post_handshake_auth)(SSL *, int) = NULL;
@@ -600,10 +609,10 @@
600609
int (*SSL_read_early_data)(SSL *, void *, size_t, size_t *) = NULL;
601610
int (*SSL_CTX_set_max_early_data)(SSL_CTX *, uint32_t) = NULL;
602611
#else
603-
static const long Cryptography_HAS_TLSv1_3_FUNCTIONS = 1;
612+
static const long Cryptography_HAS_TLSv1_3_HS_FUNCTIONS = 1;
604613
#endif
605614
606-
#if CRYPTOGRAPHY_IS_BORINGSSL
615+
#if CRYPTOGRAPHY_IS_BORINGSSL || CRYPTOGRAPHY_IS_AWSLC
607616
static const long Cryptography_HAS_SSL_COOKIE = 0;
608617
609618
static const long SSL_OP_COOKIE_EXCHANGE = 0;
@@ -623,7 +632,8 @@
623632
#else
624633
static const long Cryptography_HAS_SSL_COOKIE = 1;
625634
#endif
626-
#if CRYPTOGRAPHY_IS_LIBRESSL || CRYPTOGRAPHY_IS_BORINGSSL
635+
#if CRYPTOGRAPHY_IS_LIBRESSL || CRYPTOGRAPHY_IS_BORINGSSL \
636+
|| CRYPTOGRAPHY_IS_AWSLC
627637
static const long Cryptography_HAS_PSK_TLSv1_3 = 0;
628638
void (*SSL_CTX_set_psk_find_session_callback)(SSL_CTX *,
629639
int (*)(
@@ -646,7 +656,7 @@
646656
int (*SSL_SESSION_set1_master_key)(SSL_SESSION *, const unsigned char *,
647657
size_t) = NULL;
648658
int (*SSL_SESSION_set_cipher)(SSL_SESSION *, const SSL_CIPHER *) = NULL;
649-
#if !CRYPTOGRAPHY_IS_BORINGSSL
659+
#if !CRYPTOGRAPHY_IS_BORINGSSL && !CRYPTOGRAPHY_IS_AWSLC
650660
int (*SSL_SESSION_set_protocol_version)(SSL_SESSION *, int) = NULL;
651661
#endif
652662
SSL_SESSION *(*Cryptography_SSL_SESSION_new)(void) = NULL;

src/cryptography/hazmat/backends/openssl/backend.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,19 @@ def hmac_supported(self, algorithm: hashes.HashAlgorithm) -> bool:
132132
# FIPS mode still allows SHA1 for HMAC
133133
if self._fips_enabled and isinstance(algorithm, hashes.SHA1):
134134
return True
135-
135+
if rust_openssl.CRYPTOGRAPHY_IS_AWSLC:
136+
return isinstance(
137+
algorithm,
138+
(
139+
hashes.SHA1,
140+
hashes.SHA224,
141+
hashes.SHA256,
142+
hashes.SHA384,
143+
hashes.SHA512,
144+
hashes.SHA512_224,
145+
hashes.SHA512_256,
146+
),
147+
)
136148
return self.hash_supported(algorithm)
137149

138150
def cipher_supported(self, cipher: CipherAlgorithm, mode: Mode) -> bool:
@@ -236,7 +248,10 @@ def elliptic_curve_exchange_algorithm_supported(
236248
)
237249

238250
def dh_supported(self) -> bool:
239-
return not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL
251+
return (
252+
not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL
253+
and not rust_openssl.CRYPTOGRAPHY_IS_AWSLC
254+
)
240255

241256
def dh_x942_serialization_supported(self) -> bool:
242257
return self._lib.Cryptography_HAS_EVP_PKEY_DHX == 1
@@ -252,6 +267,7 @@ def x448_supported(self) -> bool:
252267
return (
253268
not rust_openssl.CRYPTOGRAPHY_IS_LIBRESSL
254269
and not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL
270+
and not rust_openssl.CRYPTOGRAPHY_IS_AWSLC
255271
)
256272

257273
def ed25519_supported(self) -> bool:
@@ -265,6 +281,7 @@ def ed448_supported(self) -> bool:
265281
return (
266282
not rust_openssl.CRYPTOGRAPHY_IS_LIBRESSL
267283
and not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL
284+
and not rust_openssl.CRYPTOGRAPHY_IS_AWSLC
268285
)
269286

270287
def ecdsa_deterministic_supported(self) -> bool:
@@ -279,7 +296,10 @@ def poly1305_supported(self) -> bool:
279296
return True
280297

281298
def pkcs7_supported(self) -> bool:
282-
return not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL
299+
return (
300+
not rust_openssl.CRYPTOGRAPHY_IS_BORINGSSL
301+
and not rust_openssl.CRYPTOGRAPHY_IS_AWSLC
302+
)
283303

284304

285305
backend = Backend()

src/cryptography/hazmat/bindings/_rust/openssl/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ __all__ = [
4747

4848
CRYPTOGRAPHY_IS_LIBRESSL: bool
4949
CRYPTOGRAPHY_IS_BORINGSSL: bool
50+
CRYPTOGRAPHY_IS_AWSLC: bool
5051
CRYPTOGRAPHY_OPENSSL_300_OR_GREATER: bool
5152
CRYPTOGRAPHY_OPENSSL_309_OR_GREATER: bool
5253
CRYPTOGRAPHY_OPENSSL_320_OR_GREATER: bool

0 commit comments

Comments
 (0)