enable use of pyaes package for testing

This commit is contained in:
The MMGen Project 2026-05-21 12:09:33 +00:00
commit c4feeccb66
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
5 changed files with 21 additions and 2 deletions

View file

@ -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()

View file

@ -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',

View file

@ -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

View file

@ -54,5 +54,6 @@ rec {
# pydantic = pydantic; # eth-keys
# pure-protobuf = pure-protobuf; # THORChain
# bip-utils = bip-utils; # bip_hd
# pyaes = pyaes; # developer testing
};
}

View file

@ -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