1
1
/*
2
- * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
2
+ * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
3
3
*
4
4
* Licensed under the OpenSSL license (the "License"). You may not use
5
5
* this file except in compliance with the License. You can obtain a copy
@@ -63,7 +63,7 @@ static int dh_test(void)
63
63
|| !TEST_true (DH_set0_pqg (dh , p , q , g )))
64
64
goto err1 ;
65
65
66
- if (!DH_check (dh , & i ))
66
+ if (!TEST_true ( DH_check (dh , & i ) ))
67
67
goto err2 ;
68
68
if (!TEST_false (i & DH_CHECK_P_NOT_PRIME )
69
69
|| !TEST_false (i & DH_CHECK_P_NOT_SAFE_PRIME )
@@ -123,6 +123,29 @@ static int dh_test(void)
123
123
/* check whether the public key was calculated correctly */
124
124
TEST_uint_eq (BN_get_word (pub_key2 ), 3331L );
125
125
126
+ if (!TEST_ptr (BN_copy (q , p )) || !TEST_true (BN_add (q , q , BN_value_one ())))
127
+ goto err3 ;
128
+
129
+ if (!TEST_true (DH_check (dh , & i )))
130
+ goto err3 ;
131
+ if (!TEST_true (i & DH_CHECK_INVALID_Q_VALUE )
132
+ || !TEST_false (i & DH_CHECK_Q_NOT_PRIME ))
133
+ goto err3 ;
134
+
135
+ /* Modulus of size: dh check max modulus bits + 1 */
136
+ if (!TEST_true (BN_set_word (p , 1 ))
137
+ || !TEST_true (BN_lshift (p , p , OPENSSL_DH_CHECK_MAX_MODULUS_BITS )))
138
+ goto err3 ;
139
+
140
+ /*
141
+ * We expect no checks at all for an excessively large modulus
142
+ */
143
+ if (!TEST_false (DH_check (dh , & i )))
144
+ goto err3 ;
145
+
146
+ /* We'll have a stale error on the queue from the above test so clear it */
147
+ ERR_clear_error ();
148
+
126
149
/*
127
150
* II) key generation
128
151
*/
@@ -137,7 +160,7 @@ static int dh_test(void)
137
160
goto err3 ;
138
161
139
162
/* ... and check whether it is valid */
140
- if (!DH_check (a , & i ))
163
+ if (!TEST_true ( DH_check (a , & i ) ))
141
164
goto err3 ;
142
165
if (!TEST_false (i & DH_CHECK_P_NOT_PRIME )
143
166
|| !TEST_false (i & DH_CHECK_P_NOT_SAFE_PRIME )
0 commit comments