Skip to content

Commit d48c9c6

Browse files
committed
Merge branch 'murisi/zip32-support' into murisi/fixes+zip32
2 parents 76b17c0 + 96e7119 commit d48c9c6

38 files changed

+2684
-274
lines changed

app/rust/Cargo.lock

Lines changed: 101 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/rust/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ name = "rslib"
1111
crate-type = ["staticlib"]
1212

1313
[dependencies]
14+
ztruct = { path = "../ztruct", version = "*" }
1415
jubjub = { version = "0.10.0", default-features = false }
1516
aes = { version = "0.7", default-features = false }
1617
binary-ff1 = { version = "0.2", default-features = false }
18+
blake2s_simd = { version = "0.5", default-features = false }
19+
blake2b_simd = { version = "0.5", default-features = false }
20+
byteorder = { version = "1.5", default-features = false }
21+
log = "0.4"
1722

1823
[target.thumbv6m-none-eabi.dev-dependencies]
1924
panic-halt = "0.2.0"

app/rust/include/rslib.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
parser_error_t from_bytes_wide(const uint8_t input[64], uint8_t output[32]);
99
parser_error_t scalar_multiplication(const uint8_t input[32], constant_key_t key, uint8_t output[32]);
1010
parser_error_t get_default_diversifier_list(const uint8_t dk[32], uint8_t start_index[11], uint8_t d_l[44]);
11-
parser_error_t get_default_diversifier(const uint8_t dk[32], uint8_t start_index[11], uint8_t d[11]);
12-
parser_error_t get_pkd(const uint8_t ivk_ptr[32], const uint8_t hash[32], uint8_t pk_d[32]);
13-
parser_error_t get_pkd(const uint8_t ivk_ptr[32], const uint8_t hash[32], uint8_t pk_d[32]);
11+
void get_pkd(uint32_t zip32_account, const uint8_t *diversifier_ptr, uint8_t *pkd);
1412
bool is_valid_diversifier(const uint8_t hash[32]);
1513
parser_error_t randomized_secret_from_seed(const uint8_t ask[32], const uint8_t alpha[32], uint8_t output[32]);
1614
parser_error_t compute_sbar(const uint8_t s[32], uint8_t r[32], uint8_t rsk[32], uint8_t sbar[32]);
1715
parser_error_t add_points(const uint8_t hash[32], const uint8_t value[32], const uint8_t scalar[32], uint8_t cv[32]);
16+
void zip32_ovk(uint32_t zip32_account, uint8_t *ovk);
17+
void zip32_child_ask_nsk(uint32_t account, uint8_t *ask, uint8_t *nsk);
18+
void diversifier_find_valid(uint32_t zip32_account, uint8_t *default_diversifier);
19+
void zip32_dk(uint32_t zip32_account, uint8_t *dk);
20+
void zip32_chain_code(uint32_t zip32_account, uint8_t *chain_code);
21+
void zip32_parent_fvk_tag(uint32_t zip32_account, uint8_t *fvk_tag);
22+
void zip32_xfvk(uint32_t zip32_account, uint8_t *fvk_tag, uint8_t *chain_code, uint8_t *fvk, uint8_t *dk);

app/rust/src/bolos/aes.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use aes::cipher::generic_array::typenum::{U16, U32, U8};
2+
use aes::cipher::generic_array::GenericArray;
3+
use aes::cipher::BlockEncrypt;
4+
use aes::cipher::NewBlockCipher;
5+
use aes::cipher::{BlockCipher, BlockCipherKey};
6+
use aes::Aes256;
7+
8+
/// Encrypts a block using AES-256.
9+
/// This function uses the Rust `aes` crate for encryption in test environments.
10+
pub fn aes256_encrypt_block(k: &[u8], a: &[u8]) -> [u8; 16] {
11+
let cipher: Aes256 = Aes256::new(GenericArray::from_slice(k));
12+
13+
let mut b = GenericArray::clone_from_slice(a);
14+
cipher.encrypt_block(&mut b);
15+
16+
let out: [u8; 16] = b.as_slice().try_into().expect("err");
17+
out
18+
}
19+
20+
pub struct AesBOLOS {
21+
key: [u8; 32],
22+
}
23+
24+
impl AesBOLOS {
25+
pub fn new(k: &[u8; 32]) -> AesBOLOS {
26+
AesBOLOS { key: *k }
27+
}
28+
}
29+
30+
impl BlockCipher for AesBOLOS {
31+
type BlockSize = U16;
32+
type ParBlocks = U8;
33+
}
34+
35+
impl NewBlockCipher for AesBOLOS {
36+
type KeySize = U32;
37+
38+
#[inline(never)]
39+
fn new(key: &BlockCipherKey<Self>) -> Self {
40+
let v: [u8; 32] = key.as_slice().try_into().expect("Wrong length");
41+
AesBOLOS { key: v }
42+
}
43+
}
44+
impl BlockEncrypt for AesBOLOS {
45+
#[inline(never)]
46+
fn encrypt_block(&self, block: &mut GenericArray<u8, Self::BlockSize>) {
47+
let x: [u8; 16] = block.as_slice().try_into().expect("err");
48+
let y = aes256_encrypt_block(&self.key, &x);
49+
50+
block.copy_from_slice(&y);
51+
}
52+
}

0 commit comments

Comments
 (0)