Giter Site home page Giter Site logo

lascar's Introduction

Ledger-Donjon Logo

Join the chat at https://gitter.im/Ledger-Donjon/lascar Documentation Status

LASCAR

Ledger's Advanced Side Channel Analysis Repository

A fast, versatile, and open source python3 library designed to facilitate Side-Channel Analysis.

lascar is intended to be used by seasoned side-channel attackers as well as laymen who would like to get a feel of side-channel analysis.

From side-channel acquisitions to results management, passing by signal synchronisation, custom attacks, lascar provides classes/functions to solve most of the obstacles an attacker would face, when needed to perform sound, state-of-the-art side-channel analysis.

This project has been developed in parallel of the activities done by Ledger Donjon (Ledger's security team), to fully match our needs regarding side-channel evaluation.

Main features

The philosophy behind lascar is to simplify for the end user the process of a side-channel analysis. It provides many classes and functions that you can accomodate with, or inherit from to do the job you need.

  • Openness: lascar library is open source and is intended to facilitate attack implementations, and exchange between users. Contributing to lascar is strongly encouraged.
  • Simplicity: For basic state of the art attacks, the corresponding lascar script shall stay basic
  • Compatibility: Since lascar relies on mainstream python libraries (numpy, sklearn, keras): lascar is easily deployable
  • Flexibility: Implement your own classes (for your already existing trace format, your specific attacks, the way you want your output to be...), use different languages (provided that you bind them with python),...

Please note that performance has not yet been challenged.

The tutorial/examples folders of the library provide basic scripts solving the most frequent use-cases of side-channel analysis.

Installation

Lascar can be installed with pip3:

pip3 install "git+https://github.com/Ledger-Donjon/lascar.git"

Requirements

This library requires the following packages:

Tutorial

The tutorial folder contains commented scripts to understand how to handle the core classes behind lascar (Container, Session, Engine, OutputMethod)

Examples

See examples.md

Command-line tool

Use lascarctl, lascar command line tool. For documentation, see here

Ledger Donjon Logo About Ledger Donjon Ledger Donjon Logo

Created in 2018, Ledger Donjon (Ledger security team) regroups experts in security with a wide range of expertise (such as software, perturbation and side-channel attacks, secured development, reverse engineering, ...). Based in Paris, Ledger's Donjon tends to shift the paradigm of security through obscurity. Take a look at our blogposts and the detailed introduction!

Acknowledgerments

Ledger's Donjon would like to thank the people behind ASCAD, for making available real side-channel traces and scripts for analysis. Their traces have been used in examples/ascad/ folder to illustrate how to use lascar to reproduce (part of) their study.

lascar's People

Contributors

adrianthillard avatar blattm avatar catageek avatar charlesledger avatar clementperon avatar gbillou avatar gitter-badger avatar hackenbergstefan avatar kingofpayne avatar manuelsanpedro avatar yhql avatar zyuiop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lascar's Issues

A line of RankProgressionOutputMethod's plot does not correspond to a single guess

Hello,

first of all, thank you for your work so far!

I tried to use the filters parameter to get RankProgressionOutputMethod to only output the rank of the solution, but the generated plot seemed to be incorrect.

If I understand your source code correctly, a single line in a plot generated by RankProgressionOutputMethod (lets say line number k), will give you the answer to the question 'what is the k-th best guess?' and not 'what is the rank of guess k?'

The ScoreProgressionOutputMethod behaves in a similar way.

Is this intended behaviour? In case it is, it is there are two things that are rather confusing:

  1. This behaviour is not documented.
  2. When the solution is plotted, the line really gives you the rank of a single guess (working as I think it is intended)

Best,
Manuel

missing requirement

The module 'click' is not in lascar's requirements list, although it is needed for lascarctl.

Theoretical justification for the changes you made to the NICV computation

Hello,

In commit 189ad51, you completely changed the code responsible for this computation. Could you please provide a source with a theoretical justification (e.g - some kind of mathematical proof) or at least an explanation for the resulting metric, as it no longer matches the description from the original paper (for reference - NICV: Normalized Inter-Class Variance for Detection of Side-Channel Leakage, Shivam Bhasin, Jean-Luc Danger, Sylvain Guilley, Zakaria Najm, 2014).

Best regards,

TotallyNotAStudent0

Recent Installation

Hi

I really appreciate your time to help me.

I had Lascar on my older laptop which was working perfectly.
On my new PC, I installed Python 3.7, 3.8.7 and 3.9 and the latest version of Lascar and I get this error:


Session |N/A%|                          |0 trc/10000 | (3 engines, batch_size=500, leakage_shape=(26,)) |ETA:  --:--:--Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Users\eaerabi\AppData\Local\Programs\Python\Python37\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Users\eaerabi\AppData\Local\Programs\Python\Python37\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\eaerabi\AppData\Roaming\Python\Python37\site-packages\lascar-1.1-py3.7.egg\lascar\engine\engine.py", line 82, in update
    self._update(batch)
  File "C:\Users\eaerabi\AppData\Roaming\Python\Python37\site-packages\lascar-1.1-py3.7.egg\lascar\engine\partitioner_engine.py", line 125, in new_update
    pcount, acc_x = jitted_update(batch.values, batch.leakages)
  File "c:\users\eaerabi\appdata\local\programs\python\python37\lib\site-packages\numba\core\dispatcher.py", line 414, in _compile_for_args
    error_rewrite(e, 'typing')
  File "c:\users\eaerabi\appdata\local\programs\python\python37\lib\site-packages\numba\core\dispatcher.py", line 357, in error_rewrite
    raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
�[1m�[1mNo implementation of function Function(<built-in function getitem>) found for signature:

 >>> getitem(array(uint32, 1d, C), bool)

There are 22 candidate implementations:
�[1m  - Of which 20 did not match due to:
  Overload of function 'getitem': File: <numerous>: Line N/A.
    With argument(s): '(array(uint32, 1d, C), bool)':�[0m
�[1m   No match.�[0m
�[1m  - Of which 2 did not match due to:
  Overload in function 'GetItemBuffer.generic': File: numba\core\typing\arraydecl.py: Line 162.
    With argument(s): '(array(uint32, 1d, C), bool)':�[0m
�[1m   Rejected as the implementation raised a specific error:
     TypeError: unsupported array index type bool in [bool]�[0m
  raised from c:\users\eaerabi\appdata\local\programs\python\python37\lib\site-packages\numba\core\typing\arraydecl.py:69
�[0m
�[0m�[1mDuring: typing of intrinsic-call at C:\Users\eaerabi\AppData\Roaming\Python\Python37\site-packages\lascar-1.1-py3.7.egg\lascar\engine\partitioner_engine.py (116)�[0m
�[1m
File "..\..\..\Users\eaerabi\AppData\Roaming\Python\Python37\site-packages\lascar-1.1-py3.7.egg\lascar\engine\partitioner_engine.py", line 116:�[0m
�[1m            def jitted_update(batchvalues, batchleakages, pfunc = self._partition_function, psize = self._partition_size, rng2idx = self._partition_range_to_index, order = self._order):
                <source elided>
                for pv in np.arange(batchvalues.shape[0]):
�[1m                    idx = rng2idx[pfunc(batchvalues[pv])]
�[0m                    �[1m^�[0m�[0m


These are the packages installed:
Package Version


atomicwrites 1.4.0
attrs 20.3.0
cached-property 1.5.2
click 8.0.0a1
colorama 0.4.4
cycler 0.10.0
freetype-py 2.2.0
h5py 3.1.0
importlib-metadata 3.3.0
iniconfig 1.1.1
joblib 1.0.0
keras 2.4.3
kiwisolver 1.3.1
lascar 1.1
llvmlite 0.35.0
matplotlib 3.3.3
numba 0.52.0
numpy 1.20.0rc2
packaging 20.8
pillow 8.1.0
pip 20.1.1
pluggy 1.0.0.dev0
progressbar2 3.53.1
py 1.10.0
pyparsing 3.0.0b2
pytest 6.2.1
python-dateutil 2.8.1
python-utils 2.4.0
pyyaml 5.3.1
scikit-learn 0.24.0
scipy 1.6.0
setuptools 47.1.0
six 1.15.0
sklearn 0.0
threadpoolctl 2.1.0
toml 0.10.2
typing-extensions 3.7.4.3
vispy 0.6.6
zipp 3.4.0

Thanks for your help.
Regards
Ehsan

Issue when installing on Linux (Manjaro 18.0.4)

Hello,

When installing on Linux, we had issues during install.
It appears that the command "python3 setup.py install --user" was not sufficient, and that we had to go for a "sudo python3 setup.py install". Running it with "sudo python3 setup.py install --user" was the cause of the issue.

Regards,
Vincent.

Missing requirement and Wrong arugment when using progressbar

Hey, found two issues.

  1. PYQT5 is needed when running 07-session-dpa-example.py to show the output result figure.
  2. In ./lascar/session.py line 301. The "max_value" should be "maxval". Maybe it's about the version problem, my "progressbar" is version 2.5.

Regards,
-Huanjia

'Dataset' object has no attribute 'value'

In tutorial 8,

assert np.all(hdf5_output_method_bis["dpa_lsb/500"].value == dpa_lsb_engine.finalize())
the method .value is suggested to access a hdf5 dataset value. But the object has no such attribute.

  File "08-session-manage-outputs.py", line 161, in <module>
    assert np.all(hdf5_output_method_bis["dpa_lsb/500"].value == dpa_lsb_engine.finalize())
AttributeError: 'Dataset' object has no attribute 'value'

Lascar CpaEngine Jit Errors

Hello!

Was using lascar to perform CPA analysis; however, the jit functionality of the CpaEngine was breaking.
Here is the debug output if interested:
Wanted to report this just in case anyone else runs into this problem in the meantime!

cpa_engines = [lascar.CpaEngine(name="cpa_%02d" % i, selection_function=generate_selection_function(i), guess_range=range(256), jit=False) for i in range(BLOCK_SIZE)]
During: resolving callee type: type(CPUDispatcher(<function generate_selection_function.<locals>.selection_with_guess at 0x7f7cd7ce1c60>))
During: typing of call at /usr/local/lib/python3.11/dist-packages/lascar/engine/guess_engine.py (74)


File "../../../../usr/local/lib/python3.11/dist-packages/lascar/engine/guess_engine.py", line 74:
            def hf(guessrange, batchvalues):
                <source elided>
                    for guess in np.arange(guessrange.shape[0]):
                        out[d, guess] = f(batchvalues[d], guessrange[guess])
                        ^

/usr/local/lib/python3.11/dist-packages/lascar/engine/cpa_engine.py:78: RuntimeWarning: invalid value encountered in divide
  numerator = (self._accXM / self._number_of_processed_traces) - np.outer(
/usr/local/lib/python3.11/dist-packages/lascar/engine/cpa_engine.py:79: RuntimeWarning: invalid value encountered in divide
  self._accM / self._number_of_processed_traces, m
/usr/local/lib/python3.11/dist-packages/lascar/engine/cpa_engine.py:83: RuntimeWarning: invalid value encountered in divide
  self._accM2 / self._number_of_processed_traces
/usr/local/lib/python3.11/dist-packages/lascar/engine/cpa_engine.py:84: RuntimeWarning: invalid value encountered in divide
  - (self._accM / self._number_of_processed_traces) ** 2,

CPA to my captured power traces: Divide by Zero, Overflows and errors...

Hi to all

I am trying to feed power traces captured from my oscilloscope to Lascar CPAEngine.
I started by "cpa.py" and changed it. I translated my data into the "leakage" and "values" with the same formats as "BasicAesSimulationContainer" function builds:

When it runs, it shows these errors:

2019-03-04 14:28:47,843 - lascar.session - INFO - Session Session: 1000 traces, 3 engines, batch_size=10, leakage_shape=(1000,)
Session | 88%|#####################   |880 trc/1000 | (3 engines, batch_size=10, leakage_shape=(1000,)) |ETA:   0:00:00divide by zero (flag: 9) encountered.
Abort (q) or ignore for this session (press enter) ?
C:\Users\aerabieh\AppData\Roaming\Python\Python37\site-packages\lascar-0.1-py3.7.egg\lascar\engine\cpa_engine.py:75: RuntimeWarning: invalid value encountered in true_divide
c:\python3\lib\site-packages\matplotlib-3.0.2-py3.7-win-amd64.egg\matplotlib\transforms.py:2902: RuntimeWarning: overflow encountered in double_scalars
  elif vmax - vmin <= maxabsvalue * tiny:
c:\python3\lib\site-packages\matplotlib-3.0.2-py3.7-win-amd64.egg\matplotlib\axes\_base.py:2484: RuntimeWarning: overflow encountered in double_scalars
  delta = (x1t - x0t) * margin
Session |100%|#######################|1000 trc/1000 | (3 engines, batch_size=10, leakage_shape=(1000,)) |Time:  0:00:02
2019-03-04 14:28:52,303 - lascar.session - INFO - Session cpa on 16 bytes: 1000 traces, 18 engines, batch_size=50, leakage_shape=(1000,)
cpa on 16 bytes |N/A%|                 |0 trc/1000 | (18 engines, batch_size=50, leakage_shape=(1000,)) |ETA:  --:--:--Exception ignored in: <function Image.__del__ at 0x0000019891A89C80>
Traceback (most recent call last):
  File "C:\Python3\lib\tkinter\__init__.py", line 3507, in __del__
    self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Tcl_AsyncDelete: async handler deleted by the wrong thread

Can you give me any clue what is wrong with it?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.