From 4ad9428dfa75a7dc8249ff6f9356b31cfce63879 Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Sat, 29 Jul 2017 19:20:43 +0900 Subject: [PATCH] Support both pycryptodome and pycryptodomex --- pywii/Common/pywii/ec.py | 5 ++++- pywii/Common/pywii/wii.py | 17 ++++++++++++----- pywii/pywii-tools/tmdupdatecr.py | 5 ++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/pywii/Common/pywii/ec.py b/pywii/Common/pywii/ec.py index a0468b8..6cef40a 100644 --- a/pywii/Common/pywii/ec.py +++ b/pywii/Common/pywii/ec.py @@ -6,7 +6,10 @@ from array import array from struct import pack, unpack -from Cryptodome.Util.number import bytes_to_long, long_to_bytes +try: + from Cryptodome.Util.number import bytes_to_long, long_to_bytes +except ImportError: + from Crypto.Util.number import bytes_to_long, long_to_bytes # y**2 + x*y = x**3 + x + b ec_b = "\x00\x66\x64\x7e\xde\x6c\x33\x2c\x7f\x8c\x09\x23\xbb\x58\x21"+\ diff --git a/pywii/Common/pywii/wii.py b/pywii/Common/pywii/wii.py index 1338dff..9484d3a 100644 --- a/pywii/Common/pywii/wii.py +++ b/pywii/Common/pywii/wii.py @@ -8,11 +8,18 @@ from struct import unpack, pack import os, os.path import sys -from Cryptodome.Cipher import AES -from Cryptodome.Hash import SHA -from Cryptodome.PublicKey import RSA -from Cryptodome.Util.number import bytes_to_long, long_to_bytes -from Cryptodome.Signature import pkcs1_15 +try: + from Cryptodome.Cipher import AES + from Cryptodome.Hash import SHA + from Cryptodome.PublicKey import RSA + from Cryptodome.Util.number import bytes_to_long, long_to_bytes + from Cryptodome.Signature import pkcs1_15 +except ImportError: + from Crypto.Cipher import AES + from Crypto.Hash import SHA + from Crypto.PublicKey import RSA + from Crypto.Util.number import bytes_to_long, long_to_bytes + from Crypto.Signature import pkcs1_15 import ec diff --git a/pywii/pywii-tools/tmdupdatecr.py b/pywii/pywii-tools/tmdupdatecr.py index 0778dc5..55ac566 100755 --- a/pywii/pywii-tools/tmdupdatecr.py +++ b/pywii/pywii-tools/tmdupdatecr.py @@ -2,7 +2,10 @@ import sys, os, os.path import pywii as wii -from Cryptodome.Hash import SHA +try: + from Cryptodome.Hash import SHA +except ImportError: + from Crypto.Hash import SHA wii.loadkeys()