Skip to content

Commit

Permalink
src: remove ERR prefix in crypto status enums
Browse files Browse the repository at this point in the history
This commit removes the ERR prefix of the remaining status enums in
crypto so they are consistent with Commit
923f76d ("src: remove ERR prefix in
WebCryptoKeyExportStatus").

PR-URL: #35867
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
  • Loading branch information
danbev authored and danielleadams committed Nov 9, 2020
1 parent 6968b0f commit 1b277d9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 47 deletions.
44 changes: 22 additions & 22 deletions src/crypto/crypto_aes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace {
// Implements general AES encryption and decryption for CBC
// The key_data must be a secret key.
// On success, this function sets out to a new AllocatedBuffer
// instance containing the results and returns WebCryptoCipherStatus::ERR_OK.
// instance containing the results and returns WebCryptoCipherStatus::OK.
WebCryptoCipherStatus AES_Cipher(
Environment* env,
KeyObjectData* key_data,
Expand Down Expand Up @@ -59,15 +59,15 @@ WebCryptoCipherStatus AES_Cipher(
nullptr,
encrypt)) {
// Cipher init failed
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}

if (mode == EVP_CIPH_GCM_MODE && !EVP_CIPHER_CTX_ctrl(
ctx.get(),
EVP_CTRL_AEAD_SET_IVLEN,
params.iv.size(),
nullptr)) {
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}

if (!EVP_CIPHER_CTX_set_key_length(
Expand All @@ -80,7 +80,7 @@ WebCryptoCipherStatus AES_Cipher(
reinterpret_cast<const unsigned char*>(key_data->GetSymmetricKey()),
params.iv.data<unsigned char>(),
encrypt)) {
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}

size_t tag_len = 0;
Expand All @@ -95,7 +95,7 @@ WebCryptoCipherStatus AES_Cipher(
EVP_CTRL_AEAD_SET_TAG,
params.tag.size(),
const_cast<char*>(params.tag.get()))) {
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}
break;
case kWebCryptoCipherEncrypt:
Expand Down Expand Up @@ -123,7 +123,7 @@ WebCryptoCipherStatus AES_Cipher(
&out_len,
params.additional_data.data<unsigned char>(),
params.additional_data.size())) {
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}

char* data = MallocOpenSSL<char>(buf_len);
Expand All @@ -136,15 +136,15 @@ WebCryptoCipherStatus AES_Cipher(
&out_len,
in.data<unsigned char>(),
in.size())) {
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}

total += out_len;
CHECK_LE(out_len, buf_len);
ptr += out_len;
out_len = EVP_CIPHER_CTX_block_size(ctx.get());
if (!EVP_CipherFinal_ex(ctx.get(), ptr, &out_len)) {
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}
total += out_len;

Expand All @@ -153,15 +153,15 @@ WebCryptoCipherStatus AES_Cipher(
if (cipher_mode == kWebCryptoCipherEncrypt && mode == EVP_CIPH_GCM_MODE) {
data += out_len;
if (!EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_AEAD_GET_TAG, tag_len, ptr))
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
total += tag_len;
}

// It's possible that we haven't used the full allocated space. Size down.
buf.Resize(total);
*out = std::move(buf);

return WebCryptoCipherStatus::ERR_OK;
return WebCryptoCipherStatus::OK;
}

// The AES_CTR implementation here takes it's inspiration from the chromium
Expand Down Expand Up @@ -232,7 +232,7 @@ WebCryptoCipherStatus AES_CTR_Cipher2(
counter,
encrypt)) {
// Cipher init failed
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}

int out_len = 0;
Expand All @@ -243,17 +243,17 @@ WebCryptoCipherStatus AES_CTR_Cipher2(
&out_len,
in.data<unsigned char>(),
in.size())) {
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}

if (!EVP_CipherFinal_ex(ctx.get(), out + out_len, &final_len))
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;

out_len += final_len;
if (static_cast<unsigned>(out_len) != in.size())
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;

return WebCryptoCipherStatus::ERR_OK;
return WebCryptoCipherStatus::OK;
}

WebCryptoCipherStatus AES_CTR_Cipher(
Expand All @@ -265,25 +265,25 @@ WebCryptoCipherStatus AES_CTR_Cipher(
ByteSource* out) {
BignumPointer num_counters(BN_new());
if (!BN_lshift(num_counters.get(), BN_value_one(), params.length))
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;

BignumPointer current_counter = GetCounter(params);

BignumPointer num_output(BN_new());

if (!BN_set_word(num_output.get(), CeilDiv(in.size(), kAesBlockSize)))
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;

// Just like in chromium's implementation, if the counter will
// be incremented more than there are counter values, we fail.
if (BN_cmp(num_output.get(), num_counters.get()) > 0)
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;

BignumPointer remaining_until_reset(BN_new());
if (!BN_sub(remaining_until_reset.get(),
num_counters.get(),
current_counter.get())) {
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}

// Output size is identical to the input size
Expand All @@ -302,7 +302,7 @@ WebCryptoCipherStatus AES_CTR_Cipher(
in,
params.iv.data<unsigned char>(),
ptr);
if (status == WebCryptoCipherStatus::ERR_OK)
if (status == WebCryptoCipherStatus::OK)
*out = std::move(buf);
return status;
}
Expand All @@ -319,7 +319,7 @@ WebCryptoCipherStatus AES_CTR_Cipher(
params.iv.data<unsigned char>(),
ptr);

if (status != WebCryptoCipherStatus::ERR_OK)
if (status != WebCryptoCipherStatus::OK)
return status;

// Wrap the counter around to zero
Expand All @@ -336,7 +336,7 @@ WebCryptoCipherStatus AES_CTR_Cipher(
new_counter_block.data(),
ptr + input_size_part1);

if (status == WebCryptoCipherStatus::ERR_OK)
if (status == WebCryptoCipherStatus::OK)
*out = std::move(buf);

return status;
Expand Down
12 changes: 6 additions & 6 deletions src/crypto/crypto_cipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ enum WebCryptoCipherMode {
};

enum class WebCryptoCipherStatus {
ERR_OK,
ERR_INVALID_KEY_TYPE,
ERR_FAILED
OK,
INVALID_KEY_TYPE,
FAILED
};

// CipherJob is a base implementation class for implementations of
Expand Down Expand Up @@ -222,13 +222,13 @@ class CipherJob final : public CryptoJob<CipherTraits> {
*CryptoJob<CipherTraits>::params(),
in_,
&out_)) {
case WebCryptoCipherStatus::ERR_OK:
case WebCryptoCipherStatus::OK:
// Success!
break;
case WebCryptoCipherStatus::ERR_INVALID_KEY_TYPE:
case WebCryptoCipherStatus::INVALID_KEY_TYPE:
// Fall through
// TODO(@jasnell): Separate error for this
case WebCryptoCipherStatus::ERR_FAILED: {
case WebCryptoCipherStatus::FAILED: {
CryptoErrorVector* errors = CryptoJob<CipherTraits>::errors();
errors->Capture();
if (errors->empty())
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto_keygen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ KeyGenJobStatus SecretKeyGenTraits::DoKeyGen(
CHECK_LE(params->length, INT_MAX);
params->out = MallocOpenSSL<char>(params->length);
EntropySource(reinterpret_cast<unsigned char*>(params->out), params->length);
return KeyGenJobStatus::ERR_OK;
return KeyGenJobStatus::OK;
}

Maybe<bool> SecretKeyGenTraits::EncodeKey(
Expand Down
20 changes: 10 additions & 10 deletions src/crypto/crypto_keygen.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ void Initialize(Environment* env, v8::Local<v8::Object> target);
} // namespace Keygen

enum class KeyGenJobStatus {
ERR_OK,
ERR_FAILED
OK,
FAILED
};

// A Base CryptoJob for generating secret keys or key pairs.
Expand Down Expand Up @@ -77,11 +77,11 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> {
AdditionalParams* params = CryptoJob<KeyGenTraits>::params();

switch (KeyGenTraits::DoKeyGen(AsyncWrap::env(), params)) {
case KeyGenJobStatus::ERR_OK:
status_ = KeyGenJobStatus::ERR_OK;
case KeyGenJobStatus::OK:
status_ = KeyGenJobStatus::OK;
// Success!
break;
case KeyGenJobStatus::ERR_FAILED: {
case KeyGenJobStatus::FAILED: {
CryptoErrorVector* errors = CryptoJob<KeyGenTraits>::errors();
errors->Capture();
if (errors->empty())
Expand All @@ -96,7 +96,7 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> {
Environment* env = AsyncWrap::env();
CryptoErrorVector* errors = CryptoJob<KeyGenTraits>::errors();
AdditionalParams* params = CryptoJob<KeyGenTraits>::params();
if (status_ == KeyGenJobStatus::ERR_OK &&
if (status_ == KeyGenJobStatus::OK &&
LIKELY(!KeyGenTraits::EncodeKey(env, params, result).IsNothing())) {
*err = Undefined(env->isolate());
return v8::Just(true);
Expand All @@ -112,7 +112,7 @@ class KeyGenJob final : public CryptoJob<KeyGenTraits> {
SET_SELF_SIZE(KeyGenJob);

private:
KeyGenJobStatus status_ = KeyGenJobStatus::ERR_FAILED;
KeyGenJobStatus status_ = KeyGenJobStatus::FAILED;
};

// A Base KeyGenTraits for Key Pair generation algorithms.
Expand Down Expand Up @@ -162,15 +162,15 @@ struct KeyPairGenTraits final {
AdditionalParameters* params) {
EVPKeyCtxPointer ctx = KeyPairAlgorithmTraits::Setup(params);
if (!ctx || EVP_PKEY_keygen_init(ctx.get()) <= 0)
return KeyGenJobStatus::ERR_FAILED;
return KeyGenJobStatus::FAILED;

// Generate the key
EVP_PKEY* pkey = nullptr;
if (!EVP_PKEY_keygen(ctx.get(), &pkey))
return KeyGenJobStatus::ERR_FAILED;
return KeyGenJobStatus::FAILED;

params->key = ManagedEVPPKey(EVPKeyPointer(pkey));
return KeyGenJobStatus::ERR_OK;
return KeyGenJobStatus::OK;
}

static v8::Maybe<bool> EncodeKey(
Expand Down
16 changes: 8 additions & 8 deletions src/crypto/crypto_rsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,16 @@ WebCryptoCipherStatus RSA_Cipher(
EVP_PKEY_CTX_new(key_data->GetAsymmetricKey().get(), nullptr));

if (!ctx || init(ctx.get()) <= 0)
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;

if (EVP_PKEY_CTX_set_rsa_padding(ctx.get(), params.padding) <= 0) {
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}

if (params.digest != nullptr &&
(EVP_PKEY_CTX_set_rsa_oaep_md(ctx.get(), params.digest) <= 0 ||
EVP_PKEY_CTX_set_rsa_mgf1_md(ctx.get(), params.digest) <= 0)) {
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}

size_t label_len = params.label.size();
Expand All @@ -214,7 +214,7 @@ WebCryptoCipherStatus RSA_Cipher(
CHECK_NOT_NULL(label);
if (EVP_PKEY_CTX_set0_rsa_oaep_label(ctx.get(), label, label_len) <= 0) {
OPENSSL_free(label);
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}
}

Expand All @@ -225,7 +225,7 @@ WebCryptoCipherStatus RSA_Cipher(
&out_len,
in.data<unsigned char>(),
in.size()) <= 0) {
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}

char* data = MallocOpenSSL<char>(out_len);
Expand All @@ -238,13 +238,13 @@ WebCryptoCipherStatus RSA_Cipher(
&out_len,
in.data<unsigned char>(),
in.size()) <= 0) {
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}

buf.Resize(out_len);

*out = std::move(buf);
return WebCryptoCipherStatus::ERR_OK;
return WebCryptoCipherStatus::OK;
}
} // namespace

Expand Down Expand Up @@ -356,7 +356,7 @@ WebCryptoCipherStatus RSACipherTraits::DoCipher(
return RSA_Cipher<EVP_PKEY_decrypt_init, EVP_PKEY_decrypt>(
env, key_data.get(), params, in, out);
}
return WebCryptoCipherStatus::ERR_FAILED;
return WebCryptoCipherStatus::FAILED;
}

Maybe<bool> ExportJWKRsaKey(
Expand Down

0 comments on commit 1b277d9

Please sign in to comment.