This commit is contained in:
2025-08-05 16:21:33 +02:00
parent 56af312aad
commit 8cc828fc0e
5 changed files with 304 additions and 609 deletions

View File

@@ -3,6 +3,7 @@
use k256::{SecretKey, ecdh::diffie_hellman, elliptic_curve::sec1::ToEncodedPoint};
use sha2::Sha256;
use getrandom::fill;
use crate::{error::CryptoError, key::symmetric::SymmetricKey};
@@ -22,7 +23,7 @@ impl AsymmetricKeypair {
/// Generates a new random keypair
pub fn new() -> Result<Self, CryptoError> {
let mut raw_private = [0u8; 32];
rand::fill(&mut raw_private);
fill(&mut raw_private);
let sk = SecretKey::from_slice(&raw_private)
.expect("Key is provided generated with fixed valid size");
let pk = sk.public_key();

View File

@@ -4,6 +4,7 @@ use k256::ecdsa::{
Signature, SigningKey, VerifyingKey,
signature::{Signer, Verifier},
};
use getrandom::fill;
use crate::error::CryptoError;
@@ -19,7 +20,7 @@ impl SigningKeypair {
/// Generates a new random keypair
pub fn new() -> Result<Self, CryptoError> {
let mut raw_private = [0u8; 32];
rand::fill(&mut raw_private);
fill(&mut raw_private);
let sk = SigningKey::from_slice(&raw_private)
.expect("Key is provided generated with fixed valid size");
let vk = sk.verifying_key().to_owned();

View File

@@ -5,6 +5,7 @@
//! Keys are 32 bytes in size.
use chacha20poly1305::{ChaCha20Poly1305, KeyInit, Nonce, aead::Aead};
use getrandom::fill;
use crate::error::CryptoError;
@@ -18,7 +19,7 @@ impl SymmetricKey {
/// Generate a new random SymmetricKey.
pub fn new() -> Self {
let mut key = [0u8; 32];
rand::fill(&mut key);
fill(&mut key);
Self(key)
}
@@ -47,7 +48,7 @@ impl SymmetricKey {
// Generate random nonce
let mut nonce_bytes = [0u8; NONCE_SIZE];
rand::fill(&mut nonce_bytes);
fill(&mut nonce_bytes);
let nonce = Nonce::from_slice(&nonce_bytes);
// Encrypt message