Skip to content

Commit 30ae684

Browse files
committed
remove remaining libwally code/header uses
The defines (SHA256_LEN for example) are replaced by new definitions or inlined.
1 parent d6d0aa2 commit 30ae684

File tree

13 files changed

+14
-55
lines changed

13 files changed

+14
-55
lines changed

src/common_main.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "screen.h"
2525
#include "securechip/securechip.h"
2626
#include "util.h"
27-
#include <wally_core.h>
2827

2928
extern void __attribute__((noreturn)) __stack_chk_fail(void);
3029
void __attribute__((noreturn)) __stack_chk_fail(void)
@@ -52,22 +51,6 @@ static const securechip_interface_functions_t _securechip_interface_functions =
5251
.random_32_bytes = random_32_bytes,
5352
};
5453

55-
static void _wally_patched_bzero(void* ptr, size_t len)
56-
{
57-
util_zero(ptr, len);
58-
}
59-
60-
static bool _setup_wally(void)
61-
{
62-
static struct wally_operations _ops = {0};
63-
_ops.struct_size = sizeof(struct wally_operations);
64-
if (wally_get_operations(&_ops) != WALLY_OK) {
65-
return false;
66-
}
67-
_ops.bzero_fn = _wally_patched_bzero;
68-
return wally_set_operations(&_ops) == WALLY_OK;
69-
}
70-
7154
void common_main(void)
7255
{
7356
mpu_bitbox02_init();
@@ -76,10 +59,6 @@ void common_main(void)
7659
AbortAutoenter("memory_setup failed");
7760
}
7861

79-
if (!_setup_wally()) {
80-
AbortAutoenter("_setup_wally failed");
81-
}
82-
8362
/* Enable/configure SmartEEPROM. */
8463
smarteeprom_bb02_config();
8564

src/factorysetup.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
#include <secp256k1.h>
3636
#include <ui/oled/oled.h>
3737

38-
#include <wally_crypto.h>
39-
4038
#define BUFFER_SIZE_DOWN 1024
4139
#define BUFFER_SIZE_UP 1024
4240

@@ -387,7 +385,7 @@ static void _api_msg(const uint8_t* input, size_t in_len, uint8_t* output, size_
387385
result = ERR_INVALID_INPUT;
388386
break;
389387
}
390-
uint8_t msg32[SHA256_LEN] = {0};
388+
uint8_t msg32[32] = {0};
391389
_attestation_sighash(attestation_device_pubkey, msg32);
392390
bool matches_a_root_pubkey = false;
393391
for (size_t pubkey_idx = 0; pubkey_idx < sizeof(_root_pubkey_bytes) / ROOT_PUBKEY_SIZE;

src/keystore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ bool keystore_unlock_bip39(const char* mnemonic_passphrase)
464464
return false;
465465
}
466466

467-
uint8_t bip39_seed[BIP39_SEED_LEN_512] = {0};
467+
uint8_t bip39_seed[64] = {0};
468468
UTIL_CLEANUP_64(bip39_seed);
469469
rust_derive_bip39_seed(
470470
rust_util_bytes(seed, seed_length),

src/keystore.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
#include <stdint.h>
2323

2424
#include <secp256k1.h>
25-
#include <wally_bip32.h>
26-
#include <wally_bip39.h> // for BIP39_WORDLIST_LEN
27-
#include <wally_crypto.h> // for EC_PUBLIC_KEY_LEN
2825

2926
#define KEYSTORE_MAX_SEED_LENGTH (32)
3027
#define KEYSTORE_U2F_SEED_LENGTH SHA256_LEN

src/rust/bitbox02-rust/src/workflow/mnemonic.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ use sha2::{Digest, Sha256};
2929

3030
const NUM_RANDOM_WORDS: u8 = 5;
3131

32+
/// Number of words in the BIP-39 wordlist.
33+
const BIP39_WORDLIST_LEN: u16 = 2048;
34+
3235
fn as_str_vec(v: &[zeroize::Zeroizing<String>]) -> Vec<&str> {
3336
v.iter().map(|s| s.as_str()).collect()
3437
}
@@ -56,7 +59,7 @@ fn create_random_unique_words(word: &str, length: u8) -> (u8, Vec<zeroize::Zeroi
5659
// A random word everywhere else.
5760
// Loop until we get a unique word, we don't want repeated words in the list.
5861
loop {
59-
let idx = rand16() % bitbox02::keystore::BIP39_WORDLIST_LEN;
62+
let idx = rand16() % BIP39_WORDLIST_LEN;
6063
if picked_indices.contains(&idx) {
6164
continue;
6265
};
@@ -319,7 +322,7 @@ pub async fn get(
319322
.await;
320323

321324
// Provide all bip39 words to restrict the keyboard entry.
322-
let bip39_wordlist: Vec<u16> = (0..bitbox02::keystore::BIP39_WORDLIST_LEN).collect();
325+
let bip39_wordlist: Vec<u16> = (0..BIP39_WORDLIST_LEN).collect();
323326

324327
let mut word_idx: usize = 0;
325328
let mut entered_words = vec![zeroize::Zeroizing::new(String::new()); num_words];
@@ -430,7 +433,7 @@ mod tests {
430433

431434
fn bruteforce_lastword(mnemonic: &[&str]) -> Vec<zeroize::Zeroizing<String>> {
432435
let mut result = Vec::new();
433-
for i in 0..bitbox02::keystore::BIP39_WORDLIST_LEN {
436+
for i in 0..BIP39_WORDLIST_LEN {
434437
let word = bitbox02::keystore::get_bip39_word(i).unwrap();
435438
let mut m = mnemonic.to_vec();
436439
m.push(&word);

src/rust/bitbox02-sys/build.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ const ALLOWLIST_FNS: &[&str] = &[
157157
"ui_screen_stack_pop_all",
158158
"ui_screen_stack_push",
159159
"util_format_datetime",
160-
"wally_free_string",
161160
"communication_mode_ble_enabled",
162161
];
163162

@@ -213,8 +212,6 @@ pub fn main() -> Result<(), &'static str> {
213212
"../../usb/class/hid",
214213
"../../usb/class/hid/hww",
215214
"../../usb/class/hid/u2f",
216-
// $WALLY_INCLUDES
217-
"../../../external/libwally-core/include",
218215
// $SECP256k1_INCLUDES
219216
"../../../external/libwally-core/src/secp256k1/include",
220217
];

src/rust/bitbox02-sys/wrapper.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@
5050
#include <ui/screen_stack.h>
5151
#include <ui/ugui/ugui.h>
5252
#include <util.h>
53-
#include <wally_bip39.h>
54-
#include <wally_core.h>
55-
#include <wally_crypto.h>
5653

5754
#if defined(TESTING)
5855
#include <fake_memory.h>

src/rust/bitbox02/src/keystore.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use core::convert::TryInto;
2424

2525
use bitbox02_sys::keystore_error_t;
2626

27-
pub const BIP39_WORDLIST_LEN: u16 = bitbox02_sys::BIP39_WORDLIST_LEN as u16;
28-
pub const EC_PUBLIC_KEY_LEN: usize = bitbox02_sys::EC_PUBLIC_KEY_LEN as _;
27+
/// Length of a compressed secp256k1 pubkey.
28+
const EC_PUBLIC_KEY_LEN: usize = 33;
2929
pub const MAX_SEED_LENGTH: usize = bitbox02_sys::KEYSTORE_MAX_SEED_LENGTH as usize;
3030

3131
pub fn is_locked() -> bool {

src/u2f.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <usb/usb_processing.h>
3535
#include <utils_assert.h>
3636
#include <version.h>
37-
#include <wally_crypto.h>
3837

3938
#ifndef TESTING
4039
#include <hal_timer.h>
@@ -49,6 +48,8 @@ typedef struct {
4948

5049
#define APDU_LEN(A) (uint32_t)(((A).lc1 << 16) + ((A).lc2 << 8) + ((A).lc3))
5150
#define U2F_KEYHANDLE_LEN (U2F_NONCE_LENGTH + SHA256_LEN)
51+
#define SHA256_LEN 32
52+
#define HMAC_SHA256_LEN 32
5253

5354
#if (U2F_EC_KEY_SIZE != SHA256_LEN) || (U2F_EC_KEY_SIZE != U2F_NONCE_LENGTH)
5455
#error "Incorrect macro values for u2f"

src/u2f/u2f_app.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <stddef.h>
99
#include <stdio.h>
10-
#include <wally_bip39.h>
1110

1211
#define APPID_BOGUS_CHROMIUM "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
1312
#define APPID_BOGUS_FIREFOX "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"

0 commit comments

Comments
 (0)