// 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>> encryptRSA_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> cipherText(keyLength / 8); // Per Step 3.c of https://tools.ietf.org/html/rfc3447#section-7.1.1 size_t cipherTextLength = cipherText.size(); if (CCRSACryptorEncrypt(key, ccOAEPPadding, data, dataLength, cipherText.data(), &cipherTextLength, label.data(), label.size(), digestAlgorithm)) return Exception { OperationError }; return WTFMove(cipherText); }
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); }