// FIXME: We should change data to Vector<uint8_t> type once WebKitSubtleCrypto is deprecated. // https://bugs.webkit.org/show_bug.cgi?id=164939 static ExceptionOr<Vector<uint8_t>> decryptRSA_OAEP(CryptoAlgorithmIdentifier hash, const Vector<uint8_t>& label, const PlatformRSAKey key, size_t keyLength, const uint8_t* data, size_t dataLength) { CCDigestAlgorithm digestAlgorithm; if (!getCommonCryptoDigestAlgorithm(hash, digestAlgorithm)) return Exception { OperationError }; Vector<uint8_t> plainText(keyLength / 8); // Per Step 1.b of https://tools.ietf.org/html/rfc3447#section-7.1.1 size_t plainTextLength = plainText.size(); if (CCRSACryptorDecrypt(key, ccOAEPPadding, data, dataLength, plainText.data(), &plainTextLength, label.data(), label.size(), digestAlgorithm)) return Exception { OperationError }; plainText.resize(plainTextLength); return WTFMove(plainText); }
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); }