summaryrefslogtreecommitdiff
path: root/dh.c
diff options
context:
space:
mode:
authordjm <djm>2008-06-29 12:47:04 +0000
committerdjm <djm>2008-06-29 12:47:04 +0000
commit68b39b2dce6364fc87fb39667570bbbe16d24774 (patch)
tree1adbc2bb85b3f555134f8b4dbc25c79eeff3c98c /dh.c
parentff6446343380ce7e4ad2542a997b503bd7a2ae4e (diff)
downloadopenssh-68b39b2dce6364fc87fb39667570bbbe16d24774.tar.gz
- djm@cvs.openbsd.org 2008/06/26 09:19:40
[dh.c dh.h moduli.c] when loading moduli from /etc/moduli in sshd(8), check that they are of the expected "safe prime" structure and have had appropriate primality tests performed; feedback and ok dtucker@
Diffstat (limited to 'dh.c')
-rw-r--r--dh.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/dh.c b/dh.c
index 0908fcf1..b7660532 100644
--- a/dh.c
+++ b/dh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dh.c,v 1.46 2008/04/13 00:22:17 djm Exp $ */
+/* $OpenBSD: dh.c,v 1.47 2008/06/26 09:19:39 djm Exp $ */
/*
* Copyright (c) 2000 Niels Provos. All rights reserved.
*
@@ -46,6 +46,7 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg)
char *cp, *arg;
char *strsize, *gen, *prime;
const char *errstr = NULL;
+ long long n;
cp = line;
if ((arg = strdelim(&cp)) == NULL)
@@ -62,12 +63,24 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg)
arg = strsep(&cp, " "); /* type */
if (cp == NULL || *arg == '\0')
goto fail;
+ /* Ensure this is a safe prime */
+ n = strtonum(arg, 0, 5, &errstr);
+ if (errstr != NULL || n != MODULI_TYPE_SAFE)
+ goto fail;
arg = strsep(&cp, " "); /* tests */
if (cp == NULL || *arg == '\0')
goto fail;
+ /* Ensure prime has been tested and is not composite */
+ n = strtonum(arg, 0, 0x1f, &errstr);
+ if (errstr != NULL ||
+ (n & MODULI_TESTS_COMPOSITE) || !(n & ~MODULI_TESTS_COMPOSITE))
+ goto fail;
arg = strsep(&cp, " "); /* tries */
if (cp == NULL || *arg == '\0')
goto fail;
+ n = strtonum(arg, 0, 1<<30, &errstr);
+ if (errstr != NULL || n == 0)
+ goto fail;
strsize = strsep(&cp, " "); /* size */
if (cp == NULL || *strsize == '\0' ||
(dhg->size = (u_int)strtonum(strsize, 0, 64*1024, &errstr)) == 0 ||