jeudi 21 octobre 2021

Is there a way to seed a cryptographically secure RNG engine int rust using a [u8; 64] array?

I am currently trying to write a library in rust - to be compiled to WASM - for working with bip39 mnemonic keys. I am currently using tiny-bip39 and RSA.

When generating a private key using RSA as per the example given on RSA I want to seed the rng based on the mnemonic passphrase I have passed into the function. I tried achieving this by simply getting the seed from the mnemonic object generated by tiny-bip39, however this seems to generate a &[u8] with a length of 64. However, Seed is defined as [u8; 32], and without having to write my own rng, I cannot figure out how to use a len 64 seed.

#[wasm_bindgen]
pub fn get_key_from_mnemonic(phrase: &str) {
    let mnemonic = Mnemonic::from_phrase(phrase, Language::English).unwrap();

    assert_eq!(phrase, mnemonic.phrase());

    let seed = Seed::new(&mnemonic, "");
    let seed_bytes = seed.as_bytes();

    let mut rng = ChaCha12Rng::from_seed(seed_bytes);

    [...]
}

Is there a cryptographically secure rng that allows for len 64 seed?

I tried simply trying into, but that did not seem to work, which makes sense.

let seed_bytes: <ChaCha12Rng as SeedableRng>::Seed = seed.as_bytes().try_into().unwrap();



Aucun commentaire:

Enregistrer un commentaire