Use the MPI::value_padded() method for left-padding.
This commit is contained in:
parent
40c52c7f3a
commit
ddf62dbfe2
3 changed files with 4 additions and 17 deletions
|
@ -12,7 +12,7 @@ repository = "https://gitlab.com/hkos/openpgp-card"
|
||||||
documentation = "https://docs.rs/crate/openpgp-card-sequoia"
|
documentation = "https://docs.rs/crate/openpgp-card-sequoia"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sequoia-openpgp = "1.3"
|
sequoia-openpgp = "1.4"
|
||||||
nettle = "7"
|
nettle = "7"
|
||||||
openpgp-card = { path = "../openpgp-card", version = "0.0.4" }
|
openpgp-card = { path = "../openpgp-card", version = "0.0.4" }
|
||||||
openpgp-card-pcsc = { path = "../pcsc", version = "0.0.4" }
|
openpgp-card-pcsc = { path = "../pcsc", version = "0.0.4" }
|
||||||
|
|
|
@ -225,9 +225,9 @@ impl EccKey for SqEccKey {
|
||||||
fn get_private(&self) -> Vec<u8> {
|
fn get_private(&self) -> Vec<u8> {
|
||||||
// FIXME: padding for 25519?
|
// FIXME: padding for 25519?
|
||||||
match self.curve {
|
match self.curve {
|
||||||
Curve::NistP256 => util::left_zero_pad(self.private.value(), 0x20),
|
Curve::NistP256 => self.private.value_padded(0x20).to_vec(),
|
||||||
Curve::NistP384 => util::left_zero_pad(self.private.value(), 0x30),
|
Curve::NistP384 => self.private.value_padded(0x30).to_vec(),
|
||||||
Curve::NistP521 => util::left_zero_pad(self.private.value(), 0x42),
|
Curve::NistP521 => self.private.value_padded(0x42).to_vec(),
|
||||||
_ => self.private.value().to_vec(),
|
_ => self.private.value().to_vec(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,16 +305,3 @@ pub fn decrypt(
|
||||||
|
|
||||||
Ok(decrypted)
|
Ok(decrypted)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This fn prepends zeros to `value` so that the resulting Vec<u8> has
|
|
||||||
/// len `size`.
|
|
||||||
///
|
|
||||||
/// (Leading zero-bytes may be stripped from MPIs, this fn is a helper for
|
|
||||||
/// re-creating the non-stripped representation of an MPI)
|
|
||||||
pub(crate) fn left_zero_pad(value: &[u8], size: usize) -> Vec<u8> {
|
|
||||||
let pad = size - value.len();
|
|
||||||
let mut res = vec![0; pad];
|
|
||||||
res.extend_from_slice(value);
|
|
||||||
|
|
||||||
res
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue