Skip to content

Commit e6cc02f

Browse files
committed
Merge remote-tracking branch 'benma/ed25519-test'
2 parents 4a64cac + 1233b2a commit e6cc02f

File tree

11 files changed

+91
-19
lines changed

11 files changed

+91
-19
lines changed

src/rust/bitbox02-rust/src/hww/api/backup.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ mod tests {
231231
mock_sd();
232232
mock_unlocked_using_mnemonic(
233233
"memory raven era cave phone system dice come mechanic split moon repeat",
234+
"",
234235
);
235236
mock_memory();
236237

@@ -278,7 +279,7 @@ mod tests {
278279
ui_confirm_create: Some(Box::new(|_params| true)),
279280
..Default::default()
280281
});
281-
mock_unlocked_using_mnemonic("purity concert above invest pigeon category peace tuition hazard vivid latin since legal speak nation session onion library travel spell region blast estate stay");
282+
mock_unlocked_using_mnemonic("purity concert above invest pigeon category peace tuition hazard vivid latin since legal speak nation session onion library travel spell region blast estate stay", "");
282283
mock_memory();
283284
bitbox02::memory::set_device_name(DEVICE_NAME_1).unwrap();
284285
assert!(block_on(create(&pb::CreateBackupRequest {
@@ -304,7 +305,7 @@ mod tests {
304305
ui_confirm_create: Some(Box::new(|_params| true)),
305306
..Default::default()
306307
});
307-
mock_unlocked_using_mnemonic("goddess item rack improve shaft occur actress rib emerge salad rich blame model glare lounge stable electric height scrub scrub oyster now dinner oven");
308+
mock_unlocked_using_mnemonic("goddess item rack improve shaft occur actress rib emerge salad rich blame model glare lounge stable electric height scrub scrub oyster now dinner oven", "");
308309
mock_memory();
309310
bitbox02::memory::set_device_name(DEVICE_NAME_2).unwrap();
310311
assert!(block_on(create(&pb::CreateBackupRequest {

src/rust/bitbox02-rust/src/hww/api/bitcoin.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ mod tests {
394394
expected_display_title: "Litecoin\naccount #1",
395395
},
396396
] {
397-
mock_unlocked_using_mnemonic(test.mnemonic);
397+
mock_unlocked_using_mnemonic(test.mnemonic, "");
398398

399399
// Without display.
400400
let mut req = pb::BtcPubRequest {
@@ -424,7 +424,7 @@ mod tests {
424424
})),
425425
..Default::default()
426426
});
427-
mock_unlocked_using_mnemonic(test.mnemonic);
427+
mock_unlocked_using_mnemonic(test.mnemonic, "");
428428
assert_eq!(
429429
block_on(process_pub(&req)),
430430
Ok(Response::Pub(pb::PubResponse {
@@ -678,7 +678,7 @@ mod tests {
678678
};
679679

680680
// Without display.
681-
mock_unlocked_using_mnemonic(test.mnemonic);
681+
mock_unlocked_using_mnemonic(test.mnemonic, "");
682682
assert_eq!(
683683
block_on(process_pub(&req)),
684684
Ok(Response::Pub(pb::PubResponse {
@@ -699,7 +699,7 @@ mod tests {
699699
})),
700700
..Default::default()
701701
});
702-
mock_unlocked_using_mnemonic(test.mnemonic);
702+
mock_unlocked_using_mnemonic(test.mnemonic, "");
703703
assert_eq!(
704704
block_on(process_pub(&req)),
705705
Ok(Response::Pub(pb::PubResponse {
@@ -908,6 +908,7 @@ mod tests {
908908
});
909909
mock_unlocked_using_mnemonic(
910910
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
911+
"",
911912
);
912913

913914
let multisig = Multisig {

src/rust/bitbox02-rust/src/hww/api/bitcoin/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ mod tests {
538538
fn test_payload_simple() {
539539
mock_unlocked_using_mnemonic(
540540
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
541+
"",
541542
);
542543
let mut xpub_cache = Bip32XpubCache::new();
543544
let coin_params = super::super::params::get(pb::BtcCoin::Btc);

src/rust/bitbox02-rust/src/hww/api/bitcoin/multisig.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ mod tests {
714714
// ok.
715715
mock_unlocked_using_mnemonic(
716716
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
717+
"",
717718
);
718719
assert!(validate(&multisig, keypath, expected_coin).is_ok());
719720

src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,7 @@ mod tests {
24462446
});
24472447
mock_unlocked_using_mnemonic(
24482448
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
2449+
"",
24492450
);
24502451
// For the multisig registration below.
24512452
mock_memory();
@@ -2514,6 +2515,7 @@ mod tests {
25142515
mock_default_ui();
25152516
mock_unlocked_using_mnemonic(
25162517
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
2518+
"",
25172519
);
25182520
let init_request = {
25192521
let tx = transaction.borrow();
@@ -2571,6 +2573,7 @@ mod tests {
25712573
mock_default_ui();
25722574
mock_unlocked_using_mnemonic(
25732575
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
2576+
"",
25742577
);
25752578
// For the multisig registration below.
25762579
mock_memory();
@@ -2635,6 +2638,7 @@ mod tests {
26352638
mock_default_ui();
26362639
mock_unlocked_using_mnemonic(
26372640
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
2641+
"",
26382642
);
26392643
// For the multisig registration below.
26402644
mock_memory();

src/rust/bitbox02-rust/src/hww/api/rootfingerprint.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ mod tests {
4242
assert_eq!(process(), Err(Error::Generic));
4343

4444
mock_unlocked_using_mnemonic(
45-
"purity concert above invest pigeon category peace tuition hazard vivid latin since legal speak nation session onion library travel spell region blast estate stay"
45+
"purity concert above invest pigeon category peace tuition hazard vivid latin since legal speak nation session onion library travel spell region blast estate stay",
46+
"",
4647
);
4748
assert_eq!(
4849
process(),
@@ -53,6 +54,7 @@ mod tests {
5354

5455
mock_unlocked_using_mnemonic(
5556
"small agent wife animal marine cloth exit thank stool idea steel frame",
57+
"",
5658
);
5759
assert_eq!(
5860
process(),

src/rust/bitbox02-rust/src/keystore.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ mod tests {
4848
assert!(get_xpub(keypath).is_err());
4949

5050
// 24 words
51-
mock_unlocked_using_mnemonic("sleep own lobster state clean thrive tail exist cactus bitter pass soccer clinic riot dream turkey before sport action praise tunnel hood donate man");
51+
mock_unlocked_using_mnemonic(
52+
"sleep own lobster state clean thrive tail exist cactus bitter pass soccer clinic riot dream turkey before sport action praise tunnel hood donate man",
53+
"",
54+
);
5255
assert_eq!(
5356
get_xpub(&[]).unwrap().serialize_str(bip32::XPubType::Xpub).unwrap(),
5457
"xpub661MyMwAqRbcEhX8d9WJh78SZrxusAzWFoykz4n5CF75uYRzixw5FZPUSoWyhaaJ1bpiPFdzdHSQqJN38PcTkyrLmxT4J2JDYfoGJQ4ioE2",
@@ -59,7 +62,10 @@ mod tests {
5962
);
6063

6164
// 18 words
62-
mock_unlocked_using_mnemonic("sleep own lobster state clean thrive tail exist cactus bitter pass soccer clinic riot dream turkey before subject");
65+
mock_unlocked_using_mnemonic(
66+
"sleep own lobster state clean thrive tail exist cactus bitter pass soccer clinic riot dream turkey before subject",
67+
"",
68+
);
6369
assert_eq!(
6470
get_xpub(keypath).unwrap().serialize_str(bip32::XPubType::Xpub).unwrap(),
6571
"xpub6C7fKxGtTzEVxCC22U2VHx4GpaVy77DzU6KdZ1CLuHgoUGviBMWDc62uoQVxqcRa5RQbMPnffjpwxve18BG81VJhJDXnSpRe5NGKwVpXiAb",
@@ -68,6 +74,7 @@ mod tests {
6874
// 12 words
6975
mock_unlocked_using_mnemonic(
7076
"sleep own lobster state clean thrive tail exist cactus bitter pass sniff",
77+
"",
7178
);
7279
assert_eq!(
7380
get_xpub(keypath).unwrap().serialize_str(bip32::XPubType::Xpub).unwrap(),
@@ -81,12 +88,14 @@ mod tests {
8188
assert_eq!(root_fingerprint(), Err(()));
8289

8390
mock_unlocked_using_mnemonic(
84-
"purity concert above invest pigeon category peace tuition hazard vivid latin since legal speak nation session onion library travel spell region blast estate stay"
91+
"purity concert above invest pigeon category peace tuition hazard vivid latin since legal speak nation session onion library travel spell region blast estate stay",
92+
"",
8593
);
8694
assert_eq!(root_fingerprint(), Ok(vec![0x02, 0x40, 0xe9, 0x2a]));
8795

8896
mock_unlocked_using_mnemonic(
8997
"small agent wife animal marine cloth exit thank stool idea steel frame",
98+
"",
9099
);
91100
assert_eq!(root_fingerprint(), Ok(vec![0xf4, 0x0b, 0x46, 0x9a]));
92101
}

src/rust/bitbox02-rust/src/keystore/ed25519.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use alloc::vec::Vec;
16+
1517
use bip32_ed25519::{Xprv, Xpub, ED25519_EXPANDED_SECRET_KEY_SIZE};
1618

19+
fn get_seed() -> Result<zeroize::Zeroizing<Vec<u8>>, ()> {
20+
bitbox02::keystore::get_ed25519_seed()
21+
}
22+
1723
fn get_xprv(keypath: &[u32]) -> Result<Xprv, ()> {
18-
let root = bitbox02::keystore::get_ed25519_seed()?;
24+
let root = get_seed()?;
1925
Ok(Xprv::from_normalize(
2026
&root[..ED25519_EXPANDED_SECRET_KEY_SIZE],
2127
&root[ED25519_EXPANDED_SECRET_KEY_SIZE..],
@@ -48,10 +54,46 @@ mod tests {
4854
use super::*;
4955

5056
use bip32_ed25519::HARDENED_OFFSET;
51-
use bitbox02::testing::mock_unlocked;
57+
use bitbox02::testing::{mock_unlocked, mock_unlocked_using_mnemonic};
58+
59+
#[test]
60+
fn test_get_seed() {
61+
// Test vectors taken from:
62+
// https://github.com/cardano-foundation/CIPs/blob/6c249ef48f8f5b32efc0ec768fadf4321f3173f2/CIP-0003/Ledger.md#test-vectors
63+
// See also: https://github.com/cardano-foundation/CIPs/pull/132
64+
65+
mock_unlocked_using_mnemonic(
66+
"recall grace sport punch exhibit mad harbor stand obey short width stem awkward used stairs wool ugly trap season stove worth toward congress jaguar",
67+
"",
68+
);
69+
assert_eq!(
70+
get_seed().unwrap().as_slice(),
71+
b"\xa0\x8c\xf8\x5b\x56\x4e\xcf\x3b\x94\x7d\x8d\x43\x21\xfb\x96\xd7\x0e\xe7\xbb\x76\x08\x77\xe3\x71\x89\x9b\x14\xe2\xcc\xf8\x86\x58\x10\x4b\x88\x46\x82\xb5\x7e\xfd\x97\xde\xcb\xb3\x18\xa4\x5c\x05\xa5\x27\xb9\xcc\x5c\x2f\x64\xf7\x35\x29\x35\xa0\x49\xce\xea\x60\x68\x0d\x52\x30\x81\x94\xcc\xef\x2a\x18\xe6\x81\x2b\x45\x2a\x58\x15\xfb\xd7\xf5\xba\xbc\x08\x38\x56\x91\x9a\xaf\x66\x8f\xe7\xe4",
72+
);
73+
74+
// Multiple loop iterations.
75+
mock_unlocked_using_mnemonic(
76+
"correct cherry mammal bubble want mandate polar hazard crater better craft exotic choice fun tourist census gap lottery neglect address glow carry old business",
77+
"",
78+
);
79+
assert_eq!(
80+
get_seed().unwrap().as_slice(),
81+
b"\x58\x7c\x67\x74\x35\x7e\xcb\xf8\x40\xd4\xdb\x64\x04\xff\x7a\xf0\x16\xda\xce\x04\x00\x76\x97\x51\xad\x2a\xbf\xc7\x7b\x9a\x38\x44\xcc\x71\x70\x25\x20\xef\x1a\x4d\x1b\x68\xb9\x11\x87\x78\x7a\x9b\x8f\xaa\xb0\xa9\xbb\x6b\x16\x0d\xe5\x41\xb6\xee\x62\x46\x99\x01\xfc\x0b\xed\xa0\x97\x5f\xe4\x76\x3b\xea\xbd\x83\xb7\x05\x1a\x5f\xd5\xcb\xce\x5b\x88\xe8\x2c\x4b\xba\xca\x26\x50\x14\xe5\x24\xbd",
82+
);
83+
84+
mock_unlocked_using_mnemonic(
85+
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art",
86+
"foo",
87+
);
88+
assert_eq!(
89+
get_seed().unwrap().as_slice(),
90+
b"\xf0\x53\xa1\xe7\x52\xde\x5c\x26\x19\x7b\x60\xf0\x32\xa4\x80\x9f\x08\xbb\x3e\x5d\x90\x48\x4f\xe4\x20\x24\xbe\x31\xef\xcb\xa7\x57\x8d\x91\x4d\x3f\xf9\x92\xe2\x16\x52\xfe\xe6\xa4\xd9\x9f\x60\x91\x00\x69\x38\xfa\xc2\xc0\xc0\xf9\xd2\xde\x0b\xa6\x4b\x75\x4e\x92\xa4\xf3\x72\x3f\x23\x47\x20\x77\xaa\x4c\xd4\xdd\x8a\x8a\x17\x5d\xba\x07\xea\x18\x52\xda\xd1\xcf\x26\x8c\x61\xa2\x67\x9c\x38\x90",
91+
);
92+
}
5293

5394
#[test]
5495
fn test_get_xpub() {
96+
bitbox02::keystore::lock();
5597
assert!(get_xpub(&[]).is_err());
5698

5799
mock_unlocked();

src/rust/bitbox02/src/input.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ impl SafeInputString {
2929
SafeInputString(Box::new([0; INPUT_STRING_MAX_SIZE]))
3030
}
3131

32+
#[cfg(feature = "testing")]
33+
pub fn from_buf(buf: &[u8]) -> SafeInputString {
34+
let mut s = SafeInputString::new();
35+
s.as_mut()[..buf.len()].copy_from_slice(buf);
36+
s
37+
}
38+
3239
/// Copies the string bytes from `source` without additional allocations.
3340
pub fn copy_from(&mut self, source: &Self) {
3441
self.0.copy_from_slice(&source.0[..]);
@@ -80,9 +87,7 @@ mod tests {
8087
use std::prelude::v1::*;
8188

8289
fn from(buf: &[u8]) -> SafeInputString {
83-
let mut pw = SafeInputString::new();
84-
pw.as_mut()[..buf.len()].copy_from_slice(buf);
85-
pw
90+
SafeInputString::from_buf(buf)
8691
}
8792

8893
#[test]

src/rust/bitbox02/src/keystore.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ mod tests {
369369
// 12 words
370370
mock_unlocked_using_mnemonic(
371371
"trust cradle viable innocent stand equal little small junior frost laundry room",
372+
"",
372373
);
373374
assert_eq!(
374375
copy_seed().unwrap().as_slice(),
@@ -378,6 +379,7 @@ mod tests {
378379
// 18 words
379380
mock_unlocked_using_mnemonic(
380381
"pupil parent toe bright slam plastic spy suspect verb battle nominee loan call crystal upset razor luggage join",
382+
"",
381383
);
382384
assert_eq!(
383385
copy_seed().unwrap().as_slice(),
@@ -386,6 +388,7 @@ mod tests {
386388

387389
mock_unlocked_using_mnemonic(
388390
"purity concert above invest pigeon category peace tuition hazard vivid latin since legal speak nation session onion library travel spell region blast estate stay",
391+
"",
389392
);
390393
assert_eq!(
391394
copy_seed().unwrap().as_slice(),

0 commit comments

Comments
 (0)