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.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import os, shutil
  2. from subprocess import check_call
  3. ### Install ELMO
  4. from elmo.config import ELMO_TOOL_REPOSITORY
  5. ELMO_SOURCE = 'https://github.com/sca-research/ELMO.git'
  6. elmo_complete_path = os.path.join('elmo', ELMO_TOOL_REPOSITORY)
  7. if not os.path.isdir(elmo_complete_path):
  8. from setup import install_elmo_tool
  9. install_elmo_tool(elmo_complete_path)
  10. def print_success(text):
  11. OKGREEN = '\033[92m'
  12. ENDC = '\033[0m'
  13. print(OKGREEN+text+ENDC)
  14. #########################################################
  15. # TEST 1 : MANAGE A FRESH SIMULATION #
  16. #########################################################
  17. foldername = 'test-project'
  18. classname = 'TestSimu'
  19. ### Create Simulation
  20. from elmo.manage import create_simulation
  21. shutil.rmtree('test-project', ignore_errors=True) # Clean before
  22. create_simulation(foldername, classname)
  23. assert os.path.isdir(foldername), 'Folder not created'
  24. ### List Available Simulations
  25. from elmo.manage import search_simulations
  26. simulations = search_simulations(foldername)
  27. assert classname in simulations, 'Test Simulation not found'
  28. ### Use a Simulation
  29. from elmo.manage import get_simulation
  30. simu = get_simulation(classname, foldername)
  31. shutil.rmtree(foldername)
  32. print_success(' - Test 1 "Manage A Fresh Simulation": Success!')
  33. #########################################################
  34. # TEST 2 : USE ELMO ENGINE #
  35. #########################################################
  36. ### Use the ELMO Engine
  37. from elmo.engine import ELMOEngine, Instr
  38. engine = ELMOEngine()
  39. for i in range(0, 256):
  40. engine.add_point(
  41. (Instr.LDR, Instr.MUL, Instr.OTHER), # Types of the previous, current and next instructions
  42. (0x0000, i), # Operands of the previous instructions
  43. (0x2BAC, i) # Operands of the current instructions
  44. )
  45. engine.run() # Compute the power consumption of all these points
  46. power = engine.power # Numpy 1D array with an entry for each previous point
  47. engine.reset_points() # Reset the engine to study other points
  48. assert power.shape == (256, )
  49. print_success(' - Test 2 "Use ELMO Engine": Success!')
  50. #########################################################
  51. # TEST 3 : USE A REAL SIMULATION #
  52. #########################################################
  53. from elmo import get_simulation
  54. KyberNTTSimulation = get_simulation('KyberNTTSimulation')
  55. simulation = KyberNTTSimulation()
  56. simulation.set_challenges(simulation.get_random_challenges(10))
  57. res = simulation.run()
  58. assert not res['error']
  59. assert res['nb_traces'] == 10
  60. assert res['nb_instructions']
  61. print_success(' - Test 3 "Use A Real Simulation": Success!')
  62. #########################################################
  63. print_success('All seems fine!')