Skip to content

Cannot reproduce results from lascar in jlsca #11

@r3-ck0

Description

@r3-ck0

Hi,

I was working on a CPA problem that I was bashing my head in using jlsca and which was trivially solved by lascar and I wanted to understand the difference / my mistake. Here is the data to reproduce:

cpa_data.zip

Here is my code for jlsca:

using Jlsca.Trs
using Jlsca.Sca
using Jlsca.Align
using Plots
using Statistics

fname = "/home/kali/machines/self/hw/cpa/nMY.ts"
keyByteNum = 1
condavg = false;

trs = InspectorTrace(fname)

attack = AesSboxAttack()
attack.xor = true
anal = IncrementalCPA() # Also tested  CPA()

anal.leakages = [HW()] # Also tested with ID(), Bit(0) and all bits

params = DpaAttack(attack,anal)
params.maxCols = 1042
params.maxColsPost = 1042
params.dataOffset = 1
params.targetOffsets = collect(1:16)
params.updateInterval = 10
params.knownKey = missing
params.keepraw = true

getTrs() = trs

@time rankdata = sca(DistributedTrace(getTrs), params, 1, nrTraces);

And here is my code for lascar, which runs perfectly:

import numpy as np 
from lascar import Session, CpaEngine, ConsoleOutputMethod, MatPlotLibOutputMethod, RankProgressionOutputMethod, ScoreProgressionOutputMethod, DictOutputMethod
from lascar.container import TraceBatchContainer
from lascar.tools.aes import sbox

traces = np.load("traces.npy")
values = np.load("pts.npy")


engines = [
        CpaEngine(f"cpa{i}",  lambda v, k, z=i: sbox[v[z] ^ k], range(256))
        for i in range(16)
]


t = TraceBatchContainer(traces, values)
s = Session(t)
s.add_engines(engines)
s.output_method = ConsoleOutputMethod(*engines)

s.run()

If I understand correctly, lascar is using an identity leakage model, but I'm not 100% sure if it doesn't take the hamming weight somewhere still. For the rest, the lascar code - to me - looks identical to what I try to do in jlsca, but I'm probably missing an important step.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions