Follow OTClient code style
This commit is contained in:
parent
79e31cb041
commit
9186ac5321
|
@ -330,20 +330,15 @@ void Crypt::rsaSetPublicKey(const std::string& n, const std::string& e)
|
||||||
BN_dec2bn(&m_rsa->n, n.c_str());
|
BN_dec2bn(&m_rsa->n, n.c_str());
|
||||||
BN_dec2bn(&m_rsa->e, e.c_str());
|
BN_dec2bn(&m_rsa->e, e.c_str());
|
||||||
// clear rsa cache
|
// clear rsa cache
|
||||||
if (m_rsa->_method_mod_n)
|
if(m_rsa->_method_mod_n) {
|
||||||
{
|
|
||||||
BN_MONT_CTX_free(m_rsa->_method_mod_n);
|
BN_MONT_CTX_free(m_rsa->_method_mod_n);
|
||||||
m_rsa->_method_mod_n = NULL;
|
m_rsa->_method_mod_n = nullptr;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
{
|
BIGNUM *bn, *be;
|
||||||
BIGNUM *bn=NULL;
|
|
||||||
BIGNUM *be=NULL;
|
|
||||||
BN_dec2bn(&bn, n.c_str());
|
BN_dec2bn(&bn, n.c_str());
|
||||||
BN_dec2bn(&be, e.c_str());
|
BN_dec2bn(&be, e.c_str());
|
||||||
RSA_set0_key(m_rsa,bn,be,NULL);
|
RSA_set0_key(m_rsa, bn, be, nullptr);
|
||||||
// note, not supposed to free bn/be here, that's m_rsa's destructor's job
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,30 +352,20 @@ void Crypt::rsaSetPrivateKey(const std::string& p, const std::string& q, const s
|
||||||
if (m_rsa->_method_mod_p)
|
if (m_rsa->_method_mod_p)
|
||||||
{
|
{
|
||||||
BN_MONT_CTX_free(m_rsa->_method_mod_p);
|
BN_MONT_CTX_free(m_rsa->_method_mod_p);
|
||||||
m_rsa->_method_mod_p = NULL;
|
m_rsa->_method_mod_p = nullptr;
|
||||||
}
|
}
|
||||||
if (m_rsa->_method_mod_q)
|
if (m_rsa->_method_mod_q)
|
||||||
{
|
{
|
||||||
BN_MONT_CTX_free(m_rsa->_method_mod_q);
|
BN_MONT_CTX_free(m_rsa->_method_mod_q);
|
||||||
m_rsa->_method_mod_q = NULL;
|
m_rsa->_method_mod_q = nullptr;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
{
|
BIGNUM *bp, *bq, *bd;
|
||||||
|
|
||||||
if(d.length()> 0)
|
|
||||||
{
|
|
||||||
BIGNUM *bd=NULL;
|
|
||||||
BN_dec2bn(&bd, d.c_str());
|
|
||||||
RSA_set0_key(m_rsa,NULL,NULL,bd);
|
|
||||||
}
|
|
||||||
BIGNUM *bp=NULL;
|
|
||||||
BIGNUM *bq=NULL;
|
|
||||||
BN_dec2bn(&bp, p.c_str());
|
BN_dec2bn(&bp, p.c_str());
|
||||||
BN_dec2bn(&bq, q.c_str());
|
BN_dec2bn(&bq, q.c_str());
|
||||||
RSA_set0_factors(m_rsa,bp,bq);
|
BN_dec2bn(&bd, d.c_str());
|
||||||
// note, not supposed to free bp/bq/bd here, that's m_rsa's destructor's job
|
RSA_set0_key(m_rsa, nullptr, nullptr, bd);
|
||||||
|
RSA_set0_factors(m_rsa, bp, bq);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,30 +382,24 @@ bool Crypt::rsaCheckKey()
|
||||||
BN_mod(m_rsa->dmq1, m_rsa->d, r2, ctx);
|
BN_mod(m_rsa->dmq1, m_rsa->d, r2, ctx);
|
||||||
BN_mod_inverse(m_rsa->iqmp, m_rsa->q, m_rsa->p, ctx);
|
BN_mod_inverse(m_rsa->iqmp, m_rsa->q, m_rsa->p, ctx);
|
||||||
#else
|
#else
|
||||||
{
|
const BIGNUM *dmp1_c, *d, *dmq1_c, *iqmp_c, *q, *p;
|
||||||
const BIGNUM *dmp1_c=NULL;
|
|
||||||
const BIGNUM *d=NULL;
|
RSA_get0_key(m_rsa, nullptr, nullptr, &d);
|
||||||
const BIGNUM *dmq1_c=NULL;
|
|
||||||
const BIGNUM *iqmp_c=NULL;
|
|
||||||
const BIGNUM *q=NULL;
|
|
||||||
const BIGNUM *p=NULL;
|
|
||||||
RSA_get0_key(m_rsa,NULL, NULL, &d);
|
|
||||||
RSA_get0_factors(m_rsa, &p, &q);
|
RSA_get0_factors(m_rsa, &p, &q);
|
||||||
RSA_get0_crt_params(m_rsa,&dmp1_c,&dmq1_c,&iqmp_c);
|
RSA_get0_crt_params(m_rsa, &dmp1_c, &dmq1_c, &iqmp_c);
|
||||||
BIGNUM *dmp1=BN_dup(dmp1_c);
|
|
||||||
BIGNUM *dmq1=BN_dup(dmq1_c);
|
BIGNUM *dmp1 = BN_dup(dmp1_c), *dmq1 = BN_dup(dmq1_c), *iqmp = BN_dup(iqmp_c);
|
||||||
BIGNUM *iqmp=BN_dup(iqmp_c);
|
|
||||||
BN_mod(dmp1, d, r1, ctx);
|
BN_mod(dmp1, d, r1, ctx);
|
||||||
BN_mod(dmq1, d, r2, ctx);
|
BN_mod(dmq1, d, r2, ctx);
|
||||||
BN_mod_inverse(iqmp, q, p, ctx);
|
BN_mod_inverse(iqmp, q, p, ctx);
|
||||||
RSA_set0_crt_params(m_rsa, dmp1, dmq1, iqmp);
|
RSA_set0_crt_params(m_rsa, dmp1, dmq1, iqmp);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ERR_load_crypto_strings();
|
ERR_load_crypto_strings();
|
||||||
g_logger.error(stdext::format("RSA check failed - %s", ERR_error_string(ERR_get_error(), NULL)));
|
g_logger.error(stdext::format("RSA check failed - %s", ERR_error_string(ERR_get_error(), nullptr)));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -443,4 +422,3 @@ int Crypt::rsaGetSize()
|
||||||
{
|
{
|
||||||
return RSA_size(m_rsa);
|
return RSA_size(m_rsa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue