From f55ee3c51b21da881e48526255ac448cfe1c06ef Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Tue, 20 Feb 2018 09:32:15 -0500 Subject: Add some additional error checking to DL_Group --- src/lib/pubkey/dl_group/dl_group.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/pubkey/dl_group/dl_group.cpp b/src/lib/pubkey/dl_group/dl_group.cpp index 3e362801e..791cab8aa 100644 --- a/src/lib/pubkey/dl_group/dl_group.cpp +++ b/src/lib/pubkey/dl_group/dl_group.cpp @@ -194,6 +194,9 @@ DL_Group::DL_Group(RandomNumberGenerator& rng, if(type == Strong) { + if(qbits != 0 && qbits != pbits - 1) + throw Invalid_Argument("Cannot create strong-prime DL_Group with specified q bits"); + const BigInt p = random_safe_prime(rng, pbits); const BigInt q = (p - 1) / 2; @@ -388,6 +391,9 @@ BigInt DL_Group::power_g_p(const BigInt& x) const */ std::vector DL_Group::DER_encode(Format format) const { + if(get_q().is_zero() && (format == ANSI_X9_57 || format == ANSI_X9_42)) + throw Encoding_Error("Cannot encode DL_Group in ANSI formats when q param is missing"); + if(format == ANSI_X9_57) { return DER_Encoder() -- cgit v1.2.3