Skip to content

Commit

Permalink
src: linting cleanups with crypto changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Sep 3, 2024
1 parent 0867fc8 commit ed97c62
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
30 changes: 15 additions & 15 deletions src/crypto/crypto_hkdf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,21 @@ bool HKDFTraits::DeriveBits(
Environment* env,
const HKDFConfig& params,
ByteSource* out) {
auto dp = ncrypto::hkdf(
params.digest,
ncrypto::Buffer<const unsigned char> {
.data = reinterpret_cast<const unsigned char*>(params.key->GetSymmetricKey()),
.len = params.key->GetSymmetricKeySize(),
},
ncrypto::Buffer<const unsigned char> {
.data = params.info.data<const unsigned char>(),
.len = params.info.size(),
},
ncrypto::Buffer<const unsigned char> {
.data = params.salt.data<const unsigned char>(),
.len = params.salt.size(),
},
params.length);
auto dp = ncrypto::hkdf(params.digest,
ncrypto::Buffer<const unsigned char>{
.data = reinterpret_cast<const unsigned char*>(
params.key->GetSymmetricKey()),
.len = params.key->GetSymmetricKeySize(),
},
ncrypto::Buffer<const unsigned char>{
.data = params.info.data<const unsigned char>(),
.len = params.info.size(),
},
ncrypto::Buffer<const unsigned char>{
.data = params.salt.data<const unsigned char>(),
.len = params.salt.size(),
},
params.length);
if (!dp) return false;

*out = ByteSource::Allocated(dp.release());
Expand Down
19 changes: 9 additions & 10 deletions src/crypto/crypto_pbkdf2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,17 @@ Maybe<bool> PBKDF2Traits::AdditionalConfig(
return Just(true);
}

bool PBKDF2Traits::DeriveBits(
Environment* env,
const PBKDF2Config& params,
ByteSource* out) {

bool PBKDF2Traits::DeriveBits(Environment* env,
const PBKDF2Config& params,
ByteSource* out) {
// Both pass and salt may be zero length here.
auto dp = ncrypto::pbkdf2(
params.digest,
ncrypto::Buffer<const char>(params.pass.data<char>(), params.pass.size()),
ncrypto::Buffer<const unsigned char>(params.salt.data<unsigned char>(), params.salt.size()),
params.iterations,
params.length);
params.digest,
ncrypto::Buffer<const char>(params.pass.data<char>(), params.pass.size()),
ncrypto::Buffer<const unsigned char>(params.salt.data<unsigned char>(),
params.salt.size()),
params.iterations,
params.length);

if (!dp) return false;
*out = ByteSource::Allocated(dp.release());
Expand Down
16 changes: 8 additions & 8 deletions src/crypto/crypto_scrypt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ Maybe<bool> ScryptTraits::AdditionalConfig(
params->length = args[offset + 6].As<Int32>()->Value();
CHECK_GE(params->length, 0);

if (!ncrypto::checkScryptParams(params->N, params->r, params->p, params->maxmem)) {
if (!ncrypto::checkScryptParams(
params->N, params->r, params->p, params->maxmem)) {
// Do not use CryptoErrorStore or ThrowCryptoError here in order to maintain
// backward compatibility with ERR_CRYPTO_INVALID_SCRYPT_PARAMS.
uint32_t err = ERR_peek_last_error();
Expand All @@ -118,7 +119,6 @@ bool ScryptTraits::DeriveBits(
Environment* env,
const ScryptConfig& params,
ByteSource* out) {

// If the params.length is zero-length, just return an empty buffer.
// It's useless, yes, but allowed via the API.
if (params.length == 0) {
Expand All @@ -127,13 +127,13 @@ bool ScryptTraits::DeriveBits(
}

auto dp = ncrypto::scrypt(
ncrypto::Buffer<const char> {
.data = params.pass.data<char>(),
.len = params.pass.size(),
ncrypto::Buffer<const char>{
.data = params.pass.data<char>(),
.len = params.pass.size(),
},
ncrypto::Buffer<const unsigned char> {
.data = params.salt.data<unsigned char>(),
.len = params.salt.size(),
ncrypto::Buffer<const unsigned char>{
.data = params.salt.data<unsigned char>(),
.len = params.salt.size(),
},
params.N,
params.r,
Expand Down

0 comments on commit ed97c62

Please sign in to comment.