Cleanup formatting

This commit is contained in:
John Preston 2017-12-07 09:34:11 +04:00 committed by Berkus Decker
parent 71daae1227
commit c2edb39069
3 changed files with 29 additions and 8 deletions

View File

@ -83,11 +83,18 @@ public:
} }
} }
void setBytes(base::const_byte_span bytes) { void setBytes(base::const_byte_span bytes) {
if (!BN_bin2bn(reinterpret_cast<const unsigned char*>(bytes.data()), bytes.size(), raw())) { if (!BN_bin2bn(
reinterpret_cast<const unsigned char*>(bytes.data()),
bytes.size(),
raw())) {
_failed = true; _failed = true;
} }
} }
void setModExp(const BigNum &a, const BigNum &p, const BigNum &m, const Context &context = Context()) { void setModExp(
const BigNum &a,
const BigNum &p,
const BigNum &m,
const Context &context = Context()) {
if (a.failed() || p.failed() || m.failed()) { if (a.failed() || p.failed() || m.failed()) {
_failed = true; _failed = true;
} else if (a.isNegative() || p.isNegative() || m.isNegative()) { } else if (a.isNegative() || p.isNegative() || m.isNegative()) {
@ -134,7 +141,11 @@ public:
return false; return false;
} }
constexpr auto kMillerRabinIterationCount = 30; constexpr auto kMillerRabinIterationCount = 30;
auto result = BN_is_prime_ex(raw(), kMillerRabinIterationCount, context.raw(), NULL); auto result = BN_is_prime_ex(
raw(),
kMillerRabinIterationCount,
context.raw(),
NULL);
if (result == 1) { if (result == 1) {
return true; return true;
} else if (result != 0) { } else if (result != 0) {
@ -169,7 +180,9 @@ public:
} }
auto length = BN_num_bytes(raw()); auto length = BN_num_bytes(raw());
auto result = base::byte_vector(length, gsl::byte()); auto result = base::byte_vector(length, gsl::byte());
auto resultSize = BN_bn2bin(raw(), reinterpret_cast<unsigned char*>(result.data())); auto resultSize = BN_bn2bin(
raw(),
reinterpret_cast<unsigned char*>(result.data()));
Assert(resultSize == length); Assert(resultSize == length);
return result; return result;
} }

View File

@ -154,7 +154,10 @@ bool IsPrimeAndGood(base::const_byte_span primeBytes, int g) {
return IsPrimeAndGoodCheck(openssl::BigNum(primeBytes), g); return IsPrimeAndGoodCheck(openssl::BigNum(primeBytes), g);
} }
std::vector<gsl::byte> CreateAuthKey(base::const_byte_span firstBytes, base::const_byte_span randomBytes, base::const_byte_span primeBytes) { std::vector<gsl::byte> CreateAuthKey(
base::const_byte_span firstBytes,
base::const_byte_span randomBytes,
base::const_byte_span primeBytes) {
using openssl::BigNum; using openssl::BigNum;
BigNum first(firstBytes); BigNum first(firstBytes);
BigNum prime(primeBytes); BigNum prime(primeBytes);
@ -165,7 +168,10 @@ std::vector<gsl::byte> CreateAuthKey(base::const_byte_span firstBytes, base::con
return BigNum::ModExp(first, BigNum(randomBytes), prime).getBytes(); return BigNum::ModExp(first, BigNum(randomBytes), prime).getBytes();
} }
ModExpFirst CreateModExp(int g, base::const_byte_span primeBytes, base::const_byte_span randomSeed) { ModExpFirst CreateModExp(
int g,
base::const_byte_span primeBytes,
base::const_byte_span randomSeed) {
Expects(randomSeed.size() == ModExpFirst::kRandomPowerSize); Expects(randomSeed.size() == ModExpFirst::kRandomPowerSize);
using namespace openssl; using namespace openssl;

View File

@ -72,12 +72,14 @@ namespace internal {
class RSAPublicKey::Private { class RSAPublicKey::Private {
public: public:
Private(base::const_byte_span key) : _rsa(PEM_read_bio_RSAPublicKey(BIO_new_mem_buf(const_cast<gsl::byte*>(key.data()), key.size()), 0, 0, 0)) { Private(base::const_byte_span key)
: _rsa(PEM_read_bio_RSAPublicKey(BIO_new_mem_buf(const_cast<gsl::byte*>(key.data()), key.size()), 0, 0, 0)) {
if (_rsa) { if (_rsa) {
computeFingerprint(); computeFingerprint();
} }
} }
Private(base::const_byte_span nBytes, base::const_byte_span eBytes) : _rsa(RSA_new()) { Private(base::const_byte_span nBytes, base::const_byte_span eBytes)
: _rsa(RSA_new()) {
if (_rsa) { if (_rsa) {
auto n = openssl::BigNum(nBytes).takeRaw(); auto n = openssl::BigNum(nBytes).takeRaw();
auto e = openssl::BigNum(eBytes).takeRaw(); auto e = openssl::BigNum(eBytes).takeRaw();