Skip to content

Commit

Permalink
Fix leakage model parameter variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
TrAyZeN committed Dec 9, 2024
1 parent a766281 commit 52d8c36
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions benches/cpa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64>, plaintexts: &Array2<u8>) -> Cpa {
Expand All @@ -26,8 +26,8 @@ fn cpa_sequential(traces: &Array2<f64>, plaintexts: &Array2<u8>) -> Cpa {
cpa.finalize(leakage_model)
}

pub fn leakage_model_normal(value: ArrayView1<usize>, guess: usize) -> usize {
hw(sbox((value[1] ^ guess) as u8) as usize)
pub fn leakage_model_normal(plaintext: ArrayView1<usize>, guess: usize) -> usize {
hw(sbox((plaintext[1] ^ guess) as u8) as usize)
}

fn cpa_normal_sequential(traces: &Array2<f64>, plaintexts: &Array2<u8>) -> Cpa {
Expand Down
4 changes: 2 additions & 2 deletions src/distinguishers/cpa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/distinguishers/cpa_normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/distinguishers/dpa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use crate::{
/// .collect::<Array1<Array1<u8>>>()
/// .view(),
/// 256,
/// |key: Array1<u8>, guess| sbox(key[0] ^ guess as u8) & 1 == 1,
/// |plaintext: Array1<u8>, guess| sbox(plaintext[0] ^ guess as u8) & 1 == 1,
/// 2
/// );
/// ```
Expand Down

0 comments on commit 52d8c36

Please sign in to comment.