From 0668ff23fca129fde78f4a73faddc26676d65ee4 Mon Sep 17 00:00:00 2001 From: Sergiy Yevtushenko Date: Wed, 30 Oct 2024 16:04:53 +0100 Subject: [PATCH] Make Clippy happy #6 --- ragger_tests/test_sign_tx_ed25519.py | 4 +++- ragger_tests/test_sign_tx_secp256k1.py | 3 +++ src/crypto/ed25519.rs | 9 +++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ragger_tests/test_sign_tx_ed25519.py b/ragger_tests/test_sign_tx_ed25519.py index bb65adc0..93ef3db9 100644 --- a/ragger_tests/test_sign_tx_ed25519.py +++ b/ragger_tests/test_sign_tx_ed25519.py @@ -10,7 +10,6 @@ DATA_PATH = str(Path(__file__).parent.joinpath("data").absolute()) + "/" ROOT_SCREENSHOT_PATH = Path(__file__).parent.resolve() - def read_file(file): with open(DATA_PATH + file, "rb") as f: return f.read() @@ -53,12 +52,15 @@ def sign_tx_ed25519(firmware, backend, navigator, click_count, file_name, test_n except Exception as e: if click_count == 0: return + print("Communication error ", e) + raise pubkey = ed25519.Ed25519PublicKey.from_public_bytes(bytes(rc[64:96])) try: pubkey.verify(bytes(rc[0:64]), bytes(rc[96:128])) except Exception as e: print("Invalid signature ", e) + raise def test_sign_tx_ed25519_call_function(firmware, backend, navigator, test_name): diff --git a/ragger_tests/test_sign_tx_secp256k1.py b/ragger_tests/test_sign_tx_secp256k1.py index 7ff8af6e..f84eb328 100644 --- a/ragger_tests/test_sign_tx_secp256k1.py +++ b/ragger_tests/test_sign_tx_secp256k1.py @@ -55,6 +55,8 @@ def sign_tx_secp256k1(firmware, backend, navigator, click_count, file_name, test except Exception as e: if click_count == 0: return + print("Communication error ", e) + raise r = int.from_bytes(rc[1:33], byteorder='big', signed=False) s = int.from_bytes(rc[33:65], byteorder='big', signed=False) @@ -67,6 +69,7 @@ def sign_tx_secp256k1(firmware, backend, navigator, click_count, file_name, test assert rc[98:130].hex() == vector[0], "Invalid calculated hash\nExpected: " + vector[0] + "\nReceived: " + rc[98:130].hex() except Exception as e: print("Invalid signature ", e) + raise def test_sign_tx_secp256k1_call_function(firmware, backend, navigator, test_name): diff --git a/src/crypto/ed25519.rs b/src/crypto/ed25519.rs index a2ad3e03..a00756b4 100644 --- a/src/crypto/ed25519.rs +++ b/src/crypto/ed25519.rs @@ -91,12 +91,9 @@ impl KeyPair25519 { pub fn public_bytes(&self) -> [u8; ED25519_PUBLIC_KEY_LEN] { let mut pk = [0u8; ED25519_PUBLIC_KEY_LEN]; - self.origin.public.W[33..65] - .iter() - .enumerate() - .for_each(|(i, &v)| { - pk[31 - i] = v; - }); + (0..ED25519_PUBLIC_KEY_LEN).for_each(|i| { + pk[i] = self.origin.public.W[64 - i]; + }); if self.origin.public.W[32] & 1u8 == 1 { pk[31] |= 0x80;