CryptoAlgorithmRSA_OAEPMac.cpp [plain text]
#include "config.h"
#include "CryptoAlgorithmRSA_OAEP.h"
#if ENABLE(SUBTLE_CRYPTO)
#include "CommonCryptoUtilities.h"
#include "CryptoAlgorithmRsaOaepParams.h"
#include "CryptoKeyRSA.h"
#include "ExceptionCode.h"
namespace WebCore {
void CryptoAlgorithmRSA_OAEP::platformEncrypt(const CryptoAlgorithmRsaOaepParams& 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;
}
Vector<uint8_t> cipherText(1024);
size_t cipherTextLength = cipherText.size();
ASSERT(parameters.hasLabel || parameters.label.isEmpty());
CCCryptorStatus status = CCRSACryptorEncrypt(key.platformKey(), ccOAEPPadding, data.first, data.second, cipherText.data(), &cipherTextLength, parameters.label.data(), parameters.label.size(), digestAlgorithm);
if (status) {
failureCallback();
return;
}
cipherText.resize(cipherTextLength);
callback(cipherText);
}
void CryptoAlgorithmRSA_OAEP::platformDecrypt(const CryptoAlgorithmRsaOaepParams& 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;
}
Vector<uint8_t> plainText(1024);
size_t plainTextLength = plainText.size();
CCCryptorStatus status = CCRSACryptorDecrypt(key.platformKey(), ccOAEPPadding, data.first, data.second, plainText.data(), &plainTextLength, parameters.label.data(), parameters.label.size(), digestAlgorithm);
if (status) {
failureCallback();
return;
}
plainText.resize(plainTextLength);
callback(plainText);
}
}
#endif // ENABLE(SUBTLE_CRYPTO)