From 7d75c1ac83dd9bc5fc237248d821e6cb1780673f Mon Sep 17 00:00:00 2001 From: Hugo Rosenkranz-Costa Date: Mon, 20 Nov 2023 17:07:58 +0100 Subject: [PATCH] feat: iterate through subkeys using BFS for decaps --- src/core/primitives.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/primitives.rs b/src/core/primitives.rs index 541ffdf8..10f528f6 100644 --- a/src/core/primitives.rs +++ b/src/core/primitives.rs @@ -231,7 +231,9 @@ pub fn decaps( ) -> Result, Error> { let precomp = &(&encapsulation.c1 * &usk.a) + &(&encapsulation.c2 * &usk.b); for encapsulation_i in &encapsulation.encs { - for (_, (sk_j, x_j)) in usk.subkeys.iter() { + // BFS search user subkeys to first try the most recent rotations of each + // partitions. + for (_, (sk_j, x_j)) in usk.subkeys.bfs() { let e_j = match encapsulation_i { KeyEncapsulation::HybridEncapsulation(epq_i) => { if let Some(sk_j) = sk_j {