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

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

Issue 820523003: [webcrypto] Implement PBKDF2 (blink-side) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added Layout tests 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..f518be887e6ddf4ef0bdc23b1e5b5ac30424e827 100644
--- a/Source/modules/crypto/NormalizeAlgorithm.cpp
+++ b/Source/modules/crypto/NormalizeAlgorithm.cpp
@@ -70,6 +70,7 @@ const AlgorithmNameMapping algorithmNameMappings[] = {
{"ECDH", 4, WebCryptoAlgorithmIdEcdh},
{"SHA-1", 5, WebCryptoAlgorithmIdSha1},
{"ECDSA", 5, WebCryptoAlgorithmIdEcdsa},
+ {"PBKDF2", 6, WebCryptoAlgorithmIdPbkdf2},
{"AES-KW", 6, WebCryptoAlgorithmIdAesKw},
{"SHA-512", 7, WebCryptoAlgorithmIdSha512},
{"SHA-384", 7, WebCryptoAlgorithmIdSha384},
@@ -757,6 +758,29 @@ bool parseEcdhKeyDeriveParams(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmPa
params = adoptPtr(new WebCryptoEcdhKeyDeriveParams(cryptoKey->key()));
return true;
}
+// dictionary Pbkdf2Params : Algorithm {
+// required BufferSource salt;
+// [EnforceRange] required unsigned long iterations;
+// required HashAlgorithmIdentifier hash;
+// };
+bool parsePbkdf2Params(const Dictionary& raw, OwnPtr<WebCryptoAlgorithmParams>& params, const ErrorContext& context, AlgorithmError* error)
+{
+ BufferSource saltBufferSource;
+ if (!getBufferSource(raw, "salt", saltBufferSource, context, error))
+ return false;
+
+ DOMArrayPiece salt(saltBufferSource);
+
+ uint32_t iterations;
+ if (!getUint32(raw, "iterations", iterations, context, error))
+ return false;
+
+ WebCryptoAlgorithm hash;
+ if (!parseHash(raw, hash, context, error))
+ return false;
+ params = adoptPtr(new WebCryptoPbkdf2Params(hash, salt.bytes(), salt.byteLength(), iterations));
+ return true;
+}
// Defined by the WebCrypto spec as:
//
@@ -823,6 +847,9 @@ bool parseAlgorithmParams(const Dictionary& raw, WebCryptoAlgorithmParamsType ty
case WebCryptoAlgorithmParamsTypeAesDerivedKeyParams:
context.add("AesDerivedKeyParams");
return parseAesDerivedKeyParams(raw, params, context, error);
+ case WebCryptoAlgorithmParamsTypePbkdf2Params:
+ context.add("Pbkdf2Params");
+ return parsePbkdf2Params(raw, params, context, error);
}
ASSERT_NOT_REACHED();
return false;

Powered by Google App Engine
This is Rietveld 408576698