| 
									
										
										
										
											2002-04-03 18:45:09 -07:00
										 |  |  | #! /usr/bin/env python | 
					
						
							| 
									
										
										
										
											2009-08-03 15:14:44 -04:00
										 |  |  | # | 
					
						
							|  |  |  | #  setup.py : Distutils setup script | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # =================================================================== | 
					
						
							| 
									
										
										
										
											2014-06-14 22:00:00 +02:00
										 |  |  | # The contents of this file are dedicated to the public domain.  To | 
					
						
							|  |  |  | # the extent that dedication to the public domain is not available, | 
					
						
							| 
									
										
										
										
											2009-08-03 15:14:44 -04:00
										 |  |  | # everyone is granted a worldwide, perpetual, royalty-free, | 
					
						
							|  |  |  | # non-exclusive license to exercise all rights associated with the | 
					
						
							| 
									
										
										
										
											2014-06-14 22:00:00 +02:00
										 |  |  | # contents of this file for any purpose whatsoever. | 
					
						
							|  |  |  | # No rights are reserved. | 
					
						
							| 
									
										
										
										
											2009-08-03 15:14:44 -04:00
										 |  |  | # | 
					
						
							|  |  |  | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | 
					
						
							|  |  |  | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | 
					
						
							|  |  |  | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | 
					
						
							|  |  |  | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | 
					
						
							|  |  |  | # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | 
					
						
							|  |  |  | # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | 
					
						
							|  |  |  | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 
					
						
							|  |  |  | # SOFTWARE. | 
					
						
							|  |  |  | # =================================================================== | 
					
						
							| 
									
										
										
										
											2002-07-11 14:31:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 23:37:43 +02:00
										 |  |  | from __future__ import print_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-25 22:29:47 +02:00
										 |  |  | try: | 
					
						
							|  |  |  |     from setuptools import Extension, Command, setup | 
					
						
							|  |  |  | except ImportError: | 
					
						
							|  |  |  |     from distutils.core import Extension, Command, setup | 
					
						
							| 
									
										
										
										
											2003-02-28 17:38:29 -07:00
										 |  |  | from distutils.command.build_ext import build_ext | 
					
						
							| 
									
										
										
										
											2018-11-04 11:31:40 +01:00
										 |  |  | from distutils.command.build_py import build_py | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  | import re | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import shutil | 
					
						
							|  |  |  | import struct | 
					
						
							| 
									
										
										
										
											2018-11-26 12:39:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | from compiler_opt import set_compiler_options | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-16 23:50:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | use_separate_namespace = os.path.isfile(".separate_namespace") | 
					
						
							| 
									
										
										
										
											2002-04-03 18:45:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-20 22:16:50 +01:00
										 |  |  | project_name = "pycryptodome" | 
					
						
							|  |  |  | package_root = "Crypto" | 
					
						
							|  |  |  | other_project = "pycryptodomex" | 
					
						
							|  |  |  | other_root = "Cryptodome" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if use_separate_namespace: | 
					
						
							|  |  |  |     project_name, other_project = other_project, project_name | 
					
						
							|  |  |  |     package_root, other_root = other_root, package_root | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | longdesc = """
 | 
					
						
							|  |  |  | PyCryptodome | 
					
						
							|  |  |  | ============ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyCryptodome is a self-contained Python package of low-level | 
					
						
							|  |  |  | cryptographic primitives. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-24 11:29:20 +03:00
										 |  |  | It supports Python 2.6 and 2.7, Python 3.4 and newer, and PyPy. | 
					
						
							| 
									
										
										
										
											2016-02-20 22:16:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | You can install it with:: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pip install THIS_PROJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | All modules are installed under the ``THIS_ROOT`` package. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Check the OTHER_PROJECT_ project for the equivalent library that | 
					
						
							|  |  |  | works under the ``OTHER_ROOT`` package. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyCryptodome is a fork of PyCrypto. It brings several enhancements | 
					
						
							|  |  |  | with respect to the last official version of PyCrypto (2.6.1), | 
					
						
							|  |  |  | for instance: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | * Authenticated encryption modes (GCM, CCM, EAX, SIV, OCB) | 
					
						
							|  |  |  | * Accelerated AES on Intel platforms via AES-NI | 
					
						
							|  |  |  | * First class support for PyPy | 
					
						
							|  |  |  | * Elliptic curves cryptography (NIST P-256 curve only) | 
					
						
							|  |  |  | * Better and more compact API (`nonce` and `iv` attributes for ciphers, | 
					
						
							|  |  |  |   automatic generation of random nonces and IVs, simplified CTR cipher mode, | 
					
						
							|  |  |  |   and more) | 
					
						
							|  |  |  | * SHA-3 (including SHAKE XOFs) and BLAKE2 hash algorithms | 
					
						
							|  |  |  | * Salsa20 and ChaCha20 stream ciphers | 
					
						
							|  |  |  | * scrypt and HKDF | 
					
						
							|  |  |  | * Deterministic (EC)DSA | 
					
						
							|  |  |  | * Password-protected PKCS#8 key containers | 
					
						
							|  |  |  | * Shamir's Secret Sharing scheme | 
					
						
							|  |  |  | * Random numbers get sourced directly from the OS (and not from a CSPRNG in userspace) | 
					
						
							|  |  |  | * Simplified install process, including better support for Windows | 
					
						
							|  |  |  | * Cleaner RSA and DSA key generation (largely based on FIPS 186-4) | 
					
						
							|  |  |  | * Major clean ups and simplification of the code base | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyCryptodome is not a wrapper to a separate C library like *OpenSSL*. | 
					
						
							|  |  |  | To the largest possible extent, algorithms are implemented in pure Python. | 
					
						
							|  |  |  | Only the pieces that are extremely critical to performance (e.g. block ciphers) | 
					
						
							|  |  |  | are implemented as C extensions. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | For more information, see the `homepage`_. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | All the code can be downloaded from `GitHub`_. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | .. _OTHER_PROJECT: https://pypi.python.org/pypi/OTHER_PROJECT | 
					
						
							|  |  |  | .. _`homepage`: http://www.pycryptodome.org | 
					
						
							|  |  |  | .. _GitHub: https://github.com/Legrandin/pycryptodome | 
					
						
							|  |  |  | """.replace("THIS_PROJECT", project_name).\
 | 
					
						
							|  |  |  |     replace("THIS_ROOT", package_root).\ | 
					
						
							|  |  |  |     replace("OTHER_PROJECT", other_project).\ | 
					
						
							|  |  |  |     replace("OTHER_ROOT", other_root) | 
					
						
							| 
									
										
										
										
											2014-06-08 21:31:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-18 23:20:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-28 17:38:29 -07:00
										 |  |  | class PCTBuildExt (build_ext): | 
					
						
							| 
									
										
										
										
											2014-12-16 07:50:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 23:21:15 +01:00
										 |  |  |     # Avoid linking Python's dynamic library | 
					
						
							|  |  |  |     def get_libraries(self, ext): | 
					
						
							|  |  |  |         return [] | 
					
						
							| 
									
										
										
										
											2003-02-28 17:38:29 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-07 00:10:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-13 23:11:05 -04:00
										 |  |  | class PCTBuildPy(build_py): | 
					
						
							|  |  |  |     def find_package_modules(self, package, package_dir, *args, **kwargs): | 
					
						
							| 
									
										
										
										
											2010-12-29 13:21:05 -05:00
										 |  |  |         modules = build_py.find_package_modules(self, package, package_dir, | 
					
						
							| 
									
										
										
										
											2018-11-26 12:39:46 +01:00
										 |  |  |                                                 *args, **kwargs) | 
					
						
							| 
									
										
										
										
											2008-08-13 23:11:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         # Exclude certain modules | 
					
						
							| 
									
										
										
										
											2008-09-15 18:16:11 -04:00
										 |  |  |         retval = [] | 
					
						
							|  |  |  |         for item in modules: | 
					
						
							|  |  |  |             pkg, module = item[:2] | 
					
						
							|  |  |  |             retval.append(item) | 
					
						
							|  |  |  |         return retval | 
					
						
							| 
									
										
										
										
											2008-08-13 23:11:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-16 23:50:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-21 13:04:18 -05:00
										 |  |  | class TestCommand(Command): | 
					
						
							| 
									
										
										
										
											2018-11-26 12:39:46 +01:00
										 |  |  |     "Run self-test" | 
					
						
							| 
									
										
										
										
											2008-11-21 13:04:18 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-10 18:52:40 +01:00
										 |  |  |     # Long option name, short option name, description | 
					
						
							| 
									
										
										
										
											2008-11-21 13:04:18 -05:00
										 |  |  |     user_options = [ | 
					
						
							| 
									
										
										
										
											2018-04-10 13:19:30 +02:00
										 |  |  |         ('skip-slow-tests', None, 'Skip slow tests'), | 
					
						
							|  |  |  |         ('wycheproof-warnings', None, 'Show warnings from wycheproof tests'), | 
					
						
							|  |  |  |         ('module=', 'm', 'Test a single module (e.g. Cipher, PublicKey)'), | 
					
						
							| 
									
										
										
										
											2008-11-21 13:04:18 -05:00
										 |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def initialize_options(self): | 
					
						
							|  |  |  |         self.build_dir = None | 
					
						
							|  |  |  |         self.skip_slow_tests = None | 
					
						
							| 
									
										
										
										
											2018-04-10 13:19:30 +02:00
										 |  |  |         self.wycheproof_warnings = None | 
					
						
							| 
									
										
										
										
											2011-01-10 18:52:40 +01:00
										 |  |  |         self.module = None | 
					
						
							| 
									
										
										
										
											2008-11-21 13:04:18 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def finalize_options(self): | 
					
						
							|  |  |  |         self.set_undefined_options('install', ('build_lib', 'build_dir')) | 
					
						
							| 
									
										
										
										
											2018-11-26 12:39:46 +01:00
										 |  |  |         self.config = {'slow_tests': not self.skip_slow_tests, | 
					
						
							|  |  |  |                        'wycheproof_warnings': self.wycheproof_warnings} | 
					
						
							| 
									
										
										
										
											2008-11-21 13:04:18 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def run(self): | 
					
						
							| 
									
										
										
										
											2012-10-14 12:59:59 +02:00
										 |  |  |         # Run sub commands | 
					
						
							|  |  |  |         for cmd_name in self.get_sub_commands(): | 
					
						
							|  |  |  |             self.run_command(cmd_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-21 13:04:18 -05:00
										 |  |  |         # Run SelfTest | 
					
						
							|  |  |  |         old_path = sys.path[:] | 
					
						
							| 
									
										
										
										
											2016-02-16 23:50:20 +01:00
										 |  |  |         self.announce("running self-tests on " + package_root) | 
					
						
							| 
									
										
										
										
											2008-11-21 13:04:18 -05:00
										 |  |  |         try: | 
					
						
							|  |  |  |             sys.path.insert(0, self.build_dir) | 
					
						
							| 
									
										
										
										
											2016-02-16 23:50:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if use_separate_namespace: | 
					
						
							|  |  |  |                 from Cryptodome import SelfTest | 
					
						
							|  |  |  |                 from Cryptodome.Math import Numbers | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 from Crypto import SelfTest | 
					
						
							|  |  |  |                 from Crypto.Math import Numbers | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-10 18:52:40 +01:00
										 |  |  |             moduleObj = None | 
					
						
							|  |  |  |             if self.module: | 
					
						
							| 
									
										
										
										
											2018-11-26 12:39:46 +01:00
										 |  |  |                 if self.module.count('.') == 0: | 
					
						
							| 
									
										
										
										
											2011-01-10 18:52:40 +01:00
										 |  |  |                     # Test a whole a sub-package | 
					
						
							| 
									
										
										
										
											2016-02-16 23:50:20 +01:00
										 |  |  |                     full_module = package_root + ".SelfTest." + self.module | 
					
						
							| 
									
										
										
										
											2011-01-10 18:52:40 +01:00
										 |  |  |                     module_name = self.module | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     # Test only a module | 
					
						
							|  |  |  |                     # Assume only one dot is present | 
					
						
							|  |  |  |                     comps = self.module.split('.') | 
					
						
							|  |  |  |                     module_name = "test_" + comps[1] | 
					
						
							| 
									
										
										
										
											2016-02-16 23:50:20 +01:00
										 |  |  |                     full_module = package_root + ".SelfTest." + comps[0] + "." + module_name | 
					
						
							| 
									
										
										
										
											2011-01-10 18:52:40 +01:00
										 |  |  |                 # Import sub-package or module | 
					
						
							| 
									
										
										
										
											2018-11-26 12:39:46 +01:00
										 |  |  |                 moduleObj = __import__(full_module, globals(), locals(), module_name) | 
					
						
							| 
									
										
										
										
											2015-02-12 21:54:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 23:37:43 +02:00
										 |  |  |             print(package_root + ".Math implementation:", | 
					
						
							| 
									
										
										
										
											2015-02-12 21:54:38 +01:00
										 |  |  |                      str(Numbers._implementation)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-10 18:52:40 +01:00
										 |  |  |             SelfTest.run(module=moduleObj, verbosity=self.verbose, stream=sys.stdout, config=self.config) | 
					
						
							| 
									
										
										
										
											2008-11-21 13:04:18 -05:00
										 |  |  |         finally: | 
					
						
							|  |  |  |             # Restore sys.path | 
					
						
							|  |  |  |             sys.path[:] = old_path | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # Run slower self-tests | 
					
						
							|  |  |  |         self.announce("running extended self-tests") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 12:39:46 +01:00
										 |  |  |     sub_commands = [('build', None)] | 
					
						
							| 
									
										
										
										
											2012-10-14 12:59:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-26 23:08:10 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-04 21:00:22 +01:00
										 |  |  | def create_cryptodome_lib(): | 
					
						
							|  |  |  |     assert os.path.isdir("lib/Crypto") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         shutil.rmtree("lib/Cryptodome") | 
					
						
							|  |  |  |     except OSError: | 
					
						
							|  |  |  |         pass | 
					
						
							|  |  |  |     for root_src, dirs, files in os.walk("lib/Crypto"): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         root_dst, nr_repl = re.subn('Crypto', 'Cryptodome', root_src) | 
					
						
							|  |  |  |         assert nr_repl == 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for dir_name in dirs: | 
					
						
							|  |  |  |             full_dir_name_dst = os.path.join(root_dst, dir_name) | 
					
						
							|  |  |  |             if not os.path.exists(full_dir_name_dst): | 
					
						
							|  |  |  |                 os.makedirs(full_dir_name_dst) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for file_name in files: | 
					
						
							|  |  |  |             full_file_name_src = os.path.join(root_src, file_name) | 
					
						
							|  |  |  |             full_file_name_dst = os.path.join(root_dst, file_name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-29 23:37:43 +02:00
										 |  |  |             print("Copying file %s to %s" % (full_file_name_src, full_file_name_dst)) | 
					
						
							| 
									
										
										
										
											2018-02-04 21:00:22 +01:00
										 |  |  |             shutil.copy2(full_file_name_src, full_file_name_dst) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-17 22:03:53 +02:00
										 |  |  |             if full_file_name_src.split(".")[-1] not in ("py", "pyi"): | 
					
						
							|  |  |  |                 if full_file_name_src != "py.typed": | 
					
						
							|  |  |  |                     continue | 
					
						
							| 
									
										
										
										
											2018-02-04 21:00:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-17 22:07:11 +02:00
										 |  |  |             with open(full_file_name_dst, "rt") as fd: | 
					
						
							|  |  |  |                 content = (fd.read(). | 
					
						
							| 
									
										
										
										
											2018-11-26 12:39:46 +01:00
										 |  |  |                            replace("Crypto.", "Cryptodome."). | 
					
						
							|  |  |  |                            replace("Crypto ", "Cryptodome "). | 
					
						
							|  |  |  |                            replace("'Crypto'", "'Cryptodome'"). | 
					
						
							|  |  |  |                            replace('"Crypto"', '"Cryptodome"')) | 
					
						
							| 
									
										
										
										
											2018-02-04 21:00:22 +01:00
										 |  |  |             os.remove(full_file_name_dst) | 
					
						
							| 
									
										
										
										
											2018-10-17 22:07:11 +02:00
										 |  |  |             with open(full_file_name_dst, "wt") as fd: | 
					
						
							|  |  |  |                 fd.write(content) | 
					
						
							| 
									
										
										
										
											2018-02-04 21:00:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  | # Parameters for setup | 
					
						
							|  |  |  | packages =  [ | 
					
						
							|  |  |  |     "Crypto", | 
					
						
							|  |  |  |     "Crypto.Cipher", | 
					
						
							|  |  |  |     "Crypto.Hash", | 
					
						
							|  |  |  |     "Crypto.IO", | 
					
						
							|  |  |  |     "Crypto.PublicKey", | 
					
						
							|  |  |  |     "Crypto.Protocol", | 
					
						
							|  |  |  |     "Crypto.Random", | 
					
						
							|  |  |  |     "Crypto.Signature", | 
					
						
							|  |  |  |     "Crypto.Util", | 
					
						
							|  |  |  |     "Crypto.Math", | 
					
						
							|  |  |  |     "Crypto.SelfTest", | 
					
						
							|  |  |  |     "Crypto.SelfTest.Cipher", | 
					
						
							|  |  |  |     "Crypto.SelfTest.Hash", | 
					
						
							|  |  |  |     "Crypto.SelfTest.IO", | 
					
						
							|  |  |  |     "Crypto.SelfTest.Protocol", | 
					
						
							|  |  |  |     "Crypto.SelfTest.PublicKey", | 
					
						
							|  |  |  |     "Crypto.SelfTest.Random", | 
					
						
							|  |  |  |     "Crypto.SelfTest.Signature", | 
					
						
							|  |  |  |     "Crypto.SelfTest.Util", | 
					
						
							|  |  |  |     "Crypto.SelfTest.Math", | 
					
						
							|  |  |  | ] | 
					
						
							| 
									
										
										
										
											2018-11-26 12:39:46 +01:00
										 |  |  | package_dir = {"Crypto": "lib/Crypto"} | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  | package_data = { | 
					
						
							| 
									
										
										
										
											2018-10-17 22:03:53 +02:00
										 |  |  |     "Crypto" : [ "py.typed", "*.pyi" ], | 
					
						
							|  |  |  |     "Crypto.Cipher" : [ "*.pyi" ], | 
					
						
							|  |  |  |     "Crypto.Hash" : [ "*.pyi" ], | 
					
						
							| 
									
										
										
										
											2018-11-08 22:03:40 +01:00
										 |  |  |     "Crypto.Math" : [ "*.pyi" ], | 
					
						
							|  |  |  |     "Crypto.Protocol" : [ "*.pyi" ], | 
					
						
							| 
									
										
										
										
											2018-10-17 22:03:53 +02:00
										 |  |  |     "Crypto.PublicKey" : [ "*.pyi" ], | 
					
						
							|  |  |  |     "Crypto.Random" : [ "*.pyi" ], | 
					
						
							| 
									
										
										
										
											2018-11-08 22:03:40 +01:00
										 |  |  |     "Crypto.Signature" : [ "*.pyi" ], | 
					
						
							| 
									
										
										
										
											2019-01-07 08:57:05 +01:00
										 |  |  |     "Crypto.IO" : [ "*.pyi" ], | 
					
						
							|  |  |  |     "Crypto.Util" : [ "*.pyi" ], | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  |     "Crypto.SelfTest.Cipher" : [ | 
					
						
							|  |  |  |         "test_vectors/AES/*.rsp", | 
					
						
							|  |  |  |         "test_vectors/TDES/*.rsp", | 
					
						
							| 
									
										
										
										
											2018-04-09 23:02:50 +02:00
										 |  |  |         "test_vectors/wycheproof/*.json", | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  |     ], | 
					
						
							|  |  |  |     "Crypto.SelfTest.Hash" : [ | 
					
						
							| 
									
										
										
										
											2018-02-23 22:23:02 +01:00
										 |  |  |         "test_vectors/SHA1/*.rsp", | 
					
						
							| 
									
										
										
										
											2018-04-05 22:00:55 +02:00
										 |  |  |         "test_vectors/SHA2/*.rsp", | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  |         "test_vectors/SHA3/*.txt", | 
					
						
							|  |  |  |         "test_vectors/keccak/*.txt", | 
					
						
							|  |  |  |         "test_vectors/BLAKE2s/*.txt", | 
					
						
							| 
									
										
										
										
											2018-04-10 20:34:45 +02:00
										 |  |  |         "test_vectors/BLAKE2b/*.txt", | 
					
						
							|  |  |  |         "test_vectors/wycheproof/*.json", | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  |     ], | 
					
						
							|  |  |  |     "Crypto.SelfTest.Signature" : [ | 
					
						
							|  |  |  |         "test_vectors/DSA/*.*", | 
					
						
							|  |  |  |         "test_vectors/ECDSA/*.*", | 
					
						
							|  |  |  |         "test_vectors/PKCS1-v1.5/*.*", | 
					
						
							| 
									
										
										
										
											2018-04-12 14:13:12 +02:00
										 |  |  |         "test_vectors/PKCS1-PSS/*.*", | 
					
						
							|  |  |  |         "test_vectors/wycheproof/*.json", | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  |     ], | 
					
						
							|  |  |  |     "Crypto.SelfTest.PublicKey" : [ | 
					
						
							|  |  |  |         "test_vectors/ECC/*.*", | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-01-26 23:08:10 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  | system_bits = 8 * struct.calcsize("P") | 
					
						
							|  |  |  | if system_bits == 32: | 
					
						
							|  |  |  |     multiply_cmod = [ 'src/multiply_32.c' ] | 
					
						
							|  |  |  | else: | 
					
						
							|  |  |  |     multiply_cmod = [ 'src/multiply_64.c' ] | 
					
						
							| 
									
										
										
										
											2018-01-26 23:08:10 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  | ext_modules = [ | 
					
						
							|  |  |  |     # Hash functions | 
					
						
							|  |  |  |     Extension("Crypto.Hash._MD2", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/MD2.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Hash._MD4", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/MD4.c"]), | 
					
						
							| 
									
										
										
										
											2018-02-24 16:54:02 +01:00
										 |  |  |     Extension("Crypto.Hash._MD5", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/MD5.c"]), | 
					
						
							| 
									
										
										
										
											2018-02-20 14:13:29 +01:00
										 |  |  |     Extension("Crypto.Hash._SHA1", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/SHA1.c"]), | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  |     Extension("Crypto.Hash._SHA256", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/SHA256.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Hash._SHA224", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/SHA224.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Hash._SHA384", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/SHA384.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Hash._SHA512", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/SHA512.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Hash._RIPEMD160", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/RIPEMD160.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Hash._keccak", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/keccak.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Hash._BLAKE2b", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/blake2b.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Hash._BLAKE2s", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/blake2s.c"]), | 
					
						
							| 
									
										
										
										
											2018-05-31 22:41:26 +02:00
										 |  |  |     Extension("Crypto.Hash._ghash_portable", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=['src/ghash_portable.c']), | 
					
						
							|  |  |  |     Extension("Crypto.Hash._ghash_clmul", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=['src/ghash_clmul.c']), | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-29 22:22:42 +02:00
										 |  |  |     # MACs | 
					
						
							|  |  |  |     Extension("Crypto.Hash._poly1305", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/poly1305.c"]), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  |     # Block encryption algorithms | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._raw_aes", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/AES.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._raw_aesni", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/AESNI.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._raw_arc2", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/ARC2.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._raw_blowfish", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/Blowfish.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._raw_cast", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/CAST.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._raw_des", | 
					
						
							|  |  |  |         include_dirs=['src/', 'src/libtom/'], | 
					
						
							|  |  |  |         sources=["src/DES.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._raw_des3", | 
					
						
							|  |  |  |         include_dirs=['src/', 'src/libtom/'], | 
					
						
							|  |  |  |         sources=["src/DES3.c"]), | 
					
						
							| 
									
										
										
										
											2018-05-31 22:41:26 +02:00
										 |  |  |     Extension("Crypto.Util._cpuid_c", | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=['src/cpuid.c']), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Chaining modes | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._raw_ecb", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/raw_ecb.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._raw_cbc", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/raw_cbc.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._raw_cfb", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/raw_cfb.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._raw_ofb", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/raw_ofb.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._raw_ctr", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/raw_ctr.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._raw_ocb", | 
					
						
							|  |  |  |         sources=["src/raw_ocb.c"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Stream ciphers | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._ARC4", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/ARC4.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._Salsa20", | 
					
						
							|  |  |  |         include_dirs=['src/', 'src/libtom/'], | 
					
						
							|  |  |  |         sources=["src/Salsa20.c"]), | 
					
						
							|  |  |  |     Extension("Crypto.Cipher._chacha20", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/chacha20.c"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Others | 
					
						
							|  |  |  |     Extension("Crypto.Protocol._scrypt", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=["src/scrypt.c"]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Utility modules | 
					
						
							|  |  |  |     Extension("Crypto.Util._strxor", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=['src/strxor.c']), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Math | 
					
						
							|  |  |  |     Extension("Crypto.Math._montgomery", | 
					
						
							|  |  |  |         include_dirs=['src/'], | 
					
						
							|  |  |  |         sources=['src/montgomery.c', 'src/siphash.c', 'src/montgomery_utils.c'] + multiply_cmod, | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  | ] | 
					
						
							| 
									
										
										
										
											2018-01-26 23:08:10 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  | if use_separate_namespace: | 
					
						
							| 
									
										
										
										
											2018-01-31 23:38:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  |     # Fix-up setup information | 
					
						
							|  |  |  |     for i in range(len(packages)): | 
					
						
							|  |  |  |         packages[i] = packages[i].replace("Crypto", "Cryptodome") | 
					
						
							| 
									
										
										
										
											2018-11-26 12:39:46 +01:00
										 |  |  |     package_dir = {"Cryptodome": "lib/Cryptodome"} | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  |     new_package_data = {} | 
					
						
							| 
									
										
										
										
											2018-11-26 12:39:46 +01:00
										 |  |  |     for k, v in package_data.items(): | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  |         new_package_data[k.replace("Crypto", "Cryptodome")] = v | 
					
						
							|  |  |  |     package_data = new_package_data | 
					
						
							|  |  |  |     for ext in ext_modules: | 
					
						
							|  |  |  |         ext.name = ext.name.replace("Crypto", "Cryptodome") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-04 21:00:22 +01:00
										 |  |  |     # Recreate lib/Cryptodome from scratch, unless it is the only | 
					
						
							|  |  |  |     # directory available | 
					
						
							|  |  |  |     if os.path.isdir("lib/Crypto"): | 
					
						
							|  |  |  |         create_cryptodome_lib() | 
					
						
							| 
									
										
										
										
											2018-01-26 23:08:10 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-26 21:19:04 +01:00
										 |  |  | # Add compiler specific options. | 
					
						
							|  |  |  | set_compiler_options(package_root, ext_modules) | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-24 08:55:53 +03:00
										 |  |  | # By doing this we need to change version information in a single file | 
					
						
							| 
									
										
										
										
											2018-08-09 13:23:17 +02:00
										 |  |  | with open(os.path.join("lib", package_root, "__init__.py")) as init_root: | 
					
						
							|  |  |  |     for line in init_root: | 
					
						
							|  |  |  |         if line.startswith("version_info"): | 
					
						
							|  |  |  |             version_tuple = eval(line.split("=")[1]) | 
					
						
							| 
									
										
										
										
											2018-02-03 22:33:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-18 14:25:08 +01:00
										 |  |  | version_string = ".".join([str(x) for x in version_tuple]) | 
					
						
							| 
									
										
										
										
											2018-01-20 23:50:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-25 11:03:35 +02:00
										 |  |  | setup( | 
					
						
							| 
									
										
										
										
											2018-09-24 11:29:20 +03:00
										 |  |  |     name=project_name, | 
					
						
							|  |  |  |     version=version_string, | 
					
						
							|  |  |  |     description="Cryptographic library for Python", | 
					
						
							|  |  |  |     long_description=longdesc, | 
					
						
							|  |  |  |     author="Helder Eijs", | 
					
						
							|  |  |  |     author_email="helderijs@gmail.com", | 
					
						
							|  |  |  |     url="https://www.pycryptodome.org", | 
					
						
							|  |  |  |     platforms='Posix; MacOS X; Windows', | 
					
						
							|  |  |  |     zip_safe=False, | 
					
						
							|  |  |  |     python_requires='>=2.6, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*', | 
					
						
							|  |  |  |     classifiers=[ | 
					
						
							| 
									
										
										
										
											2014-05-25 14:33:34 +02:00
										 |  |  |         'Development Status :: 4 - Beta', | 
					
						
							| 
									
										
										
										
											2014-06-24 07:38:05 +02:00
										 |  |  |         'License :: OSI Approved :: BSD License', | 
					
						
							| 
									
										
										
										
											2015-03-15 21:32:10 +01:00
										 |  |  |         'License :: Public Domain', | 
					
						
							| 
									
										
										
										
											2014-05-25 11:03:35 +02:00
										 |  |  |         'Intended Audience :: Developers', | 
					
						
							|  |  |  |         'Operating System :: Unix', | 
					
						
							|  |  |  |         'Operating System :: Microsoft :: Windows', | 
					
						
							|  |  |  |         'Operating System :: MacOS :: MacOS X', | 
					
						
							|  |  |  |         'Topic :: Security :: Cryptography', | 
					
						
							|  |  |  |         'Programming Language :: Python :: 2', | 
					
						
							| 
									
										
										
										
											2015-11-01 06:22:21 -05:00
										 |  |  |         'Programming Language :: Python :: 2.6', | 
					
						
							|  |  |  |         'Programming Language :: Python :: 2.7', | 
					
						
							| 
									
										
										
										
											2014-05-25 11:03:35 +02:00
										 |  |  |         'Programming Language :: Python :: 3', | 
					
						
							| 
									
										
										
										
											2018-09-24 11:29:20 +03:00
										 |  |  |         'Programming Language :: Python :: 3.4', | 
					
						
							|  |  |  |         'Programming Language :: Python :: 3.5', | 
					
						
							|  |  |  |         'Programming Language :: Python :: 3.6', | 
					
						
							|  |  |  |         'Programming Language :: Python :: 3.7', | 
					
						
							| 
									
										
										
										
											2014-05-25 11:03:35 +02:00
										 |  |  |     ], | 
					
						
							| 
									
										
										
										
											2018-11-24 15:08:57 +01:00
										 |  |  |     license="BSD, Public Domain", | 
					
						
							| 
									
										
										
										
											2018-09-24 11:29:20 +03:00
										 |  |  |     packages=packages, | 
					
						
							|  |  |  |     package_dir=package_dir, | 
					
						
							|  |  |  |     package_data=package_data, | 
					
						
							|  |  |  |     cmdclass={ | 
					
						
							| 
									
										
										
										
											2018-11-26 12:39:46 +01:00
										 |  |  |         'build_ext': PCTBuildExt, | 
					
						
							| 
									
										
										
										
											2014-05-25 11:03:35 +02:00
										 |  |  |         'build_py': PCTBuildPy, | 
					
						
							| 
									
										
										
										
											2018-01-26 23:08:10 +01:00
										 |  |  |         'test': TestCommand, | 
					
						
							| 
									
										
										
										
											2014-05-25 11:03:35 +02:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2018-09-24 11:29:20 +03:00
										 |  |  |     ext_modules=ext_modules, | 
					
						
							| 
									
										
										
										
											2014-05-25 11:03:35 +02:00
										 |  |  | ) |