Skip to content

Commit

Permalink
crypto: use BoringSSL compatible errors
Browse files Browse the repository at this point in the history
PR-URL: #37297
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
codebytere authored and targos committed Feb 28, 2021
1 parent 19d6eb9 commit 01773ab
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/crypto/crypto_dh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ void DiffieHellman::MemoryInfo(MemoryTracker* tracker) const {
bool DiffieHellman::Init(const char* p, int p_len, int g) {
dh_.reset(DH_new());
if (p_len <= 0) {
BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);
ERR_put_error(ERR_LIB_BN, BN_F_BN_GENERATE_PRIME_EX,
BN_R_BITS_TOO_SMALL, __FILE__, __LINE__);
return false;
}
if (g <= 1) {
DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);
ERR_put_error(ERR_LIB_DH, DH_F_DH_BUILTIN_GENPARAMS,
DH_R_BAD_GENERATOR, __FILE__, __LINE__);
return false;
}
BIGNUM* bn_p =
Expand All @@ -142,18 +144,21 @@ bool DiffieHellman::Init(const char* p, int p_len, int g) {
bool DiffieHellman::Init(const char* p, int p_len, const char* g, int g_len) {
dh_.reset(DH_new());
if (p_len <= 0) {
BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);
ERR_put_error(ERR_LIB_BN, BN_F_BN_GENERATE_PRIME_EX,
BN_R_BITS_TOO_SMALL, __FILE__, __LINE__);
return false;
}
if (g_len <= 0) {
DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);
ERR_put_error(ERR_LIB_DH, DH_F_DH_BUILTIN_GENPARAMS,
DH_R_BAD_GENERATOR, __FILE__, __LINE__);
return false;
}
BIGNUM* bn_g =
BN_bin2bn(reinterpret_cast<const unsigned char*>(g), g_len, nullptr);
if (BN_is_zero(bn_g) || BN_is_one(bn_g)) {
BN_free(bn_g);
DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);
ERR_put_error(ERR_LIB_DH, DH_F_DH_BUILTIN_GENPARAMS,
DH_R_BAD_GENERATOR, __FILE__, __LINE__);
return false;
}
BIGNUM* bn_p =
Expand Down

0 comments on commit 01773ab

Please sign in to comment.