Fix or ignore compiler warnings

Merge from Widevine repo of http://go/wvgerrit/24688

b/35466719

Change-Id: If89f0cad0c61f37536a84f8dadaf08072356343a
This commit is contained in:
Fred Gylys-Colwell
2017-03-21 15:09:02 -07:00
parent c4aad89fd0
commit 85365a1497
6 changed files with 35 additions and 31 deletions

View File

@@ -106,7 +106,7 @@ void CryptoSession::Init() {
}
void CryptoSession::Terminate() {
LOGE("CryptoSession::Terminate: initialized_=%d, session_count_=%d",
LOGV("CryptoSession::Terminate: initialized_=%d, session_count_=%d",
initialized_, session_count_);
AutoLock auto_lock(crypto_lock_);
if (session_count_ > 0) {

View File

@@ -334,7 +334,7 @@ void clear_cache_function(void *page, size_t len) {
// are true, and use "#ifndef USED_BUILTIN_CLEAR_CACHE" instead of #else.
#ifdef __has_builtin
#if __has_builtin(__builtin___clear_cache)
#pragma message "clear_cache_function is using __builtin___clear_cache."
#pragma message "(info): clear_cache_function is using __builtin___clear_cache."
#define USED_BUILTIN_CLEAR_CACHE
char *begin = static_cast<char *>(page);
char *end = begin + len;
@@ -343,7 +343,7 @@ void clear_cache_function(void *page, size_t len) {
#endif
#ifndef USED_BUILTIN_CLEAR_CACHE
#if __arm__
#pragma message "clear_cache_function is using arm asm."
#pragma message "(info): clear_cache_function is using arm asm."
// ARM Cache Flush System Call:
char *begin = static_cast<char *>(page);
char *end = begin + len;
@@ -361,7 +361,7 @@ void clear_cache_function(void *page, size_t len) {
: "r0", "r1", "r7"
);
#elif __mips__
#pragma message "clear_cache_function is using mips asm."
#pragma message "(info): clear_cache_function is using mips asm."
int result = syscall(__NR_cacheflush, page, len, ICACHE);
if (result) {
fprintf(stderr, "cacheflush failed!: errno=%d %s\n", errno,
@@ -369,7 +369,7 @@ void clear_cache_function(void *page, size_t len) {
exit(-1); // TODO(fredgc): figure out more graceful error handling.
}
#else
#pragma message "clear_cache_function is not doing anything."
#pragma message "(info): clear_cache_function is not doing anything."
// TODO(fredgc): silence warning about unused variables.
#endif
#endif

View File

@@ -93,7 +93,7 @@ Session::Session()
num_keys_(4) { // Most tests only use 4 keys.
// Other tests will explicitly call set_num_keys.
// Stripe the padded message.
for (int i = 0; i < sizeof(padded_message_.padding); i++) {
for (size_t i = 0; i < sizeof(padded_message_.padding); i++) {
padded_message_.padding[i] = i % 0x100;
}
}
@@ -424,7 +424,7 @@ void Session::VerifyClientSignature(size_t data_length) {
// In the real world, a message should be signed by the client and
// verified by the server. This simulates that.
vector<uint8_t> data(data_length);
for (int i = 0; i < data.size(); i++) data[i] = i % 0xFF;
for (size_t i = 0; i < data.size(); i++) data[i] = i % 0xFF;
OEMCryptoResult sts;
size_t gen_signature_length = 0;
sts = OEMCrypto_GenerateSignature(session_id(), &data[0], data.size(), NULL,
@@ -580,7 +580,7 @@ void Session::LoadOEMCert(bool verify_cert) {
ASSERT_EQ(OEMCrypto_ERROR_SHORT_BUFFER,
OEMCrypto_GetOEMPublicCertificate(session_id(), NULL,
&public_cert_length));
ASSERT_GT(public_cert_length, 0);
ASSERT_LT(0u, public_cert_length);
public_cert.resize(public_cert_length);
ASSERT_EQ(OEMCrypto_SUCCESS,
OEMCrypto_GetOEMPublicCertificate(session_id(), &public_cert[0],
@@ -674,7 +674,6 @@ void Session::RewrapRSAKey(const struct RSAPrivateKeyMessage& encrypted,
}
}
void Session::RewrapRSAKey30(const struct RSAPrivateKeyMessage& encrypted,
size_t message_size,
const std::vector<uint8_t>& encrypted_message_key,
vector<uint8_t>* wrapped_key, bool force) {
size_t wrapped_key_length = 0;
@@ -861,8 +860,7 @@ void Session::UpdateUsageEntry(std::vector<uint8_t>* header_buffer) {
&encrypted_usage_entry_[0], &entry_buffer_length));
}
void Session::DeactivateUsageEntry(const std::string& pst,
OEMCryptoResult expect_result) {
void Session::DeactivateUsageEntry(const std::string& pst) {
ASSERT_EQ(OEMCrypto_SUCCESS,
OEMCrypto_DeactivateUsageEntry(
session_id(), reinterpret_cast<const uint8_t*>(pst.c_str()),

View File

@@ -248,7 +248,6 @@ class Session {
// Calls OEMCrypto_RewrapDeviceRSAKey30 with the given provisioning response
// message. If force is true, we assert that the key loads successfully.
void RewrapRSAKey30(const struct RSAPrivateKeyMessage& encrypted,
size_t message_size,
const std::vector<uint8_t>& encrypted_message_key,
vector<uint8_t>* wrapped_key, bool force);
// Loads the specified wrapped_rsa_key into OEMCrypto, and then runs
@@ -269,8 +268,7 @@ class Session {
// Update the usage entry and save the header to the specified buffer.
void UpdateUsageEntry(std::vector<uint8_t>* header_buffer);
// Deactivate this session's usage entry.
void DeactivateUsageEntry(const std::string& pst,
OEMCryptoResult expect_result = OEMCrypto_SUCCESS);
void DeactivateUsageEntry(const std::string& pst);
// The usage entry number for this session's usage entry.
uint32_t usage_entry_number() const { return usage_entry_number_; }
void set_usage_entry_number(uint32_t v) { usage_entry_number_ = v; }
@@ -330,7 +328,7 @@ class Session {
void set_num_keys(int num_keys) { num_keys_ = num_keys; }
// The current number of keys to use in the license(), encrypted_license()
// and key_array().
int num_keys() const { return num_keys_; }
unsigned int num_keys() const { return num_keys_; }
// Set the size of the buffer used the encrypted license.
// Must be between sizeof(MessageData) and kMaxMessageSize.
@@ -355,7 +353,7 @@ class Session {
size_t message_size_; // How much of the padded message to use.
OEMCrypto_KeyObject key_array_[kMaxNumKeys];
std::vector<uint8_t> signature_;
int num_keys_;
unsigned int num_keys_;
vector<uint8_t> encrypted_usage_entry_;
uint32_t usage_entry_number_;
string pst_;

View File

@@ -277,7 +277,7 @@ TEST_F(OEMCryptoClientTest, GetRandomLargeBuffer) {
// We don't have enough data to see that the data is really random,
// so we'll just do a spot check that two calls don't return the same values.
int count = 0;
for (int i = 0; i < size; i++) {
for (size_t i = 0; i < size; i++) {
if (data1[i] == data2[i]) count++;
}
ASSERT_LE(count, 3); // P(count > 3) = 1/256^3 = 6e-8.
@@ -505,7 +505,7 @@ TEST_F(OEMCryptoKeyboxTest, GenerateDerivedKeysFromKeyboxLargeBuffer) {
vector<uint8_t> mac_context(kMaxMessageSize);
vector<uint8_t> enc_context(kMaxMessageSize);
// Stripe the data so the two vectors are not identical, and not all zeroes.
for (int i = 0; i < kMaxMessageSize; i++) {
for (size_t i = 0; i < kMaxMessageSize; i++) {
mac_context[i] = i % 0x100;
enc_context[i] = (3 * i) % 0x100;
}
@@ -764,8 +764,7 @@ class OEMCryptoSessionTests : public OEMCryptoClientTest {
ASSERT_NO_FATAL_FAILURE(
s.MakeRSACertificate(&encrypted, sizeof(encrypted), &signature,
allowed_schemes, encoded_rsa_key_, &message_key));
ASSERT_NO_FATAL_FAILURE(s.RewrapRSAKey30(encrypted, sizeof(encrypted),
encrypted_message_key,
ASSERT_NO_FATAL_FAILURE(s.RewrapRSAKey30(encrypted, encrypted_message_key,
&wrapped_rsa_key_, force));
// Verify that the clear key is not contained in the wrapped key.
// It should be encrypted.
@@ -946,7 +945,7 @@ TEST_F(OEMCryptoSessionTests, ClientSignatureLargeBuffer) {
ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys("", false));
vector<uint8_t> context(kMaxMessageSize);
for (int i = 0; i < kMaxMessageSize; i++) {
for (size_t i = 0; i < kMaxMessageSize; i++) {
context[i] = i % 0x100;
}
static const uint32_t SignatureBufferMaxLength = 256;
@@ -1180,11 +1179,11 @@ class SessionTestAlternateVerification : public OEMCryptoSessionTests,
public:
virtual void SetUp() {
OEMCryptoSessionTests::SetUp();
target_api_ = GetParam();
target_api_ = static_cast<uint32_t>(GetParam());
}
protected:
int target_api_;
uint32_t target_api_;
};
TEST_P(SessionTestAlternateVerification, LoadKeys) {
@@ -1197,7 +1196,7 @@ TEST_P(SessionTestAlternateVerification, LoadKeys) {
if (target_api_ > 8 && target_api_ < 100) {
snprintf(buffer, 5, "kc%02d", target_api_);
}
for (int i = 0; i < s.num_keys(); i++) {
for (size_t i = 0; i < s.num_keys(); i++) {
memcpy(s.license().keys[i].control.verification, buffer, 4);
}
ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign());
@@ -1386,7 +1385,7 @@ TEST_F(OEMCryptoSessionTests, Minimum20KeysAPI12) {
ASSERT_NO_FATAL_FAILURE(s.FillSimpleMessage(0, 0, 0));
ASSERT_NO_FATAL_FAILURE(s.EncryptAndSign());
ASSERT_NO_FATAL_FAILURE(s.LoadTestKeys());
for (int key_index = 0; key_index < kMaxNumKeys; key_index++) {
for (size_t key_index = 0; key_index < kMaxNumKeys; key_index++) {
bool kSelectKeyFirst = true;
ASSERT_NO_FATAL_FAILURE(
s.TestDecryptCTR(kSelectKeyFirst, OEMCrypto_SUCCESS, key_index));
@@ -1707,7 +1706,8 @@ class OEMCryptoSessionTestsDecryptTests
// Partial block. Don't increment iv. Compute next block offset.
block_offset = block_offset + size;
} else {
EXPECT_EQ(AES_BLOCK_SIZE, block_offset + size);
EXPECT_EQ(static_cast<size_t>(AES_BLOCK_SIZE),
block_offset + size);
// Full block. Increment iv, and set offset to 0 for next block.
ctr128_inc64(1, iv);
block_offset = 0;
@@ -1751,7 +1751,7 @@ class OEMCryptoSessionTestsDecryptTests
if (decrypt_inplace_) { // Use same buffer for input and output.
// Copy the useful data from encryptedData to output_buffer, which
// will be the same as input_buffer. Leave the 0xaa padding at the end.
for(int i=0; i < total_size_; i++) output_buffer[i] = encryptedData[i];
for(size_t i=0; i < total_size_; i++) output_buffer[i] = encryptedData[i];
// Now let input_buffer point to the same data.
input_buffer = &output_buffer[0];
} else {
@@ -2479,7 +2479,7 @@ TEST_F(OEMCryptoLoadsCertificate, TestLargeRSAKey3072) {
// Devices that load certificates, should at least support RSA 2048 keys.
TEST_F(OEMCryptoLoadsCertificate, SupportsCertificatesAPI13) {
ASSERT_NE(0,
ASSERT_NE(0u,
OEMCrypto_Supports_RSA_2048bit & OEMCrypto_SupportedCertificates())
<< "Supported certificates is only " << OEMCrypto_SupportedCertificates();
}
@@ -2686,7 +2686,7 @@ TEST_F(OEMCryptoUsesCertificate, GenerateDerivedKeysLargeBuffer) {
vector<uint8_t> mac_context(kMaxMessageSize);
vector<uint8_t> enc_context(kMaxMessageSize);
// Stripe the data so the two vectors are not identical, and not all zeroes.
for (int i = 0; i < kMaxMessageSize; i++) {
for (size_t i = 0; i < kMaxMessageSize; i++) {
mac_context[i] = i % 0x100;
enc_context[i] = (3 * i) % 0x100;
}
@@ -3061,7 +3061,7 @@ class OEMCryptoCastReceiverTest : public OEMCryptoLoadsCertificateAlternates {
// CAST Receivers should report that they support cast certificates.
TEST_F(OEMCryptoCastReceiverTest, SupportsCertificatesAPI13) {
ASSERT_NE(0, OEMCrypto_Supports_RSA_CAST & OEMCrypto_SupportedCertificates());
ASSERT_NE(0u, OEMCrypto_Supports_RSA_CAST & OEMCrypto_SupportedCertificates());
}
// # PKCS#1 v1.5 Signature Example 15.1
@@ -4607,7 +4607,7 @@ TEST_F(UsageTableTest, TwoHundredEntries) {
s1.get_nonce(), pst1));
ASSERT_NO_FATAL_FAILURE(s1.EncryptAndSign());
ASSERT_NO_FATAL_FAILURE(s1.CreateNewUsageEntry());
ASSERT_EQ(s1.usage_entry_number(), 0);
ASSERT_EQ(0u, s1.usage_entry_number());
time_t start = time(NULL);
ASSERT_NO_FATAL_FAILURE(s1.LoadTestKeys(pst1, new_mac_keys_));
ASSERT_NO_FATAL_FAILURE(s1.UpdateUsageEntry(&encrypted_usage_header_));

View File

@@ -34,6 +34,10 @@ LOCAL_MODULE := libwvdrmengine_test
LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_OWNER := widevine
LOCAL_PROPRIETARY_MODULE := true
include $(BUILD_EXECUTABLE)
# -----------------------------------------------------------------------------
@@ -75,4 +79,8 @@ LOCAL_MODULE := libwvdrmengine_hidl_test
LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_OWNER := widevine
LOCAL_PROPRIETARY_MODULE := true
include $(BUILD_EXECUTABLE)