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

Unified Diff: Source/modules/crypto/NormalizeAlgorithm.cpp

Issue 707743002: WebCrypto: Add ECDSA algorithm (Blink side). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase onto master Created 6 years, 1 month 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
« no previous file with comments | « Source/bindings/core/v8/SerializedScriptValue.cpp ('k') | Source/modules/crypto/SubtleCrypto.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/crypto/NormalizeAlgorithm.cpp
diff --git a/Source/modules/crypto/NormalizeAlgorithm.cpp b/Source/modules/crypto/NormalizeAlgorithm.cpp
index ec270db78f1da996eda3ba81897b7f4e248b4d2c..f887e71e83bd1a9183d25684d045c80dad5c1893 100644
--- a/Source/modules/crypto/NormalizeAlgorithm.cpp
+++ b/Source/modules/crypto/NormalizeAlgorithm.cpp
@@ -61,6 +61,7 @@ struct AlgorithmNameMapping {
const AlgorithmNameMapping algorithmNameMappings[] = {
{"HMAC", 4, WebCryptoAlgorithmIdHmac},
{"SHA-1", 5, WebCryptoAlgorithmIdSha1},
+ {"ECDSA", 5, WebCryptoAlgorithmIdEcdsa},
{"AES-KW", 6, WebCryptoAlgorithmIdAesKw},
{"SHA-512", 7, WebCryptoAlgorithmIdSha512},
{"SHA-384", 7, WebCryptoAlgorithmIdSha384},
@@ -621,6 +622,84 @@ bool parseRsaPssParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>&
return true;
}
+// Defined by the WebCrypto spec as:
+//
+// dictionary EcdsaParams : Algorithm {
+// required HashAlgorithmIdentifier hash;
+// };
+bool parseEcdsaParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
+{
+ WebCryptoAlgorithm hash;
+ if (!parseHash(raw, hash, context, error))
+ return false;
+
+ params = adoptPtr(new WebCryptoEcdsaParams(hash));
+ return true;
+}
+
+struct CurveNameMapping {
+ const char* const name;
+ WebCryptoNamedCurve value;
+};
+
+const CurveNameMapping curveNameMappings[] = {
+ { "P-256", WebCryptoNamedCurveP256 },
+ { "P-384", WebCryptoNamedCurveP384 },
+ { "P-521", WebCryptoNamedCurveP521 }
+};
+
+// Reminder to update curveNameMappings when adding a new curve.
+COMPILE_ASSERT(WebCryptoNamedCurveLast + 1 == WTF_ARRAY_LENGTH(curveNameMappings), UPDATE_curveNameMappings);
+
+bool parseNamedCurve(const Dictionary& raw, WebCryptoNamedCurve& namedCurve, ErrorContext context, AlgorithmError* error)
+{
+ String namedCurveString;
+ if (!DictionaryHelper::get(raw, "namedCurve", namedCurveString)) {
+ setSyntaxError(context.toString("namedCurve", "Missing or not a string"), error);
+ return false;
+ }
+
+ for (size_t i = 0; i < WTF_ARRAY_LENGTH(curveNameMappings); ++i) {
+ if (curveNameMappings[i].name == namedCurveString) {
+ namedCurve = curveNameMappings[i].value;
+ return true;
+ }
+ }
+
+ setNotSupportedError(context.toString("Unrecognized namedCurve"), error);
+ return false;
+}
+
+// Defined by the WebCrypto spec as:
+//
+// dictionary EcKeyGenParams : Algorithm {
+// required NamedCurve namedCurve;
+// };
+bool parseEcKeyGenParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
+{
+ WebCryptoNamedCurve namedCurve;
+ if (!parseNamedCurve(raw, namedCurve, context, error))
+ return false;
+
+ params = adoptPtr(new WebCryptoEcKeyGenParams(namedCurve));
+ return true;
+}
+
+// Defined by the WebCrypto spec as:
+//
+// dictionary EcKeyImportParams : Algorithm {
+// required NamedCurve namedCurve;
+// };
+bool parseEcKeyImportParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
+{
+ WebCryptoNamedCurve namedCurve;
+ if (!parseNamedCurve(raw, namedCurve, context, error))
+ return false;
+
+ params = adoptPtr(new WebCryptoEcKeyImportParams(namedCurve));
+ return true;
+}
+
bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType type, OwnPtr<WebCryptoAlgorithmParams>& params, ErrorContext& context, AlgorithmError* error)
{
switch (type) {
@@ -656,6 +735,15 @@ bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType ty
case WebCryptoAlgorithmParamsTypeRsaPssParams:
context.add("RsaPssParams");
return parseRsaPssParams(raw, params, context, error);
+ case WebCryptoAlgorithmParamsTypeEcdsaParams:
+ context.add("EcdsaParams");
+ return parseEcdsaParams(raw, params, context, error);
+ case WebCryptoAlgorithmParamsTypeEcKeyGenParams:
+ context.add("EcKeyGenParams");
+ return parseEcKeyGenParams(raw, params, context, error);
+ case WebCryptoAlgorithmParamsTypeEcKeyImportParams:
+ context.add("EcKeyImportParams");
+ return parseEcKeyImportParams(raw, params, context, error);
}
ASSERT_NOT_REACHED();
return false;
« no previous file with comments | « Source/bindings/core/v8/SerializedScriptValue.cpp ('k') | Source/modules/crypto/SubtleCrypto.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698