5050 * ([email protected] ). This product includes software written by Tim 51515252
53+ #ifndef DEPS_NCRYPTO_DH_PRIMES_H_
54+ #define DEPS_NCRYPTO_DH_PRIMES_H_
55+
5356#include <openssl/dh.h>
5457
5558#include <openssl/bn.h>
5659#include <openssl/err.h>
5760#include <openssl/mem.h>
5861
59- extern "C" int bn_set_words (BIGNUM * bn , const BN_ULONG * words , size_t num );
62+ extern "C" int bn_set_words (BIGNUM * bn , const BN_ULONG * words , size_t num );
6063
61- // Backporting primes that may not be supported in earlier boringssl versions. Intentionally
62- // keeping the existing C-style formatting.
64+ // Backporting primes that may not be supported in earlier boringssl versions.
65+ // Intentionally keeping the existing C-style formatting.
6366
6467#define OPENSSL_ARRAY_SIZE (array ) (sizeof(array) / sizeof((array)[0]))
6568
@@ -71,25 +74,27 @@ extern "C" int bn_set_words(BIGNUM *bn, const BN_ULONG *words, size_t num);
7174#error "Must define either OPENSSL_32_BIT or OPENSSL_64_BIT"
7275#endif
7376
74- static BIGNUM * get_params (BIGNUM * ret , const BN_ULONG * words , size_t num_words ) {
75- BIGNUM * alloc = NULL ;
76- if (ret == NULL ) {
77+ static BIGNUM * get_params (BIGNUM * ret ,
78+ const BN_ULONG * words ,
79+ size_t num_words ) {
80+ BIGNUM * alloc = nullptr ;
81+ if (ret == nullptr ) {
7782 alloc = BN_new ();
78- if (alloc == NULL ) {
79- return NULL ;
83+ if (alloc == nullptr ) {
84+ return nullptr ;
8085 }
8186 ret = alloc ;
8287 }
8388
8489 if (!bn_set_words (ret , words , num_words )) {
8590 BN_free (alloc );
86- return NULL ;
91+ return nullptr ;
8792 }
8893
8994 return ret ;
9095}
9196
92- BIGNUM * BN_get_rfc3526_prime_2048 (BIGNUM * ret ) {
97+ BIGNUM * BN_get_rfc3526_prime_2048 (BIGNUM * ret ) {
9398 static const BN_ULONG kWords [] = {
9499 TOBN (0xffffffff , 0xffffffff ), TOBN (0x15728e5a , 0x8aacaa68 ),
95100 TOBN (0x15d22618 , 0x98fa0510 ), TOBN (0x3995497c , 0xea956ae5 ),
@@ -111,7 +116,7 @@ BIGNUM *BN_get_rfc3526_prime_2048(BIGNUM *ret) {
111116 return get_params (ret , kWords , OPENSSL_ARRAY_SIZE (kWords ));
112117}
113118
114- BIGNUM * BN_get_rfc3526_prime_3072 (BIGNUM * ret ) {
119+ BIGNUM * BN_get_rfc3526_prime_3072 (BIGNUM * ret ) {
115120 static const BN_ULONG kWords [] = {
116121 TOBN (0xffffffff , 0xffffffff ), TOBN (0x4b82d120 , 0xa93ad2ca ),
117122 TOBN (0x43db5bfc , 0xe0fd108e ), TOBN (0x08e24fa0 , 0x74e5ab31 ),
@@ -141,7 +146,7 @@ BIGNUM *BN_get_rfc3526_prime_3072(BIGNUM *ret) {
141146 return get_params (ret , kWords , OPENSSL_ARRAY_SIZE (kWords ));
142147}
143148
144- BIGNUM * BN_get_rfc3526_prime_4096 (BIGNUM * ret ) {
149+ BIGNUM * BN_get_rfc3526_prime_4096 (BIGNUM * ret ) {
145150 static const BN_ULONG kWords [] = {
146151 TOBN (0xffffffff , 0xffffffff ), TOBN (0x4df435c9 , 0x34063199 ),
147152 TOBN (0x86ffb7dc , 0x90a6c08f ), TOBN (0x93b4ea98 , 0x8d8fddc1 ),
@@ -179,7 +184,7 @@ BIGNUM *BN_get_rfc3526_prime_4096(BIGNUM *ret) {
179184 return get_params (ret , kWords , OPENSSL_ARRAY_SIZE (kWords ));
180185}
181186
182- BIGNUM * BN_get_rfc3526_prime_6144 (BIGNUM * ret ) {
187+ BIGNUM * BN_get_rfc3526_prime_6144 (BIGNUM * ret ) {
183188 static const BN_ULONG kWords [] = {
184189 TOBN (0xffffffff , 0xffffffff ), TOBN (0xe694f91e , 0x6dcc4024 ),
185190 TOBN (0x12bf2d5b , 0x0b7474d6 ), TOBN (0x043e8f66 , 0x3f4860ee ),
@@ -233,7 +238,7 @@ BIGNUM *BN_get_rfc3526_prime_6144(BIGNUM *ret) {
233238 return get_params (ret , kWords , OPENSSL_ARRAY_SIZE (kWords ));
234239}
235240
236- BIGNUM * BN_get_rfc3526_prime_8192 (BIGNUM * ret ) {
241+ BIGNUM * BN_get_rfc3526_prime_8192 (BIGNUM * ret ) {
237242 static const BN_ULONG kWords [] = {
238243 TOBN (0xffffffff , 0xffffffff ), TOBN (0x60c980dd , 0x98edd3df ),
239244 TOBN (0xc81f56e8 , 0x80b96e71 ), TOBN (0x9e3050e2 , 0x765694df ),
@@ -302,3 +307,5 @@ BIGNUM *BN_get_rfc3526_prime_8192(BIGNUM *ret) {
302307 };
303308 return get_params (ret , kWords , OPENSSL_ARRAY_SIZE (kWords ));
304309}
310+
311+ #endif // DEPS_NCRYPTO_DH_PRIMES_H_
0 commit comments