CryptoAlgorithmHKDFMac.cpp [plain text]
#include "config.h"
#include "CryptoAlgorithmHKDF.h"
#if ENABLE(SUBTLE_CRYPTO)
#include "CommonCryptoUtilities.h"
#include "CryptoAlgorithmHkdfParams.h"
#include "CryptoKeyRaw.h"
#include "ExceptionCode.h"
#include "ScriptExecutionContext.h"
namespace WebCore {
void CryptoAlgorithmHKDF::platformDeriveBits(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& baseKey, size_t length, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
{
context.ref();
workQueue.dispatch([parameters = WTFMove(parameters), baseKey = WTFMove(baseKey), length, callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
auto& hkdfParameters = downcast<CryptoAlgorithmHkdfParams>(*parameters);
auto& rawKey = downcast<CryptoKeyRaw>(baseKey.get());
Vector<uint8_t> result(length / 8);
CCDigestAlgorithm digestAlgorithm;
getCommonCryptoDigestAlgorithm(hkdfParameters.hashIdentifier, digestAlgorithm);
if (CCKeyDerivationHMac(kCCKDFAlgorithmHKDF, digestAlgorithm, 0, rawKey.key().data(), rawKey.key().size(), 0, 0, hkdfParameters.infoVector().data(), hkdfParameters.infoVector().size(), 0, 0, hkdfParameters.saltVector().data(), hkdfParameters.saltVector().size(), result.data(), result.size())) {
context.postTask([exceptionCallback = WTFMove(exceptionCallback), callback = WTFMove(callback)](ScriptExecutionContext& context) {
exceptionCallback(OperationError);
context.deref();
});
return;
}
context.postTask([callback = WTFMove(callback), result = WTFMove(result), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {
callback(result);
context.deref();
});
});
}
}
#endif // ENABLE(SUBTLE_CRYPTO)