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.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

setup.py 3.7KB

  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.1.0",
  63. author="Thibauld Feneuil",
  64. author_email="thibauld.feneuil@cryptoexperts.com",
  65. description="A Python encapsulation of a statistical leakage simulator for the ARM M0 family",
  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. },
  72. packages=setuptools.find_packages(),
  73. keywords="python3 crypto",
  74. classifiers=[
  75. "Development Status :: 2 - Pre-Alpha",
  76. "Intended Audience :: Developers",
  77. "Intended Audience :: Science/Research",
  78. "License :: OSI Approved :: MIT License",
  79. "Programming Language :: Python",
  80. "Programming Language :: Python :: 3",
  81. "Operating System :: MacOS",
  82. "Operating System :: POSIX :: Linux",
  83. "Topic :: Scientific/Engineering",
  84. "Topic :: Security :: Cryptography",
  85. "Topic :: Software Development :: Libraries :: Python Modules",
  86. ],
  87. python_requires=">=3.5",
  88. cmdclass={
  89. "build_py": PostBuildCommand,
  90. },
  91. install_requires=["numpy"],
  92. include_package_data=True,
  93. )