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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import setuptools
  2. from setuptools.command.build_py import build_py
  3. from setuptools.command.install import install
  4. from subprocess import check_call
  5. import os, shutil
  6. import re
  7. ### CONFIGURATION
  8. PELMO_SOURCE = 'https://github.com/ThFeneuil/python-elmo'
  9. ELMO_MODULE_NAME = 'elmo'
  10. ELMO_SOURCE = 'https://github.com/sca-research/ELMO.git'
  11. # Import configuration of ELMO_MODULE,
  12. # cannot use 'import elmo' because it can be ambiguous which module it will call
  13. with open(os.path.join(ELMO_MODULE_NAME, 'config.py')) as _file:
  14. globals = {'__file__': os.path.join(
  15. os.path.abspath(ELMO_MODULE_NAME),
  16. 'config.py'
  17. )}
  18. exec(_file.read(), globals)
  19. ELMO_TOOL_REPOSITORY = globals['ELMO_TOOL_REPOSITORY']
  20. ELMO_INPUT_FILE_NAME = globals['ELMO_INPUT_FILE_NAME']
  21. def install_elmo_tool(elmo_complete_path):
  22. ## Download the tool
  23. elmo_download_command = "git clone --depth=1 --branch=master {url} {elmo_path}".format(
  24. url=ELMO_SOURCE,
  25. elmo_path=elmo_complete_path,
  26. )
  27. check_call(elmo_download_command.split())
  28. shutil.rmtree(os.path.join(elmo_complete_path, '.git'))
  29. # 'test' contains a Python2 test, and it raises an error during byte-compiling
  30. shutil.rmtree(os.path.join(elmo_complete_path, 'test'))
  31. ## Setup the tool
  32. elmodefines_h = None
  33. elmodefines_h_path = os.path.join(elmo_complete_path, 'elmodefines.h')
  34. with open(elmodefines_h_path, 'r') as _file:
  35. elmodefines_lines = _file.readlines()
  36. for i, line in enumerate(elmodefines_lines):
  37. if re.match(r'\s*#define\s+DATAFILEPATH', line):
  38. elmodefines_lines[i] = '#define DATAFILEPATH "{}"'.format(ELMO_INPUT_FILE_NAME)
  39. elmodefines_h = ''.join(elmodefines_lines)
  40. with open(elmodefines_h_path, 'w') as _file:
  41. _file.write(elmodefines_h)
  42. # Compile the tool
  43. check_call("make clean".split(), cwd=elmo_complete_path)
  44. check_call("make".split(), cwd=elmo_complete_path)
  45. class PostBuildCommand(build_py):
  46. """ Build Command to add the ELMO installation """
  47. def run(self):
  48. build_py.run(self)
  49. # ELMO Installation
  50. elmo_complete_path = os.path.join(
  51. self.build_lib,
  52. ELMO_MODULE_NAME,
  53. ELMO_TOOL_REPOSITORY,
  54. )
  55. shutil.rmtree(elmo_complete_path, ignore_errors=True)
  56. install_elmo_tool(elmo_complete_path)
  57. if __name__ == '__main__':
  58. with open("README.md", "r") as fh:
  59. long_description = fh.read()
  60. setuptools.setup(
  61. name="python-elmo",
  62. version="0.0.1",
  63. author="Thibauld Feneuil",
  64. author_email="thibauld.feneuil@cryptoexperts.com",
  65. description="Emulator for power Leakage for the M0",
  66. long_description=long_description,
  67. long_description_content_type="text/markdown",
  68. url=PELMO_SOURCE,
  69. project_urls={
  70. 'ELMO Source': ELMO_SOURCE,
  71. 'pELMO Source': PELMO_SOURCE,
  72. },
  73. packages=setuptools.find_packages(),
  74. classifiers=[
  75. "Programming Language :: Python :: 3",
  76. ],
  77. python_requires='>=3.5',
  78. cmdclass={
  79. 'build_py': PostBuildCommand,
  80. },
  81. install_requires=['numpy'],
  82. include_package_data=True,
  83. )