diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-06-27 16:49:14 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-06-28 10:18:10 +0200 |
commit | 06eac62a0619003a317ccc2cccee4c0abcc3eacd (patch) | |
tree | 27c95113234b436cdb52229d1c4633479e495bd8 | |
parent | 951222e19c71160b88e08df16296d406bae7b176 (diff) |
openpgp: Parse MPIs of ElGamal signatures.
-rw-r--r-- | openpgp/src/mpis.rs | 17 | ||||
-rw-r--r-- | openpgp/src/parse/mpis.rs | 12 | ||||
-rw-r--r-- | openpgp/src/serialize/mod.rs | 4 |
3 files changed, 32 insertions, 1 deletions
diff --git a/openpgp/src/mpis.rs b/openpgp/src/mpis.rs index 038c40bd..d72740c2 100644 --- a/openpgp/src/mpis.rs +++ b/openpgp/src/mpis.rs @@ -141,6 +141,13 @@ pub enum MPIs { /// Ciphertext. c: MPI }, + /// Elgamal signature + ElgamalSignature { + /// `r` value. + r: MPI, + /// `s` value. + s: MPI + }, /// DJBs "Twisted" Edwards curve DSA public key. EdDSAPublicKey { @@ -244,6 +251,8 @@ impl MPIs { &ElgamalSecretKey { ref x } => 2 + x.value.len(), &ElgamalCiphertext { ref e, ref c } => 2 + e.value.len() + 2 + c.value.len(), + &ElgamalSignature { ref r, ref s } => + 2 + r.value.len() + 2 + s.value.len(), &EdDSAPublicKey { ref curve, ref q } => 2 + q.value.len() + @@ -332,6 +341,11 @@ impl MPIs { c.hash(hash); } + &ElgamalSignature { ref r, ref s } => { + r.hash(hash); + s.hash(hash); + } + &EdDSAPublicKey { ref curve, ref q } => { hash.update(&[curve.oid().len() as u8]); hash.update(curve.oid()); @@ -548,6 +562,9 @@ mod tests { MPIs::DSASignature { .. } => MPIs::parse_signature_naked( DSA, cur.into_inner()).unwrap(), + MPIs::ElgamalSignature { .. } => + MPIs::parse_signature_naked( + ElgamalEncryptSign, cur.into_inner()).unwrap(), MPIs::EdDSASignature { .. } => MPIs::parse_signature_naked( EdDSA, cur.into_inner()).unwrap(), diff --git a/openpgp/src/parse/mpis.rs b/openpgp/src/parse/mpis.rs index 0c3e48c3..bf82caa8 100644 --- a/openpgp/src/parse/mpis.rs +++ b/openpgp/src/parse/mpis.rs @@ -368,6 +368,16 @@ impl MPIs { }) } + ElgamalEncryptSign => { + let r = MPI::parse("elgamal_signature_r", php)?; + let s = MPI::parse("elgamal_signature_s", php)?; + + Ok(MPIs::ElgamalSignature{ + r: r, + s: s, + }) + } + EdDSA => { let r = MPI::parse("eddsa_signature_r", php)?; let s = MPI::parse("eddsa_signature_s", php)?; @@ -392,7 +402,7 @@ impl MPIs { Err(Error::UnknownPublicKeyAlgorithm(p.into()).into()) } - RSAEncrypt | ElgamalEncrypt | ElgamalEncryptSign | ECDH => { + RSAEncrypt | ElgamalEncrypt | ECDH => { Err(Error::UnknownPublicKeyAlgorithm(algo).into()) } } diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs index 01d51479..e133ab1b 100644 --- a/openpgp/src/serialize/mod.rs +++ b/openpgp/src/serialize/mod.rs @@ -236,6 +236,10 @@ impl Serialize for mpis::MPIs { e.serialize(w)?; c.serialize(w)?; } + &ElgamalSignature{ ref r, ref s } => { + r.serialize(w)?; + s.serialize(w)?; + } &EdDSAPublicKey{ ref curve, ref q } => { w.write_all(&[curve.oid().len() as u8])?; w.write_all(curve.oid())?; |