General Improvements (#268)
* Move `elliptic-curve` implementation to points to allow `Zeroize` * Simplify `Ristretto255::random_scalar` implementation * Fix `Ristretto255` deserialization * Remove unnecessary check in `Ristretto255::random_scalar` * Base `X25519` implementation on `curve25519-dalek` * Constrain public and secret key to `Copy` * Replace manual `ZeroizeOnDrop` implementation with `derive` * Update dependencies * Add `warn(unused_crate_dependencies)` * Sync crate feature naming with `voprf` * Remove unnecessary dependency crate features * Never produce a zero scalar * Rename `OprfGroup` to `OprfCs` * Rename `TripleDH` to `TripleDh` * Remove `slow-hash` crate feature * Rename `NoOpHash` to `Identity` * Rename `SlowHash` to `Ksf` * Move `KeyExchange` type definitions down * Deserialize secret and public keys from slices * Remove `PrivateKey::from_bytes` * Rename `From/ToBytes` to `De/Serialize` * Re-export `serde_` as `serde` * Custom `De/Serialize` implementation for keys * Remove custom `De/Serialize` implementation * Run Taplo v0.6
This commit is contained in:
@@ -18,25 +18,26 @@ use digest::Digest;
|
||||
use generic_array::typenum::{IsLess, IsLessOrEqual, U256};
|
||||
use generic_array::{ArrayLength, GenericArray};
|
||||
use rand::{CryptoRng, RngCore};
|
||||
use zeroize::Zeroize;
|
||||
|
||||
use crate::errors::InternalError;
|
||||
|
||||
/// A group representation for use in the key exchange
|
||||
pub trait KeGroup {
|
||||
/// Public key
|
||||
type Pk: Clone;
|
||||
type Pk: Copy + Zeroize;
|
||||
/// Length of the public key
|
||||
type PkLen: ArrayLength<u8>;
|
||||
/// Secret key
|
||||
type Sk: Clone;
|
||||
type Sk: Copy + Zeroize;
|
||||
/// Length of the secret key
|
||||
type SkLen: ArrayLength<u8>;
|
||||
|
||||
/// Serializes `self`
|
||||
fn serialize_pk(pk: &Self::Pk) -> GenericArray<u8, Self::PkLen>;
|
||||
fn serialize_pk(pk: Self::Pk) -> GenericArray<u8, Self::PkLen>;
|
||||
|
||||
/// Return a public key from its fixed-length bytes representation
|
||||
fn deserialize_pk(bytes: &GenericArray<u8, Self::PkLen>) -> Result<Self::Pk, InternalError>;
|
||||
fn deserialize_pk(bytes: &[u8]) -> Result<Self::Pk, InternalError>;
|
||||
|
||||
/// Generate a random secret key
|
||||
fn random_sk<R: RngCore + CryptoRng>(rng: &mut R) -> Self::Sk;
|
||||
@@ -52,17 +53,14 @@ pub trait KeGroup {
|
||||
H::OutputSize: IsLess<U256> + IsLessOrEqual<H::BlockSize>;
|
||||
|
||||
/// Return a public key from its secret key
|
||||
fn public_key(sk: &Self::Sk) -> Self::Pk;
|
||||
fn public_key(sk: Self::Sk) -> Self::Pk;
|
||||
|
||||
/// Diffie-Hellman key exchange
|
||||
fn diffie_hellman(pk: &Self::Pk, sk: &Self::Sk) -> GenericArray<u8, Self::PkLen>;
|
||||
|
||||
/// Zeroize secret key on drop.
|
||||
fn zeroize_sk_on_drop(sk: &mut Self::Sk);
|
||||
fn diffie_hellman(pk: Self::Pk, sk: Self::Sk) -> GenericArray<u8, Self::PkLen>;
|
||||
|
||||
/// Serializes `self`
|
||||
fn serialize_sk(sk: &Self::Sk) -> GenericArray<u8, Self::SkLen>;
|
||||
fn serialize_sk(sk: Self::Sk) -> GenericArray<u8, Self::SkLen>;
|
||||
|
||||
/// Return a public key from its fixed-length bytes representation
|
||||
fn deserialize_sk(bytes: &GenericArray<u8, Self::SkLen>) -> Result<Self::Sk, InternalError>;
|
||||
fn deserialize_sk(bytes: &[u8]) -> Result<Self::Sk, InternalError>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user