Skip to content

Commit c023f4f

Browse files
committed
Merge branch 'rust-test-ed25519'
2 parents 8555ef8 + 0df6c87 commit c023f4f

File tree

2 files changed

+22
-58
lines changed

2 files changed

+22
-58
lines changed

src/rust/bitbox02/src/keystore.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ pub fn secp256k1_schnorr_sign(
356356
#[cfg(test)]
357357
mod tests {
358358
use super::*;
359-
use crate::testing::{mock_memory, mock_unlocked, mock_unlocked_using_mnemonic};
359+
use crate::testing::{mock_memory, mock_unlocked_using_mnemonic};
360360
use alloc::string::ToString;
361361
use util::bip32::HARDENED;
362362

@@ -440,10 +440,28 @@ mod tests {
440440
lock();
441441
assert!(get_ed25519_seed().is_err());
442442

443-
mock_unlocked();
443+
// Test vectors taken from:
444+
// https://github.com/cardano-foundation/CIPs/blob/6c249ef48f8f5b32efc0ec768fadf4321f3173f2/CIP-0003/Ledger.md#test-vectors
445+
// See also: https://github.com/cardano-foundation/CIPs/pull/132
446+
447+
mock_unlocked_using_mnemonic("recall grace sport punch exhibit mad harbor stand obey short width stem awkward used stairs wool ugly trap season stove worth toward congress jaguar", "");
448+
assert_eq!(
449+
hex::encode(get_ed25519_seed().unwrap()),
450+
"a08cf85b564ecf3b947d8d4321fb96d70ee7bb760877e371899b14e2ccf88658104b884682b57efd97decbb318a45c05a527b9cc5c2f64f7352935a049ceea60680d52308194ccef2a18e6812b452a5815fbd7f5babc083856919aaf668fe7e4",
451+
);
452+
453+
// Multiple loop iterations.
454+
455+
mock_unlocked_using_mnemonic("correct cherry mammal bubble want mandate polar hazard crater better craft exotic choice fun tourist census gap lottery neglect address glow carry old business", "");
456+
assert_eq!(
457+
hex::encode(get_ed25519_seed().unwrap()),
458+
"587c6774357ecbf840d4db6404ff7af016dace0400769751ad2abfc77b9a3844cc71702520ef1a4d1b68b91187787a9b8faab0a9bb6b160de541b6ee62469901fc0beda0975fe4763beabd83b7051a5fd5cbce5b88e82c4bbaca265014e524bd",
459+
);
460+
461+
mock_unlocked_using_mnemonic("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art", "foo");
444462
assert_eq!(
445-
get_ed25519_seed().unwrap().as_ref() as &[u8],
446-
b"\xf8\xcb\x28\x85\x37\x60\x2b\x90\xd1\x29\x75\x4b\xdd\x0e\x4b\xed\xf9\xe2\x92\x3a\x04\xb6\x86\x7e\xdb\xeb\xc7\x93\xa7\x17\x6f\x5d\xca\xc5\xc9\x5d\x5f\xd2\x3a\x8e\x01\x6c\x95\x57\x69\x0e\xad\x1f\x00\x2b\x0f\x35\xd7\x06\xff\x8e\x59\x84\x1c\x09\xe0\xb6\xbb\x23\xf0\xa5\x91\x06\x42\xd0\x77\x98\x17\x40\x2e\x5e\x7a\x75\x54\x95\xe7\x44\xf5\x5c\xf1\x1e\x49\xee\xfd\x22\xa4\x60\xe9\xb2\xf7\x53",
463+
hex::encode(get_ed25519_seed().unwrap()),
464+
"f053a1e752de5c26197b60f032a4809f08bb3e5d90484fe42024be31efcba7578d914d3ff992e21652fee6a4d99f6091006938fac2c0c0f9d2de0ba64b754e92a4f3723f23472077aa4cd4dd8a8a175dba07ea1852dad1cf268c61a2679c3890",
447465
);
448466
}
449467

test/unit-test/test_keystore.c

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -524,59 +524,6 @@ static void _mock_with_mnemonic(const char* mnemonic, const char* passphrase)
524524
assert_true(keystore_unlock_bip39(passphrase));
525525
}
526526

527-
static void _test_keystore_get_ed25519_seed(void** state)
528-
{
529-
// Test vectors taken from:
530-
// https://github.com/cardano-foundation/CIPs/blob/6c249ef48f8f5b32efc0ec768fadf4321f3173f2/CIP-0003/Ledger.md#test-vectors
531-
// See also: https://github.com/cardano-foundation/CIPs/pull/132
532-
533-
_mock_with_mnemonic(
534-
"recall grace sport punch exhibit mad harbor stand obey short width stem awkward used "
535-
"stairs wool ugly trap season stove worth toward congress jaguar",
536-
"");
537-
538-
uint8_t seed[96];
539-
assert_true(keystore_get_ed25519_seed(seed));
540-
assert_memory_equal(
541-
seed,
542-
"\xa0\x8c\xf8\x5b\x56\x4e\xcf\x3b\x94\x7d\x8d\x43\x21\xfb\x96\xd7\x0e\xe7\xbb\x76\x08\x77"
543-
"\xe3\x71\x89\x9b\x14\xe2\xcc\xf8\x86\x58\x10\x4b\x88\x46\x82\xb5\x7e\xfd\x97\xde\xcb\xb3"
544-
"\x18\xa4\x5c\x05\xa5\x27\xb9\xcc\x5c\x2f\x64\xf7\x35\x29\x35\xa0\x49\xce\xea\x60\x68\x0d"
545-
"\x52\x30\x81\x94\xcc\xef\x2a\x18\xe6\x81\x2b\x45\x2a\x58\x15\xfb\xd7\xf5\xba\xbc\x08\x38"
546-
"\x56\x91\x9a\xaf\x66\x8f\xe7\xe4",
547-
sizeof(seed));
548-
549-
// Multiple loop iterations.
550-
_mock_with_mnemonic(
551-
"correct cherry mammal bubble want mandate polar hazard crater better craft exotic choice "
552-
"fun tourist census gap lottery neglect address glow carry old business",
553-
"");
554-
assert_true(keystore_get_ed25519_seed(seed));
555-
assert_memory_equal(
556-
seed,
557-
"\x58\x7c\x67\x74\x35\x7e\xcb\xf8\x40\xd4\xdb\x64\x04\xff\x7a\xf0\x16\xda\xce\x04\x00\x76"
558-
"\x97\x51\xad\x2a\xbf\xc7\x7b\x9a\x38\x44\xcc\x71\x70\x25\x20\xef\x1a\x4d\x1b\x68\xb9\x11"
559-
"\x87\x78\x7a\x9b\x8f\xaa\xb0\xa9\xbb\x6b\x16\x0d\xe5\x41\xb6\xee\x62\x46\x99\x01\xfc\x0b"
560-
"\xed\xa0\x97\x5f\xe4\x76\x3b\xea\xbd\x83\xb7\x05\x1a\x5f\xd5\xcb\xce\x5b\x88\xe8\x2c\x4b"
561-
"\xba\xca\x26\x50\x14\xe5\x24\xbd",
562-
sizeof(seed));
563-
564-
_mock_with_mnemonic(
565-
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon "
566-
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon "
567-
"abandon art",
568-
"foo");
569-
assert_true(keystore_get_ed25519_seed(seed));
570-
assert_memory_equal(
571-
seed,
572-
"\xf0\x53\xa1\xe7\x52\xde\x5c\x26\x19\x7b\x60\xf0\x32\xa4\x80\x9f\x08\xbb\x3e\x5d\x90\x48"
573-
"\x4f\xe4\x20\x24\xbe\x31\xef\xcb\xa7\x57\x8d\x91\x4d\x3f\xf9\x92\xe2\x16\x52\xfe\xe6\xa4"
574-
"\xd9\x9f\x60\x91\x00\x69\x38\xfa\xc2\xc0\xc0\xf9\xd2\xde\x0b\xa6\x4b\x75\x4e\x92\xa4\xf3"
575-
"\x72\x3f\x23\x47\x20\x77\xaa\x4c\xd4\xdd\x8a\x8a\x17\x5d\xba\x07\xea\x18\x52\xda\xd1\xcf"
576-
"\x26\x8c\x61\xa2\x67\x9c\x38\x90",
577-
sizeof(seed));
578-
}
579-
580527
// This tests that `secp256k1_schnorrsig_sign()` is the correct function to be used for schnorr sigs
581528
// in taproot. It is a separate test because there are test vectors available for this which cannot
582529
// be made to work with `keystore_secp256k1_schnorr_bip86_sign()`.
@@ -695,7 +642,6 @@ int main(void)
695642
cmocka_unit_test(_test_keystore_lock),
696643
cmocka_unit_test(_test_keystore_bip39_mnemonic_from_seed),
697644
cmocka_unit_test(_test_keystore_create_and_store_seed),
698-
cmocka_unit_test(_test_keystore_get_ed25519_seed),
699645
cmocka_unit_test(_test_secp256k1_schnorr_sign),
700646
cmocka_unit_test(_test_keystore_secp256k1_schnorr_sign),
701647
};

0 commit comments

Comments
 (0)