Merge pull request #105 from daira/add-registered-test-vectors

Add test vectors for ZIP 32 registered key derivation
This commit is contained in:
Jack Grigg 2025-02-20 10:21:19 +00:00 committed by GitHub
commit ba707b10f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
37 changed files with 283 additions and 127 deletions

View File

@ -4,8 +4,8 @@ version = "0.1.0"
description = "Zcash test vectors"
authors = [
"Jack Grigg <jack@z.cash>",
"Daira Hopwood <daira@jacaranda.org>",
"ying tong <yingtong@z.cash>",
"Daira-Emma Hopwood <daira@jacaranda.org>",
"Ying Tong Lai <yingtong@ethereum.org>",
"Taylor Hornby <taylor@defuse.ca>",
"Kris Nuttycombe <kris@electriccoin.co>",
"Simon <simon@bitcartel.com>",
@ -41,6 +41,7 @@ f4jumble_long = "zcash_test_vectors.f4jumble:long_test_vectors"
unified_address = "zcash_test_vectors.unified_address:main"
unified_full_viewing_keys = "zcash_test_vectors.unified_full_viewing_keys:main"
unified_incoming_viewing_keys = "zcash_test_vectors.unified_incoming_viewing_keys:main"
zip_0032_registered = "zcash_test_vectors.zip_0032:registered_key_derivation_tvs"
zip_0032_arbitrary = "zcash_test_vectors.zip_0032:arbitrary_key_derivation_tvs"
zip_0143 = "zcash_test_vectors.zip_0143:main"
zip_0243 = "zcash_test_vectors.zip_0243:main"

View File

@ -45,6 +45,7 @@ case "$2" in
unified_address
unified_full_viewing_keys
unified_incoming_viewing_keys
zip_0032_registered
zip_0032_arbitrary
zip_0143
zip_0243

View File

@ -0,0 +1,7 @@
[
["From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0032_registered.py"],
["context_string, seed, zip_number, subpath, sk, c, full_width"],
["5a63617368207465737420766563746f7273", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 1, [], "53a71507e6dfda588bc1e138c2657c9269e55f5d9b99e3887c134008193a2f47", "08bb26aae21d4efdc3249b9557fcd9131e8b9827241d9f61d0d774bb4fed3de6", null],
["5a63617368207465737420766563746f7273", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 1, [[2147483650, "7472616e7320726967687473206172652068756d616e20726967687473"]], "02dc25cc40310eed08b028e07fae9adbee2fbe56a4694def0401e656dfae0211", "d8f9d8a1f81d1b5d5506b5ff942d2ff3dae7a63f57d6b8c7fbe58149823cc6ec", "255d75b5f97dd880a14460ab0a28938e7ba497ceb1457fff2992e9015a8403f8c08112b7a94cf539c21c9da7ee99897be9476b6813532ee22c8947d753b72bdf"],
["5a63617368207465737420766563746f7273", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 1, [[2147483650, "7472616e7320726967687473206172652068756d616e20726967687473"], [2147483651, ""]], "a127db66628b256e5b664d54050c1e6b028963aea22b04d1bc6f48123674ed82", "340084033605edca11463ffec56bf0cac425c410e953628671cec6a6514c32a8", "7f853eef001b1bc5a1a5e67f5dfd0e90427596d4842f5b10a111e97c4073203cedf6b80a85145e5061acd29bc5a4e349b14f8557a7033e23b066b7ce2409d973"]
]

View File

@ -5,10 +5,10 @@
external_ovk: [u8; 32],
internal_ovk: [u8; 32],
account: u32,
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/bip_0032.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
c: [
0x9b, 0xa0, 0x43, 0x9c, 0x6a, 0x2d, 0x3d, 0x90, 0x38, 0x83, 0xd4, 0x53, 0x7c, 0x36, 0x22, 0x88, 0x62, 0x6d, 0xa6, 0x2c, 0x62, 0x99, 0x01, 0x2e, 0x36, 0x2d, 0x8f, 0xb6, 0xef, 0xeb, 0xab, 0x47

View File

@ -1,10 +1,10 @@
struct TestVector {
normal: Vec<u8>,
jumbled: Vec<u8>,
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/f4jumble.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
normal: vec![
0x5d, 0x7a, 0x8f, 0x73, 0x9a, 0x2d, 0x9e, 0x94, 0x5b, 0x0c, 0xe1, 0x52, 0xa8, 0x04, 0x9e, 0x29, 0x4c, 0x4d, 0x6e, 0x66, 0xb1, 0x64, 0x93, 0x9d, 0xaf, 0xfa, 0x2e, 0xf6, 0xee, 0x69, 0x21, 0x48, 0x1c, 0xdd, 0x86, 0xb3, 0xcc, 0x43, 0x18, 0xd9, 0x61, 0x4f, 0xc8, 0x20, 0x90, 0x5d, 0x04, 0x2b

View File

@ -1,10 +1,10 @@
struct TestVector {
length: usize,
jumbled_hash: [u8; 64],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/f4jumble_long.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
length: 3246395,
jumbled_hash: [

View File

@ -1,9 +1,9 @@
struct TestVector {
empty_roots: [[u8; 32]; 33],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/orchard_empty_roots.py
let test_vector = TestVector {
const TEST_VECTOR: TestVector = TestVector {
empty_roots: [
[0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
[0xd1, 0xab, 0x25, 0x07, 0xc8, 0x09, 0xc2, 0x71, 0x3c, 0x00, 0x0f, 0x52, 0x5e, 0x9f, 0xbd, 0xcb, 0x06, 0xc9, 0x58, 0x38, 0x4e, 0x51, 0xb9, 0xcc, 0x7f, 0x79, 0x2d, 0xde, 0x6c, 0x97, 0xf4, 0x11],

View File

@ -8,10 +8,10 @@
ivkb: [u8; 32],
ivkq: [u8; 32],
mcq: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/orchard_generators.py
let test_vector = TestVector {
const TEST_VECTOR: TestVector = TestVector {
skb: [
0x63, 0xc9, 0x75, 0xb8, 0x84, 0x72, 0x1a, 0x8d, 0x0c, 0xa1, 0x70, 0x7b, 0xe3, 0x0c, 0x7f, 0x0c, 0x5f, 0x44, 0x5f, 0x3e, 0x7c, 0x18, 0x8d, 0x3b, 0x06, 0xd6, 0xf1, 0x28, 0xb3, 0x23, 0x55, 0xb7
],

View File

@ -2,10 +2,10 @@
domain: Vec<u8>,
msg: Vec<u8>,
point: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/orchard_group_hash.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
domain: vec![
0x7a, 0x2e, 0x63, 0x61, 0x73, 0x68, 0x3a, 0x74, 0x65, 0x73, 0x74

View File

@ -18,10 +18,10 @@
note_rseed: [u8; 32],
note_cmx: [u8; 32],
note_nf: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/orchard_key_components.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
sk: [
0x5d, 0x7a, 0x8f, 0x73, 0x9a, 0x2d, 0x9e, 0x94, 0x5b, 0x0c, 0xe1, 0x52, 0xa8, 0x04, 0x9e, 0x29, 0x4c, 0x4d, 0x6e, 0x66, 0xb1, 0x64, 0x93, 0x9d, 0xaf, 0xfa, 0x2e, 0xf6, 0xee, 0x69, 0x21, 0x48

View File

@ -1,10 +1,10 @@
struct TestVector {
u: [u8; 32],
point: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/orchard_map_to_curve.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
u: [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

View File

@ -2,10 +2,10 @@
leaves: [[u8; 32]; 16],
paths: [[[u8; 32]; 4]; 16],
root: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/orchard_merkle_tree.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
leaves: [
[0x3d, 0xc1, 0x66, 0xd5, 0x6a, 0x1d, 0x62, 0xf5, 0xa8, 0xd7, 0x55, 0x1d, 0xb5, 0xfd, 0x93, 0x13, 0xe8, 0xc7, 0x20, 0x3d, 0x99, 0x6a, 0xf7, 0xd4, 0x77, 0x08, 0x37, 0x56, 0xd5, 0x9a, 0xf8, 0x0d],

View File

@ -18,10 +18,10 @@
ock: [u8; 32],
op: [u8; 64],
c_out: [u8; 80],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/orchard_note_encryption.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
incoming_viewing_key: [
0x10, 0x39, 0xd8, 0xe6, 0x4a, 0x80, 0x90, 0x2e, 0x10, 0x59, 0x47, 0x81, 0x7d, 0xf3, 0xbd, 0xfb, 0x7d, 0xf7, 0x03, 0x0e, 0x68, 0x73, 0x9f, 0x9c, 0x53, 0x3a, 0x36, 0xbf, 0x5a, 0x6a, 0x80, 0x72, 0x43, 0x10, 0x6d, 0xe9, 0xa7, 0xec, 0x54, 0xdd, 0x36, 0xdf, 0xa7, 0x0b, 0xdb, 0xd9, 0x07, 0x2d, 0xbd, 0xda, 0xb5, 0xe0, 0x66, 0xaa, 0xef, 0xfc, 0xf9, 0xbb, 0xa3, 0x20, 0xd4, 0xff, 0xf7, 0x12

View File

@ -1,10 +1,10 @@
struct TestVector {
initial_state: [[u8; 32]; 3],
final_state: [[u8; 32]; 3],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/orchard_poseidon.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
initial_state: [
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],

View File

@ -1,10 +1,10 @@
struct TestVector {
input: [[u8; 32]; 2],
output: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/orchard_poseidon_hash.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
input: [
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],

View File

@ -3,10 +3,10 @@
msg: Vec<bool>,
point: [u8; 32],
hash: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/orchard_sinsemilla.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
domain: vec![
0x7a, 0x2e, 0x63, 0x61, 0x73, 0x68, 0x3a, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x53, 0x69, 0x6e, 0x73, 0x65, 0x6d, 0x69, 0x6c, 0x6c, 0x61

View File

@ -3,10 +3,10 @@
c: [u8; 32],
xsk: [u8; 73],
fp: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/orchard_zip32.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
sk: [
0x7e, 0xee, 0x3c, 0x10, 0x17, 0x87, 0x09, 0x90, 0xa3, 0xdd, 0x68, 0x91, 0xb8, 0x2f, 0x80, 0xbe, 0x89, 0x76, 0xc1, 0xe7, 0xdc, 0x20, 0xd6, 0x08, 0x17, 0xa5, 0xe8, 0x8e, 0x8b, 0x2c, 0xd4, 0xb8

View File

@ -9,10 +9,10 @@
pb1: [u8; 32],
pb2: [u8; 32],
pb3: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/sapling_generators.py
let test_vector = TestVector {
const TEST_VECTOR: TestVector = TestVector {
skb: [
0x30, 0xb5, 0xf2, 0xaa, 0xad, 0x32, 0x56, 0x30, 0xbc, 0xdd, 0xdb, 0xce, 0x4d, 0x67, 0x65, 0x6d, 0x05, 0xfd, 0x1c, 0xc2, 0xd0, 0x37, 0xbb, 0x53, 0x75, 0xb6, 0xe9, 0x6d, 0x9e, 0x01, 0xa1, 0xd7
],

View File

@ -13,10 +13,10 @@
note_cmu: [u8; 32],
note_pos: u64,
note_nf: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/sapling_key_components.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
sk: [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

View File

@ -17,10 +17,10 @@
ock: [u8; 32],
op: [u8; 64],
c_out: [u8; 80],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/sapling_note_encryption.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
ovk: [
0x98, 0xd1, 0x69, 0x13, 0xd9, 0x9b, 0x04, 0x17, 0x7c, 0xab, 0xa4, 0x4f, 0x6e, 0x4d, 0x22, 0x4e, 0x03, 0xb5, 0xac, 0x03, 0x1d, 0x7c, 0xe4, 0x5e, 0x86, 0x51, 0x38, 0xe1, 0xb9, 0x96, 0xd6, 0x3b

View File

@ -7,10 +7,10 @@
m: [u8; 32],
sig: [u8; 64],
rsig: [u8; 64],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/sapling_signatures.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
sk: [
0x18, 0xe2, 0x8d, 0xea, 0x5c, 0x11, 0x81, 0x7a, 0xee, 0xb2, 0x1a, 0x19, 0x98, 0x1d, 0x28, 0x36, 0x8e, 0xc4, 0x38, 0xaf, 0xc2, 0x5a, 0x8d, 0xb9, 0x4e, 0xbe, 0x08, 0xd7, 0xa0, 0x28, 0x8e, 0x09

View File

@ -22,10 +22,10 @@
internal_xsk: Option<[u8; 169]>,
internal_xfvk: [u8; 169],
internal_fp: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/sapling_zip32.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
ask: Some([
0xb6, 0xc0, 0x0c, 0x93, 0xd3, 0x60, 0x32, 0xb9, 0xa2, 0x68, 0xe9, 0x9e, 0x86, 0xa8, 0x60, 0x77, 0x65, 0x60, 0xbf, 0x0e, 0x83, 0xc1, 0xa1, 0x0b, 0x51, 0xf6, 0x07, 0xc9, 0x54, 0x74, 0x25, 0x06

View File

@ -22,10 +22,10 @@
internal_xsk: Option<[u8; 169]>,
internal_xfvk: [u8; 169],
internal_fp: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/sapling_zip32.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
ask: Some([
0xb6, 0xc0, 0x0c, 0x93, 0xd3, 0x60, 0x32, 0xb9, 0xa2, 0x68, 0xe9, 0x9e, 0x86, 0xa8, 0x60, 0x77, 0x65, 0x60, 0xbf, 0x0e, 0x83, 0xc1, 0xa1, 0x0b, 0x51, 0xf6, 0x07, 0xc9, 0x54, 0x74, 0x25, 0x06

View File

@ -9,10 +9,10 @@
root_seed: Vec<u8>,
account: u32,
diversifier_index: u32,
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/unified_address.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
p2pkh_bytes: Some([
0x7b, 0xb8, 0x35, 0x70, 0xb8, 0xfa, 0xe1, 0x46, 0xe0, 0x3c, 0x53, 0x31, 0xa0, 0x20, 0xb1, 0xe0, 0x89, 0x2f, 0x63, 0x1d

View File

@ -7,10 +7,10 @@
unified_fvk: Vec<u8>,
root_seed: Vec<u8>,
account: u32,
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/unified_full_viewing_keys.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
t_key_bytes: Some([
0x9b, 0xa0, 0x43, 0x9c, 0x6a, 0x2d, 0x3d, 0x90, 0x38, 0x83, 0xd4, 0x53, 0x7c, 0x36, 0x22, 0x88, 0x62, 0x6d, 0xa6, 0x2c, 0x62, 0x99, 0x01, 0x2e, 0x36, 0x2d, 0x8f, 0xb6, 0xef, 0xeb, 0xab, 0x47, 0x02, 0xed, 0x63, 0x85, 0x32, 0xc4, 0x75, 0xf6, 0x74, 0x00, 0x35, 0x0f, 0xb1, 0xd6, 0xed, 0xa5, 0x59, 0xcd, 0xc2, 0x89, 0xa1, 0x9b, 0x43, 0x19, 0xeb, 0x17, 0x51, 0x40, 0xaa, 0x86, 0x89, 0x38, 0x36

View File

@ -7,10 +7,10 @@
unified_ivk: Vec<u8>,
root_seed: Vec<u8>,
account: u32,
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/unified_incoming_viewing_keys.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
t_key_bytes: Some([
0x42, 0xd6, 0x7b, 0x57, 0x0a, 0x66, 0x4b, 0x8d, 0xc3, 0xce, 0xbb, 0x8f, 0x0a, 0xf4, 0x24, 0x3f, 0xf9, 0xe7, 0xe6, 0xe8, 0xd0, 0x86, 0x08, 0x4e, 0x23, 0x25, 0x67, 0x88, 0x03, 0xb1, 0x42, 0xd1, 0x03, 0x87, 0xeb, 0xa0, 0x4d, 0xbf, 0xb4, 0x06, 0xb2, 0xb2, 0xf0, 0x46, 0xe6, 0x61, 0x40, 0x84, 0x59, 0xbc, 0x3d, 0x1e, 0x0e, 0x7a, 0xa0, 0xf1, 0x47, 0x04, 0x3b, 0x07, 0x6d, 0x00, 0xd5, 0xe1, 0x11

View File

@ -1,25 +1,25 @@
struct TestVector {
context_string: Vec<u8>,
context_string: &'static [u8],
seed: [u8; 32],
ikm: Option<Vec<u8>>,
path: Vec<u32>,
ikm: Option<&'static [u8]>,
path: &'static [u32],
sk: [u8; 32],
c: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0032_arbitrary.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
context_string: vec![
context_string: &[
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
],
seed: [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
],
ikm: Some(vec![
ikm: Some(&[
0x12, 0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73, 0x20, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
]),
path: vec![
path: &[
],
sk: [
0xe9, 0xda, 0x88, 0x06, 0x40, 0x9d, 0xc3, 0xc3, 0xeb, 0xd1, 0xfc, 0x2a, 0x71, 0xc8, 0x79, 0xc1, 0x3d, 0xd7, 0xaa, 0x93, 0xed, 0xe8, 0x03, 0xbf, 0x1a, 0x83, 0x41, 0x4b, 0x9d, 0x3b, 0x15, 0x8a
@ -29,14 +29,14 @@
],
},
TestVector {
context_string: vec![
context_string: &[
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
],
seed: [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
],
ikm: None,
path: vec![
path: &[
2147483649,
],
sk: [
@ -47,14 +47,14 @@
],
},
TestVector {
context_string: vec![
context_string: &[
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
],
seed: [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
],
ikm: None,
path: vec![
path: &[
2147483649,
2147483650,
],
@ -66,14 +66,14 @@
],
},
TestVector {
context_string: vec![
context_string: &[
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
],
seed: [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
],
ikm: None,
path: vec![
path: &[
2147483649,
2147483650,
2147483651,
@ -86,14 +86,14 @@
],
},
TestVector {
context_string: vec![
context_string: &[
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
],
seed: [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
],
ikm: None,
path: vec![
path: &[
2147483680,
],
sk: [
@ -104,14 +104,14 @@
],
},
TestVector {
context_string: vec![
context_string: &[
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
],
seed: [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
],
ikm: None,
path: vec![
path: &[
2147483680,
2147483781,
],
@ -123,14 +123,14 @@
],
},
TestVector {
context_string: vec![
context_string: &[
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
],
seed: [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
],
ikm: None,
path: vec![
path: &[
2147483680,
2147483781,
2147483648,

View File

@ -0,0 +1,74 @@
struct TestVector {
context_string: &'static [u8],
seed: [u8; 32],
zip_number: u16,
subpath: &'static [(u32, &'static [u8])],
sk: [u8; 32],
c: [u8; 32],
full_width: Option<[u8; 64]>,
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0032_registered.py
const TEST_VECTORS: &[TestVector] = &[
TestVector {
context_string: &[
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
],
seed: [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
],
zip_number: 1,
subpath: &[
],
sk: [
0x53, 0xa7, 0x15, 0x07, 0xe6, 0xdf, 0xda, 0x58, 0x8b, 0xc1, 0xe1, 0x38, 0xc2, 0x65, 0x7c, 0x92, 0x69, 0xe5, 0x5f, 0x5d, 0x9b, 0x99, 0xe3, 0x88, 0x7c, 0x13, 0x40, 0x08, 0x19, 0x3a, 0x2f, 0x47
],
c: [
0x08, 0xbb, 0x26, 0xaa, 0xe2, 0x1d, 0x4e, 0xfd, 0xc3, 0x24, 0x9b, 0x95, 0x57, 0xfc, 0xd9, 0x13, 0x1e, 0x8b, 0x98, 0x27, 0x24, 0x1d, 0x9f, 0x61, 0xd0, 0xd7, 0x74, 0xbb, 0x4f, 0xed, 0x3d, 0xe6
],
full_width: None,
},
TestVector {
context_string: &[
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
],
seed: [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
],
zip_number: 1,
subpath: &[
(2147483650, &[0x74, 0x72, 0x61, 0x6e, 0x73, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73]),
],
sk: [
0x02, 0xdc, 0x25, 0xcc, 0x40, 0x31, 0x0e, 0xed, 0x08, 0xb0, 0x28, 0xe0, 0x7f, 0xae, 0x9a, 0xdb, 0xee, 0x2f, 0xbe, 0x56, 0xa4, 0x69, 0x4d, 0xef, 0x04, 0x01, 0xe6, 0x56, 0xdf, 0xae, 0x02, 0x11
],
c: [
0xd8, 0xf9, 0xd8, 0xa1, 0xf8, 0x1d, 0x1b, 0x5d, 0x55, 0x06, 0xb5, 0xff, 0x94, 0x2d, 0x2f, 0xf3, 0xda, 0xe7, 0xa6, 0x3f, 0x57, 0xd6, 0xb8, 0xc7, 0xfb, 0xe5, 0x81, 0x49, 0x82, 0x3c, 0xc6, 0xec
],
full_width: Some([
0x25, 0x5d, 0x75, 0xb5, 0xf9, 0x7d, 0xd8, 0x80, 0xa1, 0x44, 0x60, 0xab, 0x0a, 0x28, 0x93, 0x8e, 0x7b, 0xa4, 0x97, 0xce, 0xb1, 0x45, 0x7f, 0xff, 0x29, 0x92, 0xe9, 0x01, 0x5a, 0x84, 0x03, 0xf8, 0xc0, 0x81, 0x12, 0xb7, 0xa9, 0x4c, 0xf5, 0x39, 0xc2, 0x1c, 0x9d, 0xa7, 0xee, 0x99, 0x89, 0x7b, 0xe9, 0x47, 0x6b, 0x68, 0x13, 0x53, 0x2e, 0xe2, 0x2c, 0x89, 0x47, 0xd7, 0x53, 0xb7, 0x2b, 0xdf
]),
},
TestVector {
context_string: &[
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
],
seed: [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
],
zip_number: 1,
subpath: &[
(2147483650, &[0x74, 0x72, 0x61, 0x6e, 0x73, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73]),
(2147483651, &[]),
],
sk: [
0xa1, 0x27, 0xdb, 0x66, 0x62, 0x8b, 0x25, 0x6e, 0x5b, 0x66, 0x4d, 0x54, 0x05, 0x0c, 0x1e, 0x6b, 0x02, 0x89, 0x63, 0xae, 0xa2, 0x2b, 0x04, 0xd1, 0xbc, 0x6f, 0x48, 0x12, 0x36, 0x74, 0xed, 0x82
],
c: [
0x34, 0x00, 0x84, 0x03, 0x36, 0x05, 0xed, 0xca, 0x11, 0x46, 0x3f, 0xfe, 0xc5, 0x6b, 0xf0, 0xca, 0xc4, 0x25, 0xc4, 0x10, 0xe9, 0x53, 0x62, 0x86, 0x71, 0xce, 0xc6, 0xa6, 0x51, 0x4c, 0x32, 0xa8
],
full_width: Some([
0x7f, 0x85, 0x3e, 0xef, 0x00, 0x1b, 0x1b, 0xc5, 0xa1, 0xa5, 0xe6, 0x7f, 0x5d, 0xfd, 0x0e, 0x90, 0x42, 0x75, 0x96, 0xd4, 0x84, 0x2f, 0x5b, 0x10, 0xa1, 0x11, 0xe9, 0x7c, 0x40, 0x73, 0x20, 0x3c, 0xed, 0xf6, 0xb8, 0x0a, 0x85, 0x14, 0x5e, 0x50, 0x61, 0xac, 0xd2, 0x9b, 0xc5, 0xa4, 0xe3, 0x49, 0xb1, 0x4f, 0x85, 0x57, 0xa7, 0x03, 0x3e, 0x23, 0xb0, 0x66, 0xb7, 0xce, 0x24, 0x09, 0xd9, 0x73
]),
},
];

View File

@ -6,10 +6,10 @@
amount: i64,
consensus_branch_id: u32,
sighash: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0143.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
tx: vec![
0x03, 0x00, 0x00, 0x80, 0x70, 0x82, 0xc4, 0x03, 0x00, 0x02, 0xe7, 0x71, 0x98, 0x11, 0x89, 0x3e, 0x00, 0x00, 0x09, 0x52, 0x00, 0xac, 0x65, 0x51, 0xac, 0x63, 0x65, 0x65, 0xb2, 0x83, 0x5a, 0x08, 0x05, 0x75, 0x02, 0x00, 0x02, 0x51, 0x51, 0x48, 0x1c, 0xdd, 0x86, 0xb3, 0xcc, 0x43, 0x18, 0x00

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -3,10 +3,10 @@
pk: [u8; 33],
external_ovk: [u8; 32],
internal_ovk: [u8; 32],
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0316.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
c: [
0x5d, 0x7a, 0x8f, 0x73, 0x9a, 0x2d, 0x9e, 0x94, 0x5b, 0x0c, 0xe1, 0x52, 0xa8, 0x04, 0x9e, 0x29, 0x4c, 0x4d, 0x6e, 0x66, 0xb1, 0x64, 0x93, 0x9d, 0xaf, 0xfa, 0x2e, 0xf6, 0xee, 0x69, 0x21, 0x48

View File

@ -4,10 +4,10 @@
tex_addr: &'static str,
account: u32,
child_index: u32,
};
}
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zcash_test_vectors/transparent/zip_0320.py
let test_vectors = vec![
const TEST_VECTORS: &[TestVector] = &[
TestVector {
t_addr: "t1V9mnyk5Z5cTNMCkLbaDwSskgJZucTLdgW",
p2pkh_bytes: [

View File

@ -0,0 +1,7 @@
[
["From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0032_registered.py"],
["context_string, seed, zip_number, subpath, sk, c, full_width"],
["5a63617368207465737420766563746f7273", "1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100", 1, [], "472f3a190840137c88e3999b5d5fe569927c65c238e1c18b58dadfe60715a753", "e63ded4fbb74d7d0619f1d2427988b1e13d9fc57959b24c3fd4e1de2aa26bb08", null],
["5a63617368207465737420766563746f7273", "1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100", 1, [[2147483650, "7472616e7320726967687473206172652068756d616e20726967687473"]], "1102aedf56e60104ef4d69a456be2feedb9aae7fe028b008ed0e3140cc25dc02", "ecc63c824981e5fbc7b8d6573fa6e7daf32f2d94ffb506555d1b1df8a1d8f9d8", "255d75b5f97dd880a14460ab0a28938e7ba497ceb1457fff2992e9015a8403f8c08112b7a94cf539c21c9da7ee99897be9476b6813532ee22c8947d753b72bdf"],
["5a63617368207465737420766563746f7273", "1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100", 1, [[2147483650, "7472616e7320726967687473206172652068756d616e20726967687473"], [2147483651, ""]], "82ed743612486fbcd1042ba2ae6389026b1e0c05544d665b6e258b6266db27a1", "a8324c51a6c6ce71866253e910c425c4caf06bc5fe3f4611caed053603840034", "7f853eef001b1bc5a1a5e67f5dfd0e90427596d4842f5b10a111e97c4073203cedf6b80a85145e5061acd29bc5a4e349b14f8557a7033e23b066b7ce2409d973"]
]

View File

@ -66,7 +66,7 @@ class ExtendedSpendingKey(SpendingKey):
return cls(chaincode, sk)
def child(self, i):
(sk_i, c_i) = CKDh(self.Orchard, self.data, self.chaincode, i)
(sk_i, c_i) = CKDh(self.Orchard, self.data, self.chaincode, i, 0, b"")
return self.__class__(c_i, sk_i)

View File

@ -28,6 +28,9 @@ def tv_value_json(value, bitcoin_flavoured):
value = value.thing
def bitcoinify(value):
if type(value) == tuple:
return tuple((bitcoinify(v) for v in value))
if type(value) == list:
return [bitcoinify(v) for v in value]
@ -62,23 +65,13 @@ def tv_json(filename, parts, vectors, bitcoin_flavoured):
# Rust
#
def tv_bytes_rust(name, value, pad):
print('''%s%s: [
%s%s
%s],''' % (
pad,
name,
pad,
chunk(hexlify(value)),
pad,
))
def tv_vec_bytes_rust(name, value, pad):
print('''%s%s: vec![
def tv_bytes_rust(name, value, pad, kind=""):
print('''%s%s: %s[
%s%s
%s],''' % (
pad,
name,
kind,
pad,
chunk(hexlify(value)),
pad,
@ -95,6 +88,13 @@ def tv_vec_bool_rust(name, value, pad):
pad,
))
def tv_tuple_int_bytes_rust(name, value, pad):
print("%s%s: &[" % (pad, name))
for (i, t) in value:
print("%s (%d, &[%s])," % (pad, i, chunk(hexlify(t))))
print("%s]," % (pad,))
def tv_str_rust(name, value, pad):
print('''%s%s: "%s",''' % (
pad,
@ -102,27 +102,14 @@ def tv_str_rust(name, value, pad):
value,
))
def tv_option_bytes_rust(name, value, pad):
def tv_option_bytes_rust(name, value, pad, kind=""):
if value:
print('''%s%s: Some([
%s%s
%s]),''' % (
pad,
name,
pad,
chunk(hexlify(value.thing)),
pad,
))
else:
print('%s%s: None,' % (pad, name))
def tv_option_vec_bytes_rust(name, value, pad):
if value:
print('''%s%s: Some(vec![
print('''%s%s: Some(%s[
%s%s
%s]),''' % (
pad,
name,
kind,
pad,
chunk(hexlify(value.thing)),
pad,
@ -147,14 +134,20 @@ def tv_part_rust(name, value, config, indent=3):
pad = ' ' * indent
if config['rust_type'] == 'Option<Vec<u8>>':
tv_option_vec_bytes_rust(name, value, pad)
tv_option_bytes_rust(name, value, pad, kind="vec!")
elif config['rust_type'] == 'Option<&\'static [u8]>':
tv_option_bytes_rust(name, value, pad, kind="&")
elif config['rust_type'] == 'Vec<u8>':
tv_vec_bytes_rust(name, value, pad)
tv_bytes_rust(name, value, pad, kind="vec!")
elif config['rust_type'] == '&\'static [u8]':
tv_bytes_rust(name, value, pad, kind="&")
elif config['rust_type'] == 'Vec<bool>':
tv_vec_bool_rust(name, value, pad)
elif config['rust_type'] == '&\'static [(u32, &\'static [u8])]':
tv_tuple_int_bytes_rust(name, value, pad)
elif config['rust_type'] == '&\'static str':
tv_str_rust(name, value, pad)
elif config['rust_type'].startswith('Option<['):
elif config['rust_type'].startswith('Option<[u8'):
tv_option_bytes_rust(name, value, pad)
elif type(value) == bytes:
tv_bytes_rust(name, value, pad)
@ -166,7 +159,7 @@ def tv_part_rust(name, value, config, indent=3):
print('''%s%s: %s[''' % (
pad,
name,
'vec!' if config['rust_type'].startswith('Vec<') else '',
'vec!' if config['rust_type'].startswith('Vec<') else "&" if config['rust_type'].startswith('&') else '',
))
for item in value:
if 'Vec<u8>' in config['rust_type']:
@ -211,17 +204,17 @@ def tv_part_rust(name, value, config, indent=3):
def tv_rust(filename, parts, vectors):
print(' struct TestVector {')
for p in parts: print(' %s: %s,' % (p[0], p[1]['rust_type']))
print(''' };
print(''' }
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/%s.py''' % (
filename,
))
if type(vectors) == type({}):
print(' let test_vector = TestVector {')
print(' const TEST_VECTOR: TestVector = TestVector {')
for p in parts: tv_part_rust(p[0], vectors[p[0]], p[1])
print(' };')
elif type(vectors) == type([]):
print(' let test_vectors = vec![')
print(' const TEST_VECTORS: &[TestVector] = &[')
for vector in vectors:
print(' TestVector {')
for p in parts: tv_part_rust(p[0], vector[p[0]], p[1], 4)

View File

@ -26,17 +26,90 @@ def MKGh(Context, IKM):
I_R = I[32:]
return (I_L, I_R)
def CKDh(Context, sk_par, c_par, i):
def CKDh(Context, sk_par, c_par, i, lead, tag):
assert type(Context) == HardenedOnlyContext
assert 0x80000000 <= i and i <= 0xFFFFFFFF
assert 0x00 <= lead and lead <= 0xFF
assert type(tag) == bytes
I = prf_expand(c_par, Context.CKDDomain + sk_par + i2leosp(32, i))
lead_enc = bytes([] if lead == 0 and tag == b"" else [lead])
I = prf_expand(c_par, Context.CKDDomain + sk_par + i2leosp(32, i) + lead_enc + tag)
I_L = I[:32]
I_R = I[32:]
return (I_L, I_R)
class RegisteredKey(object):
Registered = HardenedOnlyContext(b'ZIPRegistered_KD', b'\xAC')
def __init__(self, IKM, subpath, sk, chaincode, full_width=None):
self.IKM = IKM
self.subpath = subpath
self.sk = sk
self.chaincode = chaincode
self.full_width = full_width # the full-width cryptovalue at this path
@classmethod
def subtree_root(cls, ContextString, S, ZipNumber):
length_ContextString = len(ContextString)
length_S = len(S)
assert length_ContextString <= 252
assert 32 <= length_S <= 252
IKM = bytes([length_ContextString]) + ContextString + bytes([length_S]) + S
(sk_m, c_m) = MKGh(cls.Registered, IKM)
(sk, chaincode) = CKDh(cls.Registered, sk_m, c_m, hardened(ZipNumber), 0, b"")
return cls(IKM, [], sk, chaincode)
def child(self, i, tag):
(sk_child, c_child) = CKDh(self.Registered, self.sk, self.chaincode, i, 0, tag)
(I_L, I_R) = CKDh(self.Registered, self.sk, self.chaincode, i, 1, tag)
return self.__class__(None, self.subpath + [(i, tag)], sk_child, c_child, I_L + I_R)
def registered_key_derivation_tvs():
args = render_args()
context_string = b'Zcash test vectors'
seed = bytes(range(32))
m_1h = RegisteredKey.subtree_root(context_string, seed, 1)
m_1h_2h = m_1h.child(hardened(2), b"trans rights are human rights")
m_1h_2h_3h = m_1h_2h.child(hardened(3), b"")
keys = [m_1h, m_1h_2h, m_1h_2h_3h]
test_vectors = [
{
'context_string': context_string,
'seed': seed,
'zip_number': 1,
'subpath': k.subpath,
'sk': k.sk,
'c': k.chaincode,
'full_width': k.full_width,
}
for k in keys
]
render_tv(
args,
'zip_0032_registered',
(
('context_string', '&\'static [u8]'),
('seed', '[u8; 32]'),
('zip_number', 'u16'),
('subpath', '&\'static [(u32, &\'static [u8])]'),
('sk', '[u8; 32]'),
('c', '[u8; 32]'),
('full_width', 'Option<[u8; 64]>'),
),
test_vectors,
)
class ArbitraryKey(object):
Arbitrary = HardenedOnlyContext(b'ZcashArbitraryKD', b'\xAB')
Adhoc = HardenedOnlyContext(b'ZcashArbitraryKD', b'\xAB')
def __init__(self, IKM, path, sk, chaincode):
self.IKM = IKM
@ -53,11 +126,11 @@ class ArbitraryKey(object):
assert 32 <= length_S <= 252
IKM = bytes([length_ContextString]) + ContextString + bytes([length_S]) + S
(sk, chaincode) = MKGh(cls.Arbitrary, IKM)
(sk, chaincode) = MKGh(cls.Adhoc, IKM)
return cls(IKM, [], sk, chaincode)
def child(self, i):
(sk_i, c_i) = CKDh(self.Arbitrary, self.sk, self.chaincode, i)
(sk_i, c_i) = CKDh(self.Adhoc, self.sk, self.chaincode, i, 0, b"")
return self.__class__(None, self.path + [i], sk_i, c_i)
@ -84,8 +157,8 @@ def arbitrary_key_derivation_tvs():
'seed': seed,
'ikm': k.IKM,
'path': k.path,
'sk' : k.sk,
'c' : k.chaincode
'sk': k.sk,
'c': k.chaincode,
}
for k in keys
]
@ -94,12 +167,12 @@ def arbitrary_key_derivation_tvs():
args,
'zip_0032_arbitrary',
(
('context_string', 'Vec<u8>'),
('context_string', '&\'static [u8]'),
('seed', '[u8; 32]'),
('ikm', 'Option<Vec<u8>>'),
('path', 'Vec<u32>'),
('sk', '[u8; 32]'),
('c', '[u8; 32]'),
('ikm', 'Option<&\'static [u8]>'),
('path', '&\'static [u32]'),
('sk', '[u8; 32]'),
('c', '[u8; 32]'),
),
test_vectors,
)