feat: use fake random

This commit is contained in:
2023-03-12 22:05:55 +08:00
parent f7b23d0943
commit e7f03687dc

View File

@@ -1,6 +1,6 @@
use elliptic_curve::rand_core::{CryptoRng, Error, RngCore};
use p256::{ecdh::EphemeralSecret, PublicKey};
use p256::elliptic_curve::sec1::{FromEncodedPoint, ToEncodedPoint};
use rand::rngs::OsRng;
use rust_util::{failure_and_exit, information, warning, XResult};
use yubikey::certificate::PublicKeyInfo;
use yubikey::Context;
@@ -40,6 +40,32 @@ impl EphemeralKeyBytes {
}
}
struct FakeRandom;
impl CryptoRng for FakeRandom {}
impl RngCore for FakeRandom {
fn next_u32(&mut self) -> u32 {
todo!()
}
fn next_u64(&mut self) -> u64 {
todo!()
}
fn fill_bytes(&mut self, dest: &mut [u8]) {
println!("Fill random dest len: {}", dest.len());
for i in 0..dest.len() {
dest[i]= 0x01;
}
}
fn try_fill_bytes(&mut self, _dest: &mut [u8]) -> Result<(), Error> {
todo!()
}
}
fn main() -> XResult<()> {
let mut readers = Context::open()?;
let reader = readers.iter()?.next().unwrap_or_else(|| failure_and_exit!("No reader!"));
@@ -47,7 +73,8 @@ fn main() -> XResult<()> {
information!("Yubikey serial: {}", yubikey.serial().0);
let esk = EphemeralSecret::random(&mut OsRng);
// let esk = EphemeralSecret::random(&mut rand::rngs::OsRng);
let esk = EphemeralSecret::random(&mut FakeRandom);
let epk = esk.public_key();
let epk_bytes = EphemeralKeyBytes::from_public_key(&epk);