Skip to content

Commit cb55f2e

Browse files
committed
ci: diagnose X25519 CNG public key imports
1 parent c291151 commit cb55f2e

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ jobs:
4747
toolchain: stable
4848
- name: Cache build artifacts
4949
uses: Swatinem/rust-cache@42dc69e1aa15d09112580998cf2ef0119e2e91ae # v2
50+
- name: X25519 CNG import diagnostics
51+
run: cargo test x25519_cng_import_diagnostics -- --nocapture
5052
- name: cargo test
5153
run: cargo test
5254
# https://github.com/rust-lang/cargo/issues/6669

src/kx.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ mod test {
247247
use windows::core::Owned;
248248
use wycheproof::{ecdh::TestName, TestResult};
249249

250-
use crate::{keys::import_ecdh_private_key, kx::EcKeyExchange};
250+
use crate::{
251+
keys::{import_ecdh_private_key, import_ecdh_public_key},
252+
kx::EcKeyExchange,
253+
};
251254

252255
#[test]
253256
fn secp256r1() {
@@ -284,6 +287,52 @@ mod test {
284287
}
285288
}
286289

290+
#[test]
291+
fn x25519_cng_import_diagnostics() {
292+
let cases = [
293+
(
294+
"tc1 normal",
295+
"504a36999f489cd2fdbc08baff3d88fa00569ba986cba22548ffde80f9806829",
296+
Some("98c969d09aeecfe56f44da8c143e7c739afc6d3ac26cd099a73436fec147a908"),
297+
Some("08a947c1fe3634a799d06cc23a6dfc9a737c3e148cda446fe5cfee9ad069c998"),
298+
),
299+
(
300+
"tc2 twist",
301+
"63aa40c6e38346c5caf23a6df0a5e6c80889a08647e551b3563449befcfc9733",
302+
None,
303+
None,
304+
),
305+
(
306+
"tc34 special-valid-u4",
307+
"0400000000000000000000000000000000000000000000000000000000000000",
308+
Some("a0d42a061659386f4553ce7564094b15d73bc8a36340191b74c1e56f8a050469"),
309+
Some("6904058a6fe5c1741b194063a3c83bd7154b096475ce53456f385916062ad4a0"),
310+
),
311+
];
312+
let zero_y = [0u8; 32];
313+
314+
for (name, x_hex, y_le_hex, y_be_hex) in cases {
315+
let x = hex::decode(x_hex).unwrap();
316+
println!("x25519 import diagnostic: {name}");
317+
318+
let zero_res =
319+
import_ecdh_public_key(crate::kx::KxGroup::X25519.alg_handle(), &x, &zero_y);
320+
println!(" y=zero: {:?}", zero_res.as_ref().map(|_| ()));
321+
322+
if let Some(y_hex) = y_le_hex {
323+
let y = hex::decode(y_hex).unwrap();
324+
let res = import_ecdh_public_key(crate::kx::KxGroup::X25519.alg_handle(), &x, &y);
325+
println!(" y=sqrt-le: {:?}", res.as_ref().map(|_| ()));
326+
}
327+
328+
if let Some(y_hex) = y_be_hex {
329+
let y = hex::decode(y_hex).unwrap();
330+
let res = import_ecdh_public_key(crate::kx::KxGroup::X25519.alg_handle(), &x, &y);
331+
println!(" y=sqrt-be: {:?}", res.as_ref().map(|_| ()));
332+
}
333+
}
334+
}
335+
287336
#[test]
288337
fn x25519() {
289338
let test_set = wycheproof::xdh::TestSet::load(wycheproof::xdh::TestName::X25519).unwrap();

0 commit comments

Comments
 (0)