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

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: rebase Created 6 years 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..91c7b66890cedbcdfca993e1035365ac52548893 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,35 @@ bool parseAesDerivedKeyParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa
return true;
}
+// The WebCrypto spec hasn't been updated yet to define HKDF. I am assuming a
eroman 2014/12/23 20:58:24 Please add a FIXME or a link to a bug, so that the
nharper 2014/12/23 22:46:59 Done.
+// definition along the lines of:
+//
+// dictionary HkdfParams : Algorithm {
eroman 2014/12/23 20:58:24 How confident are you that this API will match the
nharper 2014/12/23 22:46:59 I'm not confident that this will match the spec. T
eroman 2014/12/23 23:34:29 Changing a required parameter from required -> opt
+// required HashAlgorithmIdentifier hash;
+// required BufferSource salt;
+// required BufferSource info;
+// };
+//
+// It is possible that salt will be changed to be optional.
eroman 2014/12/23 20:58:24 nit: no need for this comment, already covered by
nharper 2014/12/23 22:46:59 Done.
+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 +853,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;

Powered by Google App Engine
This is Rietveld 408576698