RTCRtpSFrameTransformerCocoa.cpp [plain text]
#include "config.h"
#include "RTCRtpSFrameTransformer.h"
#if ENABLE(WEB_RTC)
#include "CryptoUtilitiesCocoa.h"
#include <CommonCrypto/CommonCrypto.h>
namespace WebCore {
ExceptionOr<Vector<uint8_t>> RTCRtpSFrameTransformer::computeSaltKey(const Vector<uint8_t>& rawKey)
{
uint8_t usage[] = "SFrameSaltKey";
return deriveHDKFSHA256Bits(rawKey.data(), 16, rawKey.data() + 16, rawKey.size() - 16, usage, sizeof(usage) - 1, 128);
}
ExceptionOr<Vector<uint8_t>> RTCRtpSFrameTransformer::computeAuthenticationKey(const Vector<uint8_t>& rawKey)
{
uint8_t usage[] = "SFrameAuthenticationKey";
return deriveHDKFSHA256Bits(rawKey.data(), 16, rawKey.data() + 16, rawKey.size() - 16, usage, sizeof(usage) - 1, 256);
}
ExceptionOr<Vector<uint8_t>> RTCRtpSFrameTransformer::computeEncryptionKey(const Vector<uint8_t>& rawKey)
{
uint8_t usage[] = "SFrameEncryptionKey";
return deriveHDKFSHA256Bits(rawKey.data(), 16, rawKey.data() + 16, rawKey.size() - 16, usage, sizeof(usage) - 1, 128);
}
ExceptionOr<Vector<uint8_t>> RTCRtpSFrameTransformer::decryptData(const uint8_t* data, size_t size, const Vector<uint8_t>& iv, const Vector<uint8_t>& key)
{
return transformAES_CTR(kCCDecrypt, iv, iv.size(), key, data, size);
}
ExceptionOr<Vector<uint8_t>> RTCRtpSFrameTransformer::encryptData(const uint8_t* data, size_t size, const Vector<uint8_t>& iv, const Vector<uint8_t>& key)
{
return transformAES_CTR(kCCEncrypt, iv, iv.size(), key, data, size);
}
Vector<uint8_t> RTCRtpSFrameTransformer::computeEncryptedDataSignature(const uint8_t* data, size_t size, const Vector<uint8_t>& key)
{
return calculateSHA256Signature(key, data, size);
}
void RTCRtpSFrameTransformer::updateAuthenticationSize()
{
if (m_authenticationSize > CC_SHA256_DIGEST_LENGTH)
m_authenticationSize = CC_SHA256_DIGEST_LENGTH;
}
}
#endif // ENABLE(WEB_RTC)