CryptoAlgorithmRSASSA_PKCS1_v1_5Mac.cpp [plain text]
#include "config.h"
#include "CryptoAlgorithmRSASSA_PKCS1_v1_5.h"
#if ENABLE(SUBTLE_CRYPTO)
#include "CommonCryptoUtilities.h"
#include "CryptoAlgorithmRsaSsaParams.h"
#include "CryptoDigest.h"
#include "CryptoKeyRSA.h"
#include "ExceptionCode.h"
namespace WebCore {
void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformSign(const CryptoAlgorithmRsaSsaParams& parameters, const CryptoKeyRSA& key, const CryptoOperationData& data, VectorCallback callback, VoidCallback failureCallback, ExceptionCode& ec)
{
CCDigestAlgorithm digestAlgorithm;
if (!getCommonCryptoDigestAlgorithm(parameters.hash, digestAlgorithm)) {
ec = NOT_SUPPORTED_ERR;
return;
}
std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(parameters.hash);
if (!digest) {
ec = NOT_SUPPORTED_ERR;
return;
}
digest->addBytes(data.first, data.second);
Vector<uint8_t> digestData = digest->computeHash();
Vector<uint8_t> signature(512);
size_t signatureSize = signature.size();
CCCryptorStatus status = CCRSACryptorSign(key.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.data(), &signatureSize);
if (status) {
failureCallback();
return;
}
signature.resize(signatureSize);
callback(signature);
}
void CryptoAlgorithmRSASSA_PKCS1_v1_5::platformVerify(const CryptoAlgorithmRsaSsaParams& parameters, const CryptoKeyRSA& key, const CryptoOperationData& signature, const CryptoOperationData& data, BoolCallback callback, VoidCallback failureCallback, ExceptionCode& ec)
{
CCDigestAlgorithm digestAlgorithm;
if (!getCommonCryptoDigestAlgorithm(parameters.hash, digestAlgorithm)) {
ec = NOT_SUPPORTED_ERR;
return;
}
std::unique_ptr<CryptoDigest> digest = CryptoDigest::create(parameters.hash);
if (!digest) {
ec = NOT_SUPPORTED_ERR;
return;
}
digest->addBytes(data.first, data.second);
Vector<uint8_t> digestData = digest->computeHash();
CCCryptorStatus status = CCRSACryptorVerify(key.platformKey(), ccPKCS1Padding, digestData.data(), digestData.size(), digestAlgorithm, 0, signature.first, signature.second);
if (!status)
callback(true);
else if (status == kCCNotVerified || status == kCCDecodeError) callback(false);
else
failureCallback();
}
}
#endif // ENABLE(SUBTLE_CRYPTO)