aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/dl_group
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-02-20 09:32:15 -0500
committerJack Lloyd <[email protected]>2018-02-20 09:32:15 -0500
commitf55ee3c51b21da881e48526255ac448cfe1c06ef (patch)
tree9cabd58d8d0b0e866e4132168ab7a795a64099e0 /src/lib/pubkey/dl_group
parenta999868535ef9c9bf160650c32ce16a10d8a3e63 (diff)
Add some additional error checking to DL_Group
Diffstat (limited to 'src/lib/pubkey/dl_group')
-rw-r--r--src/lib/pubkey/dl_group/dl_group.cpp6
1 files changed, 6 insertions, 0 deletions
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<uint8_t> 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()