From 0c658f5a7cd56e86dfce38aeab18a1054bb88f2e Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 26 Dec 2018 20:35:49 -0500 Subject: [PATCH] PublicKey is optional for curve25519 --- xed25519.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/xed25519.cpp b/xed25519.cpp index 900f4ab8..05414e45 100644 --- a/xed25519.cpp +++ b/xed25519.cpp @@ -173,9 +173,12 @@ void x25519::BERDecode(BufferedTransformation &bt) BERDecodePrivateKey(octetString, false, (size_t)privateKeyInfo.RemainingLength()); octetString.MessageEnd(); + // publicKey [1] IMPLICIT PublicKey OPTIONAL bool generatePublicKey = true; - if (version == 1) + if (privateKeyInfo.EndReached() == false /*version == 1?*/) { + // Should we test this before decoding? In either case we + // just throw a BERDecodeErr() when we can't parse it. BERGeneralDecoder publicKey(privateKeyInfo, CONTEXT_SPECIFIC | CONSTRUCTED | 1); SecByteBlock subjectPublicKey; unsigned int unusedBits; @@ -510,9 +513,12 @@ void ed25519PrivateKey::BERDecode(BufferedTransformation &bt) BERDecodePrivateKey(octetString, false, (size_t)privateKeyInfo.RemainingLength()); octetString.MessageEnd(); + // publicKey [1] IMPLICIT PublicKey OPTIONAL bool generatePublicKey = true; - if (version == 1) + if (privateKeyInfo.EndReached() == false /*version == 1?*/) { + // Should we test this before decoding? In either case we + // just throw a BERDecodeErr() when we can't parse it. BERGeneralDecoder publicKey(privateKeyInfo, CONTEXT_SPECIFIC | CONSTRUCTED | 1); SecByteBlock subjectPublicKey; unsigned int unusedBits;