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

Unified Diff: components/webcrypto/fuzzer_support.cc

Issue 2162303002: [webcrypto] Add support for import/export of "raw" formatted EC keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usage_order
Patch Set: address feedback Created 4 years, 4 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/fuzzer_support.cc
diff --git a/components/webcrypto/fuzzer_support.cc b/components/webcrypto/fuzzer_support.cc
index 6b1d49596cf11225a9554288e3d1070af348a040..599813f8ce9f7decebf463dead027a473d7ea9b2 100644
--- a/components/webcrypto/fuzzer_support.cc
+++ b/components/webcrypto/fuzzer_support.cc
@@ -95,6 +95,52 @@ void ImportEcKeyFromDerFuzzData(const uint8_t* data,
Status::ErrorCreateKeyBadUsages().error_details());
}
+void ImportEcKeyFromRawFuzzData(const uint8_t* data, size_t size) {
+ EnsureInitialized();
+
+ // There are 3 possible EC named curves. Consume the first byte to decide on
+ // the curve.
+ uint8_t curve_index = 0;
+ if (size > 0) {
+ curve_index = data[0];
+ data++;
+ size--;
+ }
+
+ blink::WebCryptoNamedCurve curve;
+
+ switch (curve_index % 3) {
+ case 0:
+ curve = blink::WebCryptoNamedCurveP256;
+ break;
+ case 1:
+ curve = blink::WebCryptoNamedCurveP384;
+ break;
+ default:
+ curve = blink::WebCryptoNamedCurveP521;
+ break;
+ }
+
+ // Always use ECDSA as the algorithm. Shouldn't make an difference for import.
+ blink::WebCryptoAlgorithmId algorithm_id = blink::WebCryptoAlgorithmIdEcdsa;
+
+ // Use key usages that are compatible with the chosen algorithm and key type.
+ blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageVerify;
+
+ blink::WebCryptoKey key;
+ webcrypto::Status status = webcrypto::ImportKey(
+ blink::WebCryptoKeyFormatRaw,
+ webcrypto::CryptoData(data, base::checked_cast<uint32_t>(size)),
+ CreateEcImportAlgorithm(algorithm_id, curve), true, usages, &key);
+
+ // These errors imply a bad setup of parameters, and means ImportKey() may not
+ // be testing the actual parsing.
+ DCHECK_NE(status.error_details(),
+ Status::ErrorUnsupportedImportKeyFormat().error_details());
+ DCHECK_NE(status.error_details(),
+ Status::ErrorCreateKeyBadUsages().error_details());
+}
+
void ImportRsaKeyFromDerFuzzData(const uint8_t* data,
size_t size,
blink::WebCryptoKeyFormat format) {
« no previous file with comments | « components/webcrypto/fuzzer_support.h ('k') | third_party/WebKit/LayoutTests/crypto/subtle/ecdh/import-export-raw.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698