Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot reproduce results from lascar in jlsca #11

Open
r3-ck0 opened this issue Jul 18, 2024 · 0 comments
Open

Cannot reproduce results from lascar in jlsca #11

r3-ck0 opened this issue Jul 18, 2024 · 0 comments

Comments

@r3-ck0
Copy link

r3-ck0 commented Jul 18, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant