From 52d8c36642fa286f73a8523562ae117e902c6008 Mon Sep 17 00:00:00 2001 From: TrAyZeN Date: Mon, 9 Dec 2024 16:44:19 +0100 Subject: [PATCH] Fix leakage model parameter variable name --- benches/cpa.rs | 8 ++++---- src/distinguishers/cpa.rs | 4 ++-- src/distinguishers/cpa_normal.rs | 2 +- src/distinguishers/dpa.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/benches/cpa.rs b/benches/cpa.rs index fe6f087..3fb0a4e 100644 --- a/benches/cpa.rs +++ b/benches/cpa.rs @@ -8,8 +8,8 @@ use ndarray_rand::rand_distr::Uniform; use ndarray_rand::RandomExt; use std::iter::zip; -pub fn leakage_model(value: usize, guess: usize) -> usize { - hw(sbox((value ^ guess) as u8) as usize) +pub fn leakage_model(plaintext: usize, guess: usize) -> usize { + hw(sbox((plaintext ^ guess) as u8) as usize) } fn cpa_sequential(traces: &Array2, plaintexts: &Array2) -> Cpa { @@ -26,8 +26,8 @@ fn cpa_sequential(traces: &Array2, plaintexts: &Array2) -> Cpa { cpa.finalize(leakage_model) } -pub fn leakage_model_normal(value: ArrayView1, guess: usize) -> usize { - hw(sbox((value[1] ^ guess) as u8) as usize) +pub fn leakage_model_normal(plaintext: ArrayView1, guess: usize) -> usize { + hw(sbox((plaintext[1] ^ guess) as u8) as usize) } fn cpa_normal_sequential(traces: &Array2, plaintexts: &Array2) -> Cpa { diff --git a/src/distinguishers/cpa.rs b/src/distinguishers/cpa.rs index 883040e..a8e1949 100644 --- a/src/distinguishers/cpa.rs +++ b/src/distinguishers/cpa.rs @@ -42,7 +42,7 @@ use std::{fs::File, iter::zip, ops::Add, path::Path}; /// [2, 1], /// [2, 1], /// ]; -/// let cpa = cpa(traces.view(), plaintexts.view(), 256, 0, |key, guess| sbox((key ^ guess) as u8) as usize, 2); +/// let cpa = cpa(traces.view(), plaintexts.view(), 256, 0, |plaintext, guess| sbox((plaintext ^ guess) as u8) as usize, 2); /// ``` /// /// # Panics @@ -323,7 +323,7 @@ mod tests { ]; let plaintexts = array![[1usize], [3], [1], [2], [3], [2], [2], [1], [3], [1]]; - let leakage_model = |value, guess| value ^ guess; + let leakage_model = |plaintext, guess| plaintext ^ guess; let mut processor = CpaProcessor::new(traces.shape()[1], 256, 0); for i in 0..traces.shape()[0] { processor.update(traces.row(i), plaintexts.row(i), leakage_model); diff --git a/src/distinguishers/cpa_normal.rs b/src/distinguishers/cpa_normal.rs index 697eb83..548f9c5 100644 --- a/src/distinguishers/cpa_normal.rs +++ b/src/distinguishers/cpa_normal.rs @@ -37,7 +37,7 @@ use crate::{distinguishers::cpa::Cpa, Error}; /// [2, 1], /// [2, 1], /// ]; -/// let cpa = cpa(traces.map(|&x| x as f32).view(), plaintexts.view(), 256, |key, guess| sbox((key[0] ^ guess) as u8) as usize, 2); +/// let cpa = cpa(traces.map(|&x| x as f32).view(), plaintexts.view(), 256, |plaintext, guess| sbox((plaintext[0] ^ guess) as u8) as usize, 2); /// ``` /// /// # Panics diff --git a/src/distinguishers/dpa.rs b/src/distinguishers/dpa.rs index d5adf69..712acb5 100644 --- a/src/distinguishers/dpa.rs +++ b/src/distinguishers/dpa.rs @@ -49,7 +49,7 @@ use crate::{ /// .collect::>>() /// .view(), /// 256, -/// |key: Array1, guess| sbox(key[0] ^ guess as u8) & 1 == 1, +/// |plaintext: Array1, guess| sbox(plaintext[0] ^ guess as u8) & 1 == 1, /// 2 /// ); /// ```