Changeset 214821 in webkit
- Timestamp:
- Apr 3, 2017 11:10:29 AM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r214819 r214821 1 2017-04-03 Zan Dobersek <zdobersek@igalia.com> 2 3 [GCrypt] Implement PBKDF2 support 4 https://bugs.webkit.org/show_bug.cgi?id=170270 5 6 Reviewed by Michael Catanzaro. 7 8 Implement the CryptoAlgorithmPBKDF2::platformDeriveBits() functionality 9 for configurations that use libgcrypt. This is done by leveraging the 10 gcry_kdf_derive() API, using GCRY_KDF_PBKDF2 as the preferred KDF 11 along with the properly deducted SHA algorithm. 12 13 No new tests -- current ones cover this sufficiently, but are not yet 14 enabled due to other missing platform-specific SUBTLE_CRYPTO 15 implementations. 16 17 * crypto/gcrypt/CryptoAlgorithmPBKDF2GCrypt.cpp: 18 (WebCore::gcryptDeriveBits): 19 (WebCore::CryptoAlgorithmPBKDF2::platformDeriveBits): 20 1 21 2017-04-01 Simon Fraser <simon.fraser@apple.com> 2 22 -
trunk/Source/WebCore/crypto/gcrypt/CryptoAlgorithmPBKDF2GCrypt.cpp
r214538 r214821 1 1 /* 2 2 * Copyright (C) 2017 Apple Inc. All rights reserved. 3 * Copyright (C) 2017 Metrological Group B.V. 4 * Copyright (C) 2017 Igalia S.L. 3 5 * 4 6 * Redistribution and use in source and binary forms, with or without … … 29 31 #if ENABLE(SUBTLE_CRYPTO) 30 32 31 #include "NotImplemented.h" 33 #include "CryptoAlgorithmPbkdf2Params.h" 34 #include "CryptoKeyRaw.h" 35 #include "ExceptionCode.h" 36 #include "ScriptExecutionContext.h" 37 #include <pal/crypto/gcrypt/Utilities.h> 32 38 33 39 namespace WebCore { 34 40 35 void CryptoAlgorithmPBKDF2::platformDeriveBits(std::unique_ptr<CryptoAlgorithmParameters>&&, Ref<CryptoKey>&&, size_t, VectorCallback&&, ExceptionCallback&&, ScriptExecutionContext&, WorkQueue&)41 static std::optional<Vector<uint8_t>> gcryptDeriveBits(const Vector<uint8_t>& keyData, const Vector<uint8_t>& saltData, CryptoAlgorithmIdentifier hashIdentifier, size_t iterations, size_t length) 36 42 { 37 notImplemented(); 43 int hashAlgorithm; 44 switch (hashIdentifier) { 45 case CryptoAlgorithmIdentifier::SHA_1: 46 hashAlgorithm = GCRY_MD_SHA1; 47 break; 48 case CryptoAlgorithmIdentifier::SHA_224: 49 hashAlgorithm = GCRY_MD_SHA224; 50 break; 51 case CryptoAlgorithmIdentifier::SHA_256: 52 hashAlgorithm = GCRY_MD_SHA256; 53 break; 54 case CryptoAlgorithmIdentifier::SHA_384: 55 hashAlgorithm = GCRY_MD_SHA384; 56 break; 57 case CryptoAlgorithmIdentifier::SHA_512: 58 hashAlgorithm = GCRY_MD_SHA512; 59 break; 60 default: 61 return std::nullopt; 62 } 63 64 // Length, in bits, is a multiple of 8, as guaranteed by CryptoAlgorithmPBKDF2::deriveBits(). 65 ASSERT(!(length % 8)); 66 67 Vector<uint8_t> result(length / 8); 68 gcry_error_t error = gcry_kdf_derive(keyData.data(), keyData.size(), GCRY_KDF_PBKDF2, hashAlgorithm, saltData.data(), saltData.size(), iterations, result.size(), result.data()); 69 if (error != GPG_ERR_NO_ERROR) { 70 PAL::GCrypt::logError(error); 71 return std::nullopt; 72 } 73 74 return result; 75 } 76 77 void CryptoAlgorithmPBKDF2::platformDeriveBits(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, size_t length, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue) 78 { 79 context.ref(); 80 workQueue.dispatch( 81 [parameters = WTFMove(parameters), key = WTFMove(key), length, callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable { 82 auto& pbkdf2Parameters = downcast<CryptoAlgorithmPbkdf2Params>(*parameters); 83 auto& rawKey = downcast<CryptoKeyRaw>(key.get()); 84 85 auto output = gcryptDeriveBits(rawKey.key(), pbkdf2Parameters.saltVector(), pbkdf2Parameters.hashIdentifier, pbkdf2Parameters.iterations, length); 86 if (!output) { 87 // We should only dereference callbacks after being back to the Document/Worker threads. 88 context.postTask( 89 [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) { 90 exceptionCallback(OperationError); 91 context.deref(); 92 }); 93 return; 94 } 95 96 // We should only dereference callbacks after being back to the Document/Worker threads. 97 context.postTask( 98 [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) { 99 callback(output); 100 context.deref(); 101 }); 102 }); 38 103 } 39 104
Note: See TracChangeset
for help on using the changeset viewer.