diff --git a/Cargo.toml b/Cargo.toml index 9c19eb44..4fa34aef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/keys.rs b/src/keys.rs index 2049da28..e66f5c17 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -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) -> Diversifier { - todo!() + pub fn get(&self, j: impl Into) -> Diversifier { + let ff = FF1::::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()) } }