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:
+30
-30
@@ -25,9 +25,9 @@ use crate::errors::*;
|
||||
use crate::hash::{Hash, OutputSize, ProxyHash};
|
||||
use crate::key_exchange::group::KeGroup;
|
||||
use crate::key_exchange::traits::{
|
||||
FromBytes, Ke1MessageLen, Ke1StateLen, Ke2MessageLen, KeyExchange, ToBytes,
|
||||
Deserialize, Ke1MessageLen, Ke1StateLen, Ke2MessageLen, KeyExchange, Serialize,
|
||||
};
|
||||
use crate::key_exchange::tripledh::{NonceLen, TripleDH};
|
||||
use crate::key_exchange::tripledh::{NonceLen, TripleDh};
|
||||
use crate::keypair::{KeyPair, SecretKey};
|
||||
use crate::messages::CredentialResponseWithoutKeLen;
|
||||
use crate::opaque::{ClientLoginLen, ClientRegistrationLen, MaskedResponseLen};
|
||||
@@ -39,19 +39,19 @@ struct Ristretto255;
|
||||
|
||||
#[cfg(feature = "ristretto255")]
|
||||
impl CipherSuite for Ristretto255 {
|
||||
type OprfGroup = crate::Ristretto255;
|
||||
type OprfCs = crate::Ristretto255;
|
||||
type KeGroup = crate::Ristretto255;
|
||||
type KeyExchange = TripleDH;
|
||||
type SlowHash = crate::slow_hash::NoOpHash;
|
||||
type KeyExchange = TripleDh;
|
||||
type Ksf = crate::ksf::Identity;
|
||||
}
|
||||
|
||||
struct P256;
|
||||
|
||||
impl CipherSuite for P256 {
|
||||
type OprfGroup = ::p256::NistP256;
|
||||
type OprfCs = ::p256::NistP256;
|
||||
type KeGroup = ::p256::NistP256;
|
||||
type KeyExchange = TripleDH;
|
||||
type SlowHash = crate::slow_hash::NoOpHash;
|
||||
type KeyExchange = TripleDh;
|
||||
type Ksf = crate::ksf::Identity;
|
||||
}
|
||||
|
||||
fn random_point<CS: CipherSuite>() -> <CS::KeGroup as KeGroup>::Pk
|
||||
@@ -65,7 +65,7 @@ where
|
||||
{
|
||||
let mut rng = OsRng;
|
||||
let sk = CS::KeGroup::random_sk(&mut rng);
|
||||
CS::KeGroup::public_key(&sk)
|
||||
CS::KeGroup::public_key(sk)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -85,7 +85,7 @@ fn client_registration_roundtrip() -> Result<(), ProtocolError> {
|
||||
let pw = b"hunter2";
|
||||
let mut rng = OsRng;
|
||||
|
||||
let blind_result = &voprf::NonVerifiableClient::<CS::OprfGroup>::blind(pw, &mut rng)?;
|
||||
let blind_result = &voprf::NonVerifiableClient::<CS::OprfCs>::blind(pw, &mut rng)?;
|
||||
|
||||
let bytes: Vec<u8> = blind_result
|
||||
.state
|
||||
@@ -145,7 +145,7 @@ fn server_registration_roundtrip() -> Result<(), ProtocolError> {
|
||||
let mock_client_kp = KeyPair::<CS::KeGroup>::generate_random(&mut rng);
|
||||
// serialization order: oprf_key, public key, envelope
|
||||
let mut bytes = Vec::<u8>::new();
|
||||
bytes.extend_from_slice(&mock_client_kp.public().to_bytes());
|
||||
bytes.extend_from_slice(&mock_client_kp.public().serialize());
|
||||
bytes.extend_from_slice(&masking_key);
|
||||
bytes.extend_from_slice(&mock_envelope_bytes);
|
||||
let reg = ServerRegistration::<CS>::deserialize(&bytes)?;
|
||||
@@ -173,7 +173,7 @@ fn registration_request_roundtrip() -> Result<(), ProtocolError> {
|
||||
Le<<<OprfHash<CS> as CoreProxy>::Core as BlockSizeUser>::BlockSize, U256>: NonZero,
|
||||
{
|
||||
let pt = random_point::<CS>();
|
||||
let pt_bytes = CS::KeGroup::serialize_pk(&pt);
|
||||
let pt_bytes = CS::KeGroup::serialize_pk(pt);
|
||||
|
||||
let mut input = Vec::new();
|
||||
input.extend_from_slice(&pt_bytes);
|
||||
@@ -218,10 +218,10 @@ fn registration_response_roundtrip() -> Result<(), ProtocolError> {
|
||||
RegistrationResponseLen<CS>: ArrayLength<u8>,
|
||||
{
|
||||
let pt = random_point::<CS>();
|
||||
let beta_bytes = CS::KeGroup::serialize_pk(&pt);
|
||||
let beta_bytes = CS::KeGroup::serialize_pk(pt);
|
||||
let mut rng = OsRng;
|
||||
let skp = KeyPair::<CS::KeGroup>::generate_random(&mut rng);
|
||||
let pubkey_bytes = skp.public().to_bytes();
|
||||
let pubkey_bytes = skp.public().serialize();
|
||||
|
||||
let mut input = Vec::new();
|
||||
input.extend_from_slice(&beta_bytes);
|
||||
@@ -275,7 +275,7 @@ fn registration_upload_roundtrip() -> Result<(), ProtocolError> {
|
||||
{
|
||||
let mut rng = OsRng;
|
||||
let skp = KeyPair::<CS::KeGroup>::generate_random(&mut rng);
|
||||
let pubkey_bytes = skp.public().to_bytes();
|
||||
let pubkey_bytes = skp.public().serialize();
|
||||
|
||||
let mut key = [0u8; 32];
|
||||
rng.fill_bytes(&mut key);
|
||||
@@ -331,7 +331,7 @@ fn credential_request_roundtrip() -> Result<(), ProtocolError> {
|
||||
{
|
||||
let mut rng = OsRng;
|
||||
let alpha = random_point::<CS>();
|
||||
let alpha_bytes = CS::KeGroup::serialize_pk(&alpha);
|
||||
let alpha_bytes = CS::KeGroup::serialize_pk(alpha);
|
||||
|
||||
let client_e_kp = KeyPair::<CS::KeGroup>::generate_random(&mut rng);
|
||||
let mut client_nonce = [0u8; NonceLen::USIZE];
|
||||
@@ -339,7 +339,7 @@ fn credential_request_roundtrip() -> Result<(), ProtocolError> {
|
||||
|
||||
let ke1m: Vec<u8> = [
|
||||
client_nonce.as_ref(),
|
||||
client_e_kp.public().to_bytes().as_ref(),
|
||||
client_e_kp.public().serialize().as_ref(),
|
||||
]
|
||||
.concat();
|
||||
|
||||
@@ -397,7 +397,7 @@ fn credential_response_roundtrip() -> Result<(), ProtocolError> {
|
||||
CredentialResponseLen<CS>: ArrayLength<u8>,
|
||||
{
|
||||
let pt = random_point::<CS>();
|
||||
let pt_bytes = CS::KeGroup::serialize_pk(&pt);
|
||||
let pt_bytes = CS::KeGroup::serialize_pk(pt);
|
||||
|
||||
let mut rng = OsRng;
|
||||
|
||||
@@ -416,7 +416,7 @@ fn credential_response_roundtrip() -> Result<(), ProtocolError> {
|
||||
|
||||
let ke2m: Vec<u8> = [
|
||||
server_nonce.as_ref(),
|
||||
server_e_kp.public().to_bytes().as_ref(),
|
||||
server_e_kp.public().serialize().as_ref(),
|
||||
&mac,
|
||||
]
|
||||
.concat();
|
||||
@@ -523,15 +523,15 @@ fn client_login_roundtrip() -> Result<(), ProtocolError> {
|
||||
]
|
||||
.concat();
|
||||
|
||||
let blind_result = voprf::NonVerifiableClient::<CS::OprfGroup>::blind(pw, &mut rng)?;
|
||||
let blind_result = voprf::NonVerifiableClient::<CS::OprfCs>::blind(pw, &mut rng)?;
|
||||
|
||||
let credential_request = CredentialRequest::<CS> {
|
||||
blinded_element: blind_result.message,
|
||||
ke1_message:
|
||||
<CS::KeyExchange as KeyExchange<OprfHash<CS>, CS::KeGroup>>::KE1Message::from_bytes(
|
||||
<CS::KeyExchange as KeyExchange<OprfHash<CS>, CS::KeGroup>>::KE1Message::deserialize(
|
||||
&[
|
||||
client_nonce.as_ref(),
|
||||
client_e_kp.public().to_bytes().as_ref(),
|
||||
client_e_kp.public().serialize().as_ref(),
|
||||
]
|
||||
.concat(),
|
||||
)?,
|
||||
@@ -577,14 +577,14 @@ fn ke1_message_roundtrip() -> Result<(), ProtocolError> {
|
||||
|
||||
let ke1m = [
|
||||
client_nonce.as_slice(),
|
||||
client_e_kp.public().to_bytes().as_ref(),
|
||||
client_e_kp.public().serialize().as_ref(),
|
||||
]
|
||||
.concat();
|
||||
let reg =
|
||||
<CS::KeyExchange as KeyExchange<OprfHash<CS>, CS::KeGroup>>::KE1Message::from_bytes(
|
||||
<CS::KeyExchange as KeyExchange<OprfHash<CS>, CS::KeGroup>>::KE1Message::deserialize(
|
||||
&ke1m,
|
||||
)?;
|
||||
let reg_bytes = reg.to_bytes();
|
||||
let reg_bytes = reg.serialize();
|
||||
assert_eq!(*reg_bytes, ke1m);
|
||||
|
||||
Ok(())
|
||||
@@ -618,16 +618,16 @@ fn ke2_message_roundtrip() -> Result<(), ProtocolError> {
|
||||
|
||||
let ke2m: Vec<u8> = [
|
||||
server_nonce.as_slice(),
|
||||
server_e_kp.public().to_bytes().as_ref(),
|
||||
server_e_kp.public().serialize().as_ref(),
|
||||
&mac,
|
||||
]
|
||||
.concat();
|
||||
|
||||
let reg =
|
||||
<CS::KeyExchange as KeyExchange<OprfHash<CS>, CS::KeGroup>>::KE2Message::from_bytes(
|
||||
<CS::KeyExchange as KeyExchange<OprfHash<CS>, CS::KeGroup>>::KE2Message::deserialize(
|
||||
&ke2m,
|
||||
)?;
|
||||
let reg_bytes = reg.to_bytes();
|
||||
let reg_bytes = reg.serialize();
|
||||
assert_eq!(*reg_bytes, ke2m);
|
||||
|
||||
Ok(())
|
||||
@@ -658,10 +658,10 @@ fn ke3_message_roundtrip() -> Result<(), ProtocolError> {
|
||||
let ke3m: Vec<u8> = [mac].concat();
|
||||
|
||||
let reg =
|
||||
<CS::KeyExchange as KeyExchange<OprfHash<CS>, CS::KeGroup>>::KE3Message::from_bytes(
|
||||
<CS::KeyExchange as KeyExchange<OprfHash<CS>, CS::KeGroup>>::KE3Message::deserialize(
|
||||
&ke3m,
|
||||
)?;
|
||||
let reg_bytes = reg.to_bytes();
|
||||
let reg_bytes = reg.serialize();
|
||||
assert_eq!(*reg_bytes, ke3m);
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user