Merge from Widevine repo of http://go/wvgerrit/96783 This CL updates the reference code, unit tests, and adapter to use the new v16 function OEMCrypto_LoadDRMPrivateKey. This is just an API change to allow ECC support in the future. The reference code does not yet support ECC certificates, and the CDM code assumes that all certificates have an RSA key. Bug: 152558018 Test: unit tests on taimen and w/v16 mod mock. Change-Id: I0793b416513b81b3d74849f0b58dbdc91f075ac6
51 lines
1.9 KiB
C++
51 lines
1.9 KiB
C++
//
|
|
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine Master
|
|
// License Agreement.
|
|
//
|
|
|
|
//#define LOG_NDEBUG 0
|
|
#define LOG_TAG "WVCdm"
|
|
#include <log/log.h>
|
|
|
|
#include "WVGenericCryptoInterface.h"
|
|
|
|
#include "wv_cdm_constants.h"
|
|
|
|
namespace wvdrm {
|
|
|
|
using namespace std;
|
|
using namespace wvcdm;
|
|
|
|
OEMCryptoResult WVGenericCryptoInterface::signRSA(const uint8_t* wrapped_rsa_key,
|
|
size_t wrapped_rsa_key_length,
|
|
const uint8_t* message,
|
|
size_t message_length,
|
|
std::vector<uint8_t>& signature,
|
|
RSA_Padding_Scheme padding_scheme) {
|
|
OEMCrypto_SESSION session;
|
|
OEMCryptoResult sts = OEMCrypto_OpenSession(&session);
|
|
if (sts != OEMCrypto_SUCCESS) return sts;
|
|
sts = OEMCrypto_LoadDRMPrivateKey(session, OEMCrypto_RSA_Private_Key,
|
|
wrapped_rsa_key, wrapped_rsa_key_length);
|
|
if (sts == OEMCrypto_SUCCESS) {
|
|
size_t signatureSize = 0;
|
|
sts = OEMCrypto_GenerateRSASignature(session, message, message_length,
|
|
NULL, &signatureSize,
|
|
padding_scheme);
|
|
if (sts == OEMCrypto_SUCCESS) {
|
|
// Should be short buffer.
|
|
sts = OEMCrypto_ERROR_UNKNOWN_FAILURE;
|
|
} else if (sts == OEMCrypto_ERROR_SHORT_BUFFER) {
|
|
signature.resize(signatureSize);
|
|
sts = OEMCrypto_GenerateRSASignature(session, message, message_length,
|
|
signature.data(), &signatureSize,
|
|
padding_scheme);
|
|
}
|
|
}
|
|
OEMCrypto_CloseSession(session);
|
|
return sts;
|
|
}
|
|
|
|
} // namespace wvdrm
|