summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2021-11-29 19:41:02 +0000
committertb <>2021-11-29 19:41:02 +0000
commit4603a555cb11f07168441cba6bf88feeae093985 (patch)
treed3d8289acc42833bfaf4f9dae1d5cf6cb1d229ea /src
parente5309bbaa68f8cc6b812d0fd95e304bfc5ad93df (diff)
downloadopenbsd-4603a555cb11f07168441cba6bf88feeae093985.tar.gz
openbsd-4603a555cb11f07168441cba6bf88feeae093985.tar.bz2
openbsd-4603a555cb11f07168441cba6bf88feeae093985.zip
Provide a version of DH_check_params() for internal use.
Based on the version in OpenSSL 1.1.1l with minor tweaks. ok inoguchi jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/dh/dh_check.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/lib/libcrypto/dh/dh_check.c b/src/lib/libcrypto/dh/dh_check.c
index a8227d31ca..d0524fd631 100644
--- a/src/lib/libcrypto/dh/dh_check.c
+++ b/src/lib/libcrypto/dh/dh_check.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_check.c,v 1.17 2019/01/20 01:56:59 tb Exp $ */ 1/* $OpenBSD: dh_check.c,v 1.18 2021/11/29 19:41:02 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -61,6 +61,48 @@
61#include <openssl/bn.h> 61#include <openssl/bn.h>
62#include <openssl/dh.h> 62#include <openssl/dh.h>
63 63
64int
65DH_check_params(const DH *dh, int *flags)
66{
67 BN_CTX *ctx = NULL;
68 BIGNUM *max_g;
69 int ok = 0;
70
71 *flags = 0;
72
73 if ((ctx = BN_CTX_new()) == NULL)
74 goto err;
75 BN_CTX_start(ctx);
76 if ((max_g = BN_CTX_get(ctx)) == NULL)
77 goto err;
78
79 if (!BN_is_odd(dh->p))
80 *flags |= DH_CHECK_P_NOT_PRIME;
81
82 /*
83 * Check that 1 < dh->g < p - 1
84 */
85
86 if (BN_cmp(dh->g, BN_value_one()) <= 0)
87 *flags |= DH_NOT_SUITABLE_GENERATOR;
88 /* max_g = p - 1 */
89 if (BN_copy(max_g, dh->p) == NULL)
90 goto err;
91 if (!BN_sub_word(max_g, 1))
92 goto err;
93 /* check that g < max_g */
94 if (BN_cmp(dh->g, max_g) >= 0)
95 *flags |= DH_NOT_SUITABLE_GENERATOR;
96
97 ok = 1;
98
99 err:
100 BN_CTX_end(ctx);
101 BN_CTX_free(ctx);
102
103 return ok;
104}
105
64/* 106/*
65 * Check that p is a safe prime and 107 * Check that p is a safe prime and
66 * if g is 2, 3 or 5, check that it is a suitable generator 108 * if g is 2, 3 or 5, check that it is a suitable generator