Fixing minor nits: conversion to u16 and removing keypair constructor
This commit is contained in:
@@ -44,7 +44,7 @@ yanked = "warn"
|
||||
# The lint level for crates with security notices. Note that as of
|
||||
# 2019-12-17 there are no security notice advisories in
|
||||
# https://github.com/rustsec/advisory-db
|
||||
notice = "warn"
|
||||
notice = "deny"
|
||||
# A list of advisory IDs to ignore. Note that ignored advisories will still
|
||||
# output a note when they are encountered.
|
||||
ignore = [
|
||||
|
||||
@@ -25,6 +25,7 @@ use generic_bytes::SizedBytes;
|
||||
use hkdf::Hkdf;
|
||||
use hmac::{Hmac, Mac, NewMac};
|
||||
use rand::{CryptoRng, RngCore};
|
||||
use std::convert::TryFrom;
|
||||
use zeroize::Zeroize;
|
||||
|
||||
const KEY_LEN: usize = 32;
|
||||
@@ -493,7 +494,9 @@ fn hkdf_expand_label_extracted<D: Hash>(
|
||||
let mut okm = vec![0u8; length];
|
||||
|
||||
let mut hkdf_label: Vec<u8> = Vec::new();
|
||||
hkdf_label.extend_from_slice(&length.to_be_bytes()[std::mem::size_of::<usize>() - 2..]);
|
||||
|
||||
let length_u16: u16 = u16::try_from(length).map_err(|_| PakeError::SerializationError)?;
|
||||
hkdf_label.extend_from_slice(&length_u16.to_be_bytes());
|
||||
|
||||
let mut opaque_label: Vec<u8> = Vec::new();
|
||||
opaque_label.extend_from_slice(STR_OPAQUE);
|
||||
|
||||
+5
-11
@@ -76,16 +76,6 @@ impl<G: Group> KeyPair<G> {
|
||||
&self.sk
|
||||
}
|
||||
|
||||
/// A constructor that receives public and private key independently as
|
||||
/// bytes
|
||||
pub fn new(public: PublicKey, private: PrivateKey) -> Result<Self, InternalPakeError> {
|
||||
Ok(Self {
|
||||
pk: public,
|
||||
sk: private,
|
||||
_g: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
/// Generating a random key pair given a cryptographic rng
|
||||
pub(crate) fn generate_random<R: RngCore + CryptoRng>(rng: &mut R) -> Self {
|
||||
let sk = G::random_nonzero_scalar(rng);
|
||||
@@ -131,7 +121,11 @@ impl<G: Group> KeyPair<G> {
|
||||
pub fn from_private_key_slice(input: &[u8]) -> Result<Self, InternalPakeError> {
|
||||
let sk = PrivateKey(Key::from_arr(GenericArray::from_slice(input))?);
|
||||
let pk = Self::public_from_private(&sk);
|
||||
Self::new(pk, sk)
|
||||
Ok(Self {
|
||||
pk,
|
||||
sk,
|
||||
_g: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user