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.

пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # Python ELMO
  2. _Python 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 _Python ELMO_, you need at least Python3.5 and ```numpy```.
  10. 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,
  11. ```bash
  12. sudo apt install build-essential
  13. ```
  14. 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.
  15. ## Installation
  16. First, download _Python ELMO_.
  17. ```bash
  18. git clone https://git.aprilas.fr/tfeneuil/python-elmo
  19. ```
  20. And then, install ELMO thanks to the script of installation.
  21. ```bash
  22. python setup.py install
  23. ```
  24. ## Usage
  25. ### Create a new simulation project
  26. What is a _simulation project_ ? It is a project to simulate the traces of _one_ binary program. It includes
  27. - A Python class which enable to generate traces in Python;
  28. - The C program which will be compile to have the binary program for the analysis;
  29. - A linker script where the configuration of the simulated device are defined.
  30. To start a new project, you can use the following function.
  31. ```python
  32. from elmo.manage import create_simulation
  33. create_simulation(
  34. 'dilithium', # The (relative) path of the project
  35. 'DilithiumSimulation' # The classname of the simulation
  36. )
  37. ```
  38. This function will create a repository _dilithium_ with all the complete squeleton of the project. In this repository, you can find:
  39. - The file _project.c_ where you must put the leaking code;
  40. - 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;
  41. - A _Makefile_ ready to be used with a compiler _arm-none-eabi-gcc_.
  42. ### List all the available simulation
  43. ```python
  44. from elmo.manage import search_simulations
  45. search_simulations('.')
  46. ```
  47. ```python
  48. {'DilithiumSimulation': <class 'DilithiumSimulation'>,
  49. 'KyberNTTSimulation': <class 'KyberNTTSimulation'>}
  50. ```
  51. _Python ELMO_ offers a example project to you in the repository _projects/Examples_ of 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/).
  52. ### Use a simulation project
  53. Warning! Before using it, you have to compile your project thanks to the provided Makefile.
  54. ```python
  55. from elmo.manage import get_simulation
  56. KyberNTTSimulation = get_simulation_via_classname('KyberNTTSimulation')
  57. import numpy as np
  58. Kyber512 = {'k': 2, 'n': 256}
  59. challenges = [
  60. np.ones((Kyber512['k'], Kyber512['n']), dtype=int),
  61. ]
  62. simulation = KyberNTTSimulation(challenges)
  63. simulation.run() # Launch the simulation
  64. traces = simulation.get_traces()
  65. # And now, I can draw and analyse the traces
  66. ```
  67. ### Use a simulation project thanks to a server
  68. Sometimes, it is impossible to run the simulation thanks the simple method _run_ of the project class. Indeed, sometimes the Python script is executed in the environment where _Python ELMO_ cannot launch the ELMO tool. For example, it is the case where _Python ELMO_ is used in SageMath on Windows. On Windows, SageMath installation relies on the Cygwin POSIX emulation system and it can be a problem.
  69. To offer a solution, _Online ELMO_ can be used thanks to a link client-server. The idea is you must launch the script _run\_server.py_ which will listen (by default) at port 5000 in localhost.
  70. ```bash
  71. python -m elmo run-server
  72. ```
  73. And after, you can manipulate the projects as described in the previous section by replacing _run_ to _run\_online_.
  74. ```python
  75. from elmo.manage import get_simulation
  76. KyberNTTSimulation = get_simulation('KyberNTTSimulation')
  77. import numpy as np
  78. Kyber512 = {'k': 2, 'n': 256}
  79. challenges = [
  80. np.ones((Kyber512['k'], Kyber512['n']), dtype=int),
  81. ]
  82. simulation = KyberNTTSimulation(challenges)
  83. simulation.run_online() # Launch the simulation THANKS TO A SERVER
  84. traces = simulation.get_traces()
  85. # And now, I can draw and analyse the traces
  86. ```
  87. Warning! Using the _run\_online_ method doesn't exempt you from compiling the project with the provided Makefile.
  88. ### Use the ELMO Engine
  89. 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
  90. - the type and the operands of the previous assembler instruction
  91. - the type and the operands of the current assembler instruction
  92. - the type of the next assembler instruction
  93. The type of the instructions are:
  94. - "_**EOR**_" for ADD(1-4), AND, CMP, CPY, EOR, MOV, ORR, ROR, SUB;
  95. - "_**LSL**_" for LSL(2), LSR(2);
  96. - "_**STR**_" for STR, STRB, STRH;
  97. - "_**LDR**_" for LDR, LDRB, LDRH;
  98. - "_**MUL**_" for MUL;
  99. - "_**OTHER**_" for the other instructions.
  100. ```python
  101. from elmo.engine import ELMOEngine, Instr
  102. engine = ELMOEngine()
  103. for i in range(0, 256):
  104. engine.add_point(
  105. (Instr.LDR, Instr.MUL, Instr.OTHER), # Types of the previous, current and next instructions
  106. (0x0000, i), # Operands of the previous instructions
  107. (0x2BAC, i) # Operands of the current instructions
  108. )
  109. engine.run() # Compute the power consumption of all these points
  110. power = engine.power # Numpy 1D array with an entry for each previous point
  111. engine.reset_points() # Reset the engine to study other points
  112. ```
  113. ## Licences
  114. [MIT](LICENCE.txt)