Skip to content

Commit

Permalink
Make Clippy happy #6
Browse files Browse the repository at this point in the history
  • Loading branch information
siy committed Oct 30, 2024
1 parent bbaf46f commit 0668ff2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion ragger_tests/test_sign_tx_ed25519.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions ragger_tests/test_sign_tx_secp256k1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
9 changes: 3 additions & 6 deletions src/crypto/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0668ff2

Please sign in to comment.