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

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

Issue 789733009: Implement HKDF for WebCrypto (blink-side) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: move ASSERT(), add break Created 5 years, 11 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: Source/modules/crypto/NormalizeAlgorithm.cpp
diff --git a/Source/modules/crypto/NormalizeAlgorithm.cpp b/Source/modules/crypto/NormalizeAlgorithm.cpp
index 823989554d1830bcbaa42b07280068057277d59b..cd540a563040a4e438fedb95f935847395295ee2 100644
--- a/Source/modules/crypto/NormalizeAlgorithm.cpp
+++ b/Source/modules/crypto/NormalizeAlgorithm.cpp
@@ -67,6 +67,7 @@ struct AlgorithmNameMapping {
// Also all names must be upper case ASCII.
const AlgorithmNameMapping algorithmNameMappings[] = {
{"HMAC", 4, WebCryptoAlgorithmIdHmac},
+ {"HKDF", 4, WebCryptoAlgorithmIdHkdf},
{"ECDH", 4, WebCryptoAlgorithmIdEcdh},
{"SHA-1", 5, WebCryptoAlgorithmIdSha1},
{"ECDSA", 5, WebCryptoAlgorithmIdEcdsa},
@@ -773,6 +774,37 @@ bool parseAesDerivedKeyParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa
return true;
}
+// FIXME: once the spec has been updated, check that the implementation is
+// still correct and update this comment. http://crbug.com/399095
+//
+// The WebCrypto spec hasn't been updated yet to define HKDF
+// (https://www.w3.org/Bugs/Public/show_bug.cgi?id=27425). The assumed
+// parameters are:
+//
+// dictionary HkdfParams : Algorithm {
+// required HashAlgorithmIdentifier hash;
+// required BufferSource salt;
+// required BufferSource info;
+// };
+bool parseHkdfParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
+{
+ WebCryptoAlgorithm hash;
+ if (!parseHash(raw, hash, context, error))
+ return false;
+ BufferSource saltBufferSource;
+ if (!getBufferSource(raw, "salt", saltBufferSource, context, error))
+ return false;
+ BufferSource infoBufferSource;
+ if (!getBufferSource(raw, "info", infoBufferSource, context, error))
+ return false;
+
+ DOMArrayPiece salt(saltBufferSource);
+ DOMArrayPiece info(infoBufferSource);
+
+ params = adoptPtr(new WebCryptoHkdfParams(hash, salt.bytes(), salt.byteLength(), info.bytes(), info.byteLength()));
+ return true;
+}
+
bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType type, OwnPtr<WebCryptoAlgorithmParams>& params, ErrorContext& context, AlgorithmError* error)
{
switch (type) {
@@ -823,6 +855,9 @@ bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType ty
case WebCryptoAlgorithmParamsTypeAesDerivedKeyParams:
context.add("AesDerivedKeyParams");
return parseAesDerivedKeyParams(raw, params, context, error);
+ case WebCryptoAlgorithmParamsTypeHkdfParams:
+ context.add("HkdfParams");
+ return parseHkdfParams(raw, params, context, error);
}
ASSERT_NOT_REACHED();
return false;
« no previous file with comments | « Source/bindings/modules/v8/ScriptValueSerializerForModules.cpp ('k') | Source/platform/exported/WebCryptoAlgorithm.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698