Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(525)

Unified Diff: components/webcrypto/openssl/aes_algorithm_openssl.cc

Issue 1304063015: [refactor] Rename the webcrypto/openssl and webcrypto/test directories. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@jwk_refactor
Patch Set: fix filename in gn build Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/webcrypto/openssl/aes_algorithm_openssl.cc
diff --git a/components/webcrypto/openssl/aes_algorithm_openssl.cc b/components/webcrypto/openssl/aes_algorithm_openssl.cc
deleted file mode 100644
index 0a47286c2323b7c8cabda03ccc66d459a2ddeefc..0000000000000000000000000000000000000000
--- a/components/webcrypto/openssl/aes_algorithm_openssl.cc
+++ /dev/null
@@ -1,177 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "components/webcrypto/openssl/aes_algorithm_openssl.h"
-
-#include "base/logging.h"
-#include "components/webcrypto/crypto_data.h"
-#include "components/webcrypto/jwk.h"
-#include "components/webcrypto/openssl/key_openssl.h"
-#include "components/webcrypto/openssl/util_openssl.h"
-#include "components/webcrypto/status.h"
-#include "components/webcrypto/webcrypto_util.h"
-#include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
-
-namespace webcrypto {
-
-namespace {
-
-// Creates an AES algorithm name for the given key size (in bytes). For
-// instance "A128CBC" is the result of suffix="CBC", keylen_bytes=16.
-std::string MakeJwkAesAlgorithmName(const std::string& suffix,
- size_t keylen_bytes) {
- if (keylen_bytes == 16)
- return std::string("A128") + suffix;
- if (keylen_bytes == 24)
- return std::string("A192") + suffix;
- if (keylen_bytes == 32)
- return std::string("A256") + suffix;
- return std::string();
-}
-
-} // namespace
-
-AesAlgorithm::AesAlgorithm(blink::WebCryptoKeyUsageMask all_key_usages,
- const std::string& jwk_suffix)
- : all_key_usages_(all_key_usages), jwk_suffix_(jwk_suffix) {
-}
-
-AesAlgorithm::AesAlgorithm(const std::string& jwk_suffix)
- : all_key_usages_(blink::WebCryptoKeyUsageEncrypt |
- blink::WebCryptoKeyUsageDecrypt |
- blink::WebCryptoKeyUsageWrapKey |
- blink::WebCryptoKeyUsageUnwrapKey),
- jwk_suffix_(jwk_suffix) {
-}
-
-Status AesAlgorithm::GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
- bool extractable,
- blink::WebCryptoKeyUsageMask usages,
- GenerateKeyResult* result) const {
- Status status = CheckKeyCreationUsages(all_key_usages_, usages, false);
- if (status.IsError())
- return status;
-
- unsigned int keylen_bits;
- status = GetAesKeyGenLengthInBits(algorithm.aesKeyGenParams(), &keylen_bits);
- if (status.IsError())
- return status;
-
- return GenerateWebCryptoSecretKey(
- blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits),
- extractable, usages, keylen_bits, result);
-}
-
-Status AesAlgorithm::VerifyKeyUsagesBeforeImportKey(
- blink::WebCryptoKeyFormat format,
- blink::WebCryptoKeyUsageMask usages) const {
- switch (format) {
- case blink::WebCryptoKeyFormatRaw:
- case blink::WebCryptoKeyFormatJwk:
- return CheckKeyCreationUsages(all_key_usages_, usages, false);
- default:
- return Status::ErrorUnsupportedImportKeyFormat();
- }
-}
-
-Status AesAlgorithm::ImportKeyRaw(const CryptoData& key_data,
- const blink::WebCryptoAlgorithm& algorithm,
- bool extractable,
- blink::WebCryptoKeyUsageMask usages,
- blink::WebCryptoKey* key) const {
- const unsigned int keylen_bytes = key_data.byte_length();
- Status status = VerifyAesKeyLengthForImport(keylen_bytes);
- if (status.IsError())
- return status;
-
- // No possibility of overflow.
- unsigned int keylen_bits = keylen_bytes * 8;
-
- return CreateWebCryptoSecretKey(
- key_data,
- blink::WebCryptoKeyAlgorithm::createAes(algorithm.id(), keylen_bits),
- extractable, usages, key);
-}
-
-Status AesAlgorithm::ImportKeyJwk(const CryptoData& key_data,
- const blink::WebCryptoAlgorithm& algorithm,
- bool extractable,
- blink::WebCryptoKeyUsageMask usages,
- blink::WebCryptoKey* key) const {
- std::vector<uint8_t> raw_data;
- JwkReader jwk;
- Status status = ReadSecretKeyNoExpectedAlg(key_data, extractable, usages,
- &raw_data, &jwk);
- if (status.IsError())
- return status;
-
- bool has_jwk_alg;
- std::string jwk_alg;
- status = jwk.GetAlg(&jwk_alg, &has_jwk_alg);
- if (status.IsError())
- return status;
-
- if (has_jwk_alg) {
- std::string expected_algorithm_name =
- MakeJwkAesAlgorithmName(jwk_suffix_, raw_data.size());
-
- if (jwk_alg != expected_algorithm_name) {
- // Give a different error message if the key length was wrong.
- if (jwk_alg == MakeJwkAesAlgorithmName(jwk_suffix_, 16) ||
- jwk_alg == MakeJwkAesAlgorithmName(jwk_suffix_, 24) ||
- jwk_alg == MakeJwkAesAlgorithmName(jwk_suffix_, 32)) {
- return Status::ErrorJwkIncorrectKeyLength();
- }
- return Status::ErrorJwkAlgorithmInconsistent();
- }
- }
-
- return ImportKeyRaw(CryptoData(raw_data), algorithm, extractable, usages,
- key);
-}
-
-Status AesAlgorithm::ExportKeyRaw(const blink::WebCryptoKey& key,
- std::vector<uint8_t>* buffer) const {
- *buffer = SymKeyOpenSsl::Cast(key)->raw_key_data();
- return Status::Success();
-}
-
-Status AesAlgorithm::ExportKeyJwk(const blink::WebCryptoKey& key,
- std::vector<uint8_t>* buffer) const {
- const std::vector<uint8_t>& raw_data =
- SymKeyOpenSsl::Cast(key)->raw_key_data();
-
- WriteSecretKeyJwk(CryptoData(raw_data),
- MakeJwkAesAlgorithmName(jwk_suffix_, raw_data.size()),
- key.extractable(), key.usages(), buffer);
-
- return Status::Success();
-}
-
-Status AesAlgorithm::SerializeKeyForClone(
- const blink::WebCryptoKey& key,
- blink::WebVector<uint8_t>* key_data) const {
- key_data->assign(SymKeyOpenSsl::Cast(key)->serialized_key_data());
- return Status::Success();
-}
-
-Status AesAlgorithm::DeserializeKeyForClone(
- const blink::WebCryptoKeyAlgorithm& algorithm,
- blink::WebCryptoKeyType type,
- bool extractable,
- blink::WebCryptoKeyUsageMask usages,
- const CryptoData& key_data,
- blink::WebCryptoKey* key) const {
- return ImportKeyRaw(key_data, CreateAlgorithm(algorithm.id()), extractable,
- usages, key);
-}
-
-Status AesAlgorithm::GetKeyLength(
- const blink::WebCryptoAlgorithm& key_length_algorithm,
- bool* has_length_bits,
- unsigned int* length_bits) const {
- return GetAesKeyLength(key_length_algorithm, has_length_bits, length_bits);
-}
-
-} // namespace webcrypto
« no previous file with comments | « components/webcrypto/openssl/aes_algorithm_openssl.h ('k') | components/webcrypto/openssl/aes_cbc_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698