Implement ZIP 32 diversifier derivation

This commit is contained in:
Jack Grigg 2021-03-05 23:36:38 +00:00
parent f0779792bc
commit ceac39d74e
2 changed files with 10 additions and 2 deletions

View File

@ -19,8 +19,10 @@ publish = false
rustdoc-args = [ "--html-in-header", "katex-header.html" ]
[dependencies]
aes = "0.6"
blake2b_simd = "0.5"
ff = "0.9"
fpe = "0.4"
group = "0.9"
halo2 = { git = "https://github.com/zcash/halo2.git", branch = "main" }
nonempty = "0.6"

View File

@ -3,6 +3,8 @@
use std::convert::TryInto;
use std::mem;
use aes::Aes256;
use fpe::ff1::{BinaryNumeralString, FF1};
use group::GroupEncoding;
use halo2::{arithmetic::FieldExt, pasta::pallas};
use subtle::CtOption;
@ -176,8 +178,12 @@ impl DiversifierKey {
}
/// Returns the diversifier at the given index.
pub fn get(&self, _: impl Into<DiversifierIndex>) -> Diversifier {
todo!()
pub fn get(&self, j: impl Into<DiversifierIndex>) -> Diversifier {
let ff = FF1::<Aes256>::new(&self.0, 2).expect("valid radix");
let enc = ff
.encrypt(&[], &BinaryNumeralString::from_bytes_le(&j.into().0[..]))
.unwrap();
Diversifier(enc.to_bytes_le().try_into().unwrap())
}
}