@@ -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