enable use of pyaes package for testing
This commit is contained in:
parent
75ced150ba
commit
c4feeccb66
5 changed files with 21 additions and 2 deletions
|
|
@ -401,7 +401,10 @@ class Autosign:
|
|||
cfg = self.cfg,
|
||||
prompt = f'Default wallet ‘{wf}’ found.\nUse default wallet for autosigning?',
|
||||
default_yes = True):
|
||||
ss_in = Wallet(Config(), fn=wf)
|
||||
ss_in = Wallet(Config({
|
||||
'test_suite': self.cfg.test_suite,
|
||||
'aes_backend': self.cfg.aes_backend
|
||||
}), fn=wf)
|
||||
else:
|
||||
ss_in = get_mn_wallet()
|
||||
|
||||
|
|
|
|||
|
|
@ -229,6 +229,7 @@ class Config(Lockable):
|
|||
autochg_ignore_labels = False
|
||||
autosign = False
|
||||
threaded_python = not sys._is_gil_enabled()
|
||||
aes_backend = 'cryptography'
|
||||
|
||||
# regtest:
|
||||
bob = False
|
||||
|
|
@ -333,6 +334,7 @@ class Config(Lockable):
|
|||
_env_opts = (
|
||||
'MMGEN_DEBUG_ALL', # special: there is no `debug_all` attribute
|
||||
|
||||
'MMGEN_AES_BACKEND',
|
||||
'MMGEN_BLACKLIST_DAEMONS',
|
||||
'MMGEN_BOGUS_SEND',
|
||||
'MMGEN_BOGUS_UNSPENT_DATA',
|
||||
|
|
|
|||
|
|
@ -67,6 +67,9 @@ class Crypto:
|
|||
def __init__(self, cfg):
|
||||
self.cfg = cfg
|
||||
self.util = cfg._util
|
||||
if cfg.test_suite and self.cfg.aes_backend == 'pyaes':
|
||||
self.get_aes_ctr = self.get_aes_ctr_pyaes
|
||||
self.encrypt_aes_ctr = self.encrypt_aes_ctr_pyaes
|
||||
|
||||
@staticmethod
|
||||
def get_aes_ctr(key, iv):
|
||||
|
|
@ -78,6 +81,16 @@ class Crypto:
|
|||
encryptor = self.get_aes_ctr(key, iv)
|
||||
return encryptor.update(data) + encryptor.finalize()
|
||||
|
||||
@staticmethod
|
||||
def get_aes_ctr_pyaes(key, iv):
|
||||
import pyaes
|
||||
class MyAES(pyaes.AESModeOfOperationCTR):
|
||||
update = pyaes.AESModeOfOperationCTR.encrypt
|
||||
return MyAES(key, pyaes.Counter(int.from_bytes(iv)))
|
||||
|
||||
def encrypt_aes_ctr_pyaes(self, key, iv, data):
|
||||
return self.get_aes_ctr_pyaes(key, iv).encrypt(data)
|
||||
|
||||
def get_hash_params(self, hash_preset):
|
||||
if hash_preset in self.hash_presets:
|
||||
return self.hash_presets[hash_preset] # N, r, p
|
||||
|
|
|
|||
|
|
@ -54,5 +54,6 @@ rec {
|
|||
# pydantic = pydantic; # eth-keys
|
||||
# pure-protobuf = pure-protobuf; # THORChain
|
||||
# bip-utils = bip-utils; # bip_hd
|
||||
# pyaes = pyaes; # developer testing
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class unit_tests:
|
|||
msg('Is the ‘pysocks’ package installed?')
|
||||
return False
|
||||
|
||||
def cryptography(self, name, ut):
|
||||
def aes(self, name, ut):
|
||||
from mmgen.crypto import Crypto
|
||||
Crypto(cfg).encrypt_aes_ctr(b'deadbeef' * 4, b'deadbeef' * 2, b'foo')
|
||||
return True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue