Skip to content

Commit 23650a9

Browse files
authored
fix: re-enable aes_gcm_192 (#1143)
1 parent 0e2859d commit 23650a9

6 files changed

Lines changed: 36 additions & 28 deletions

File tree

AwsCryptographicMaterialProviders/runtimes/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ readme = "README.md"
1515
[dependencies]
1616
aws-config = "1.5.11"
1717
aws-lc-rs = "1.12.0"
18-
aws-lc-sys = "0.22.0"
18+
aws-lc-sys = "0.24.0"
1919
aws-sdk-dynamodb = "1.55.0"
2020
aws-sdk-kms = "1.51.0"
2121
aws-smithy-runtime-api = {version = "1.7.3", features = ["client"] }

AwsCryptographicMaterialProviders/runtimes/rust/src/aes_gcm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ impl AES_GCM {
5252
))
5353
} else if *self.keyLength() == 32i32 {
5454
Ok(&aws_lc_rs::aead::AES_256_GCM)
55+
} else if *self.keyLength() == 24i32 {
56+
Ok(&aws_lc_rs::aead::AES_192_GCM)
5557
} else if *self.keyLength() == 16i32 {
5658
Ok(&aws_lc_rs::aead::AES_128_GCM)
5759
} else {
5860
Err(format!(
59-
"Key length of {} not supported in Rust. Key length must be 16 or 32.",
61+
"Key length of {} not supported in Rust. Key length must be 16, 24 or 32.",
6062
self.keyLength()
6163
))
6264
}

AwsCryptographicMaterialProviders/runtimes/rust/src/ecdh.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ pub mod ECDH {
7474
const ELEM_MAX_BYTES: usize = (ELEM_MAX_BITS + 7) / 8;
7575
const PUBLIC_KEY_MAX_LEN: usize = 1 + (2 * ELEM_MAX_BYTES);
7676

77+
// This is the value checked in the Dafny test
78+
const INVALID_KEY: &str = "Invalid X509 Public Key.";
79+
7780
pub(crate) fn X509_to_X962(
7881
public_key: &[u8],
7982
compress: bool,
@@ -86,7 +89,7 @@ pub mod ECDH {
8689

8790
let evp_pkey = unsafe { EVP_parse_public_key(&mut cbs) };
8891
if evp_pkey.is_null() {
89-
return Err("Invalid X509 Public Key.".to_string());
92+
return Err(INVALID_KEY.to_string());
9093
}
9194
let ec_key = unsafe { EVP_PKEY_get0_EC_KEY(evp_pkey) };
9295

@@ -326,7 +329,29 @@ pub mod ECDH {
326329

327330
// for the moment, it's valid if we can use it to generate a shared secret
328331
fn valid_public_key(alg: &ECDHCurveSpec, public_key: &[u8]) -> Result<(), String> {
329-
X509_to_X962(public_key, false, Some(get_nid(alg)))?;
332+
let mut cbs = CBS {
333+
data: public_key.as_ptr(),
334+
len: public_key.len(),
335+
};
336+
337+
let evp_pkey = unsafe { EVP_parse_public_key(&mut cbs) };
338+
if evp_pkey.is_null() {
339+
return Err(INVALID_KEY.to_string());
340+
}
341+
let ec_key = unsafe { EVP_PKEY_get0_EC_KEY(evp_pkey) };
342+
343+
if unsafe {aws_lc_sys::EC_KEY_check_fips(ec_key)} != 1 {
344+
return Err(INVALID_KEY.to_string());
345+
}
346+
let ec_group = unsafe { EC_KEY_get0_group(ec_key) };
347+
if ec_group.is_null() {
348+
return Err(INVALID_KEY.to_string());
349+
}
350+
if get_nid(alg) != unsafe { EC_GROUP_get_curve_name(ec_group) } {
351+
return Err(INVALID_KEY.to_string());
352+
}
353+
unsafe { EVP_PKEY_free(evp_pkey) };
354+
330355
Ok(())
331356
}
332357

AwsCryptographyPrimitives/runtimes/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rust-version = "1.80.0"
99
[dependencies]
1010
aws-config = "1.5.11"
1111
aws-lc-rs = "1.12.0"
12-
aws-lc-sys = "0.22.0"
12+
aws-lc-sys = "0.24.0"
1313
aws-smithy-runtime-api = "1.7.3"
1414
aws-smithy-types = "1.2.10"
1515
chrono = "0.4.39"

TestVectorsAwsCryptographicMaterialProviders/dafny/TestVectorsAwsCryptographicMaterialProviders/src/VectorsComposition/AllAlgorithmSuites.dfy

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,16 @@ module {:options "-functionSyntax:4"} AllAlgorithmSuites {
2121
Types.CommitmentPolicy.DBE(Types.DBECommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT)
2222
}
2323

24-
// TODO: Add aes-192 after aws-lc-rs adds support
25-
// To add AES192 tests, uncomment next line and remove the current value of ESDKAlgorithmSuites
26-
// const ESDKAlgorithmSuites := set id: Types.ESDKAlgorithmSuiteId :: AlgorithmSuites.GetESDKSuite(id)
27-
const ESDKAlgorithmSuites := set id: Types.ESDKAlgorithmSuiteId |
28-
id != Types.ALG_AES_192_GCM_IV12_TAG16_NO_KDF &&
29-
id != Types.ALG_AES_192_GCM_IV12_TAG16_HKDF_SHA256 &&
30-
id != Types.ALG_AES_192_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384 ::
31-
AlgorithmSuites.GetESDKSuite(id)
24+
const ESDKAlgorithmSuites := set id: Types.ESDKAlgorithmSuiteId :: AlgorithmSuites.GetESDKSuite(id)
25+
3226
const DBEAlgorithmSuites := set id: Types.DBEAlgorithmSuiteId :: AlgorithmSuites.GetDBESuite(id)
3327

3428
const AllAlgorithmSuites := ESDKAlgorithmSuites + DBEAlgorithmSuites
3529

36-
// TODO: Add aes-192 after aws-lc-rs adds support
37-
// To add AES192 tests, comment out AllAlgorithmSuitesIsCompleteExceptAES192
38-
// and uncomment AllAlgorithmSuitesIsComplete
39-
lemma AllAlgorithmSuitesIsCompleteExceptAES192(id: Types.AlgorithmSuiteId)
40-
requires match id
41-
case ESDK(e) =>
42-
e != Types.ALG_AES_192_GCM_IV12_TAG16_NO_KDF &&
43-
e != Types.ALG_AES_192_GCM_IV12_TAG16_HKDF_SHA256 &&
44-
e != Types.ALG_AES_192_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384
45-
case DBE(_) => true
30+
lemma AllAlgorithmSuitesIsComplete(id: Types.AlgorithmSuiteId)
4631
ensures AlgorithmSuites.GetSuite(id) in AllAlgorithmSuites
4732
{}
4833

49-
// lemma AllAlgorithmSuitesIsComplete(id: Types.AlgorithmSuiteId)
50-
// ensures AlgorithmSuites.GetSuite(id) in AllAlgorithmSuites
51-
// {}
52-
5334
function ToHex(algorithmSuite: Types.AlgorithmSuiteInfo)
5435
: string
5536
{

TestVectorsAwsCryptographicMaterialProviders/runtimes/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ wrapped-client = []
1212
[dependencies]
1313
aws-config = "1.5.11"
1414
aws-lc-rs = "1.12.0"
15-
aws-lc-sys = "0.22.0"
15+
aws-lc-sys = "0.24.0"
1616
aws-sdk-dynamodb = "1.55.0"
1717
aws-sdk-kms = "1.51.0"
1818
aws-smithy-runtime-api = {version = "1.7.3", features = ["client"] }

0 commit comments

Comments
 (0)