Python-ELMO is a Python library which offers an encapsulation of the binary tool ELMO, in order to manipulate it easily in Python and SageMath script.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 5.0KB

4 anni fa
4 anni fa
4 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # Online ELMO
  2. _Online ELMO_ is a Python library which proposes an encapsulation of the project _ELMO_.
  3. [MOW17] **Towards Practical Tools for Side
  4. Channel Aware Software Engineering : ’Grey Box’ Modelling for Instruction Leakages**
  5. by _David McCann, Elisabeth Oswald et Carolyn Whitnall_.
  6. https://www.usenix.org/conference/usenixsecurity17/technical-sessions/presentation/mccann
  7. **ELMO GitHub**: https://github.com/sca-research/ELMO
  8. ## Requirements
  9. To use _Online ELMO_, you need at least Python3.5 and the packages present in the file requirements.txt
  10. ```bash
  11. pip3 install -r requirements.txt
  12. ```
  13. The library will install and compile ELMO. So, you need the GCC compiler collection and the command/utility 'make' (for more details, see the documentation of ELMO). On Ubuntu/Debian,
  14. ```bash
  15. sudo apt install build-essential
  16. ```
  17. To use ELMO on a leaking binary program, you need to compile the C implementations to binary programs (a ".bin" file). "ELMO is not linked to any ARM specific tools, so users should be fine to utilise whatever they want for this purpose. A minimal working platform for compiling your code into an ARM Thumb binary would be to use the GNU ARM Embedded Toolchain (tested version: arm-none-eabi-gcc version 7.3.1 20180622, it can be downloaded from https://developer.arm.com/open-source/gnu-toolchain/gnu-rm).", see the [documentation of ELMO](https://github.com/sca-research/ELMO) for more details.
  18. ## Installation
  19. First, download _Online ELMO_.
  20. ```bash
  21. git clone https://git.aprilas.fr/tfeneuil/OnlineELMO
  22. ```
  23. And then, install ELMO thanks to the script of installation.
  24. ```bash
  25. ./install
  26. ```
  27. ## Usage
  28. ### Create a new simulation project
  29. What is a _simulation project_ ? It is a project to simulate the traces of _one_ binary program. It includes
  30. - A Python class which enable to generate traces in Python;
  31. - The C program which will be compile to have the binary program for the analysis;
  32. - A linker script where the configuration of the simulated device are defined.
  33. To start a new project, you can use the following function.
  34. ```python3
  35. > from elmo_online.manage import create_simulation
  36. > create_simulation(
  37. > 'dilithium', # The (relative) path of the project
  38. > 'DilithiumSimulation' # The classname of the simulation
  39. >)
  40. ```
  41. This function will create a repository _dilithium_ with all the complete squeleton of the project. In this repository, you can find:
  42. - The file _project.c_ where you must put the leaking code;
  43. - The file _projectclass.py_ where there is the class of the simulation which will enable you to generate traces of the project in Python scripts;
  44. - A _Makefile_ ready to be used with a compiler _arm-none-eabi-gcc_.
  45. _Online ELMO_ offers a example project to you in the repository _projects/Examples_ in the module. This example is a project to generate traces of the execution of the NTT implemented in the cryptosystem [Kyber](https://pq-crystals.org/kyber/).
  46. ### List all the available simulation
  47. ```python3
  48. >from elmo_online.manage import search_simulations
  49. >search_simulations('.')
  50. {'DilithiumSimulation': <class 'DilithiumSimulation'>,
  51. 'KyberNTTSimulation': <class 'KyberNTTSimulation'>}
  52. ```
  53. ### Use a simulation project
  54. Warning! Before using it, you have to compile your project thanks to the provided Makefile.
  55. ```python
  56. > from elmo_online.manage import get_simulation
  57. > KyberSimulation = get_simulation_via_classname('KyberNTTSimulation')
  58. >
  59. > import numpy as np
  60. > Kyber512 = {'k': 2, 'n': 256}
  61. > challenges = [
  62. > np.ones((Kyber512['k'], Kyber512['n']), dtype=int),
  63. > ]
  64. >
  65. > simulation = KyberSimulation(challenges)
  66. > simulation.run() # Launch the simulation
  67. > traces = simulation.get_traces()
  68. > # And now, I can draw and analyse the traces
  69. ```
  70. ### Use the ELMO Engine
  71. The engine exploits the model of ELMO to directly give the power consumption of an assembler instruction. In the model, to have the power consumption of an assembler instruction, it needs
  72. - the type and the operands of the previous assembler instruction
  73. - the type and the operands of the current assembler instruction
  74. - the type of the next assembler instruction
  75. The type of the instructions are:
  76. - "_**EOR**_" for ADD(1-4), AND, CMP, CPY, EOR, MOV, ORR, ROR, SUB;
  77. - "_**LSL**_" for LSL(2), LSR(2);
  78. - "_**STR**_" for STR, STRB, STRH;
  79. - "_**LDR**_" for LDR, LDRB, LDRH;
  80. - "_**MUL**_" for MUL;
  81. - "_**OTHER**_" for the other instructions.
  82. ```python
  83. > from elmo_online.engine import ELMOEngine, Instr
  84. > engine = ELMOEngine()
  85. > for i in range(0, 256):
  86. > engine.add_point(
  87. > (Instr.LDR, Instr.MUL, Instr.OTHER), # Types of the previous, current and next instructions
  88. > (0x0000, i), # Operands of the previous instructions
  89. > (0x2BAC, i) # Operands of the current instructions
  90. > )
  91. > engine.run() # Compute the power consumption of all these points
  92. > power = engine.power # Numpy 1D array with an entry for each previous point
  93. > engine.reset_points() # Reset the engine to study other points
  94. ```
  95. ## Licences
  96. [MIT](LICENCE.txt)