X-Git-Url: http://git.webkit.org/?p=WebKit-https.git;a=blobdiff_plain;f=Source%2FWebCore%2Fcrypto%2Fgcrypt%2FCryptoAlgorithmPBKDF2GCrypt.cpp;h=5fd9e8e5c9837117e29a45df13e67e002eb2cca7;hp=536200368b9db41b82733edb861f492d65425898;hb=6500fdbaa9e52945493104f6d677427b1dd79916;hpb=9428f05dab4d2093c5c840fc5e3783aa8b8a15be diff --git a/Source/WebCore/crypto/gcrypt/CryptoAlgorithmPBKDF2GCrypt.cpp b/Source/WebCore/crypto/gcrypt/CryptoAlgorithmPBKDF2GCrypt.cpp index 5362003..5fd9e8e 100644 --- a/Source/WebCore/crypto/gcrypt/CryptoAlgorithmPBKDF2GCrypt.cpp +++ b/Source/WebCore/crypto/gcrypt/CryptoAlgorithmPBKDF2GCrypt.cpp @@ -33,39 +33,22 @@ #include "CryptoAlgorithmPbkdf2Params.h" #include "CryptoKeyRaw.h" #include "ExceptionCode.h" +#include "GCryptUtilities.h" #include "ScriptExecutionContext.h" -#include namespace WebCore { static std::optional> gcryptDeriveBits(const Vector& keyData, const Vector& saltData, CryptoAlgorithmIdentifier hashIdentifier, size_t iterations, size_t length) { - int hashAlgorithm; - switch (hashIdentifier) { - case CryptoAlgorithmIdentifier::SHA_1: - hashAlgorithm = GCRY_MD_SHA1; - break; - case CryptoAlgorithmIdentifier::SHA_224: - hashAlgorithm = GCRY_MD_SHA224; - break; - case CryptoAlgorithmIdentifier::SHA_256: - hashAlgorithm = GCRY_MD_SHA256; - break; - case CryptoAlgorithmIdentifier::SHA_384: - hashAlgorithm = GCRY_MD_SHA384; - break; - case CryptoAlgorithmIdentifier::SHA_512: - hashAlgorithm = GCRY_MD_SHA512; - break; - default: + auto hashAlgorithm = digestAlgorithm(hashIdentifier); + if (!hashAlgorithm) return std::nullopt; - } // Length, in bits, is a multiple of 8, as guaranteed by CryptoAlgorithmPBKDF2::deriveBits(). ASSERT(!(length % 8)); Vector result(length / 8); - gcry_error_t error = gcry_kdf_derive(keyData.data(), keyData.size(), GCRY_KDF_PBKDF2, hashAlgorithm, saltData.data(), saltData.size(), iterations, result.size(), result.data()); + gcry_error_t error = gcry_kdf_derive(keyData.data(), keyData.size(), GCRY_KDF_PBKDF2, *hashAlgorithm, saltData.data(), saltData.size(), iterations, result.size(), result.data()); if (error != GPG_ERR_NO_ERROR) { PAL::GCrypt::logError(error); return std::nullopt;