summaryrefslogtreecommitdiffstats
path: root/trusty
diff options
context:
space:
mode:
authorAndreas Gampe2017-10-02 16:37:31 -0500
committerandroid-build-merger2017-10-02 16:37:31 -0500
commita0e683c6a730371ba3646657e4fc545bb9727506 (patch)
tree0131c84f67cf7d6e3cae782d61f528a6cee597c6 /trusty
parentedb33628db724eceb7eb8ccb30b9058e385884a0 (diff)
parent0fdb8616b8e988be380e21586c45b48ee9c3e398 (diff)
downloadplatform-system-core-a0e683c6a730371ba3646657e4fc545bb9727506.tar.gz
platform-system-core-a0e683c6a730371ba3646657e4fc545bb9727506.tar.xz
platform-system-core-a0e683c6a730371ba3646657e4fc545bb9727506.zip
Merge "Keymaster: Move test to std::unique_ptr" am: 81348ffa9e am: 346d7e1405
am: 0fdb8616b8 Change-Id: Ie48dcc9b3c874697b726d6ab0a333905c455adb8
Diffstat (limited to 'trusty')
-rw-r--r--trusty/keymaster/trusty_keymaster_device_test.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/trusty/keymaster/trusty_keymaster_device_test.cpp b/trusty/keymaster/trusty_keymaster_device_test.cpp
index e8f5c0b69..922796492 100644
--- a/trusty/keymaster/trusty_keymaster_device_test.cpp
+++ b/trusty/keymaster/trusty_keymaster_device_test.cpp
@@ -15,9 +15,9 @@
15 */ 15 */
16#include <algorithm> 16#include <algorithm>
17#include <fstream> 17#include <fstream>
18#include <memory>
18 19
19#include <gtest/gtest.h> 20#include <gtest/gtest.h>
20#include <nativehelper/UniquePtr.h>
21#include <openssl/engine.h> 21#include <openssl/engine.h>
22 22
23#include <hardware/keymaster0.h> 23#include <hardware/keymaster0.h>
@@ -181,7 +181,7 @@ TEST_F(SigningTest, RsaSuccess) {
181 181
182 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE}; 182 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE};
183 size_t message_len = params.modulus_size / 8; 183 size_t message_len = params.modulus_size / 8;
184 UniquePtr<uint8_t[]> message(build_message(message_len)); 184 std::unique_ptr<uint8_t[]> message(build_message(message_len));
185 uint8_t* signature; 185 uint8_t* signature;
186 size_t siglen; 186 size_t siglen;
187 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len, 187 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len,
@@ -200,7 +200,7 @@ TEST_F(SigningTest, RsaShortMessage) {
200 200
201 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE}; 201 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE};
202 size_t message_len = params.modulus_size / 8 - 1; 202 size_t message_len = params.modulus_size / 8 - 1;
203 UniquePtr<uint8_t[]> message(build_message(message_len)); 203 std::unique_ptr<uint8_t[]> message(build_message(message_len));
204 uint8_t* signature; 204 uint8_t* signature;
205 size_t siglen; 205 size_t siglen;
206 EXPECT_EQ(KM_ERROR_UNKNOWN_ERROR, device.sign_data(&sig_params, ptr, size, message.get(), 206 EXPECT_EQ(KM_ERROR_UNKNOWN_ERROR, device.sign_data(&sig_params, ptr, size, message.get(),
@@ -217,7 +217,7 @@ TEST_F(SigningTest, RsaLongMessage) {
217 217
218 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE}; 218 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE};
219 size_t message_len = params.modulus_size / 8 + 1; 219 size_t message_len = params.modulus_size / 8 + 1;
220 UniquePtr<uint8_t[]> message(build_message(message_len)); 220 std::unique_ptr<uint8_t[]> message(build_message(message_len));
221 uint8_t* signature; 221 uint8_t* signature;
222 size_t siglen; 222 size_t siglen;
223 EXPECT_EQ(KM_ERROR_UNKNOWN_ERROR, device.sign_data(&sig_params, ptr, size, message.get(), 223 EXPECT_EQ(KM_ERROR_UNKNOWN_ERROR, device.sign_data(&sig_params, ptr, size, message.get(),
@@ -272,7 +272,7 @@ TEST_F(SigningTest, EcdsaLargeMessageSuccess) {
272 272
273 keymaster_ec_sign_params_t sig_params = {DIGEST_NONE}; 273 keymaster_ec_sign_params_t sig_params = {DIGEST_NONE};
274 size_t message_len = 1024 * 7; 274 size_t message_len = 1024 * 7;
275 UniquePtr<uint8_t[]> message(new uint8_t[message_len]); 275 std::unique_ptr<uint8_t[]> message(new uint8_t[message_len]);
276 // contents of message don't matter. 276 // contents of message don't matter.
277 uint8_t* signature; 277 uint8_t* signature;
278 size_t siglen; 278 size_t siglen;
@@ -294,7 +294,7 @@ TEST_F(VerificationTest, RsaSuccess) {
294 294
295 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE}; 295 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE};
296 size_t message_len = params.modulus_size / 8; 296 size_t message_len = params.modulus_size / 8;
297 UniquePtr<uint8_t[]> message(build_message(message_len)); 297 std::unique_ptr<uint8_t[]> message(build_message(message_len));
298 uint8_t* signature; 298 uint8_t* signature;
299 size_t siglen; 299 size_t siglen;
300 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len, 300 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len,
@@ -315,7 +315,7 @@ TEST_F(VerificationTest, RsaBadSignature) {
315 315
316 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE}; 316 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE};
317 size_t message_len = params.modulus_size / 8; 317 size_t message_len = params.modulus_size / 8;
318 UniquePtr<uint8_t[]> message(build_message(message_len)); 318 std::unique_ptr<uint8_t[]> message(build_message(message_len));
319 uint8_t* signature; 319 uint8_t* signature;
320 size_t siglen; 320 size_t siglen;
321 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len, 321 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len,
@@ -338,7 +338,7 @@ TEST_F(VerificationTest, RsaBadMessage) {
338 338
339 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE}; 339 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE};
340 size_t message_len = params.modulus_size / 8; 340 size_t message_len = params.modulus_size / 8;
341 UniquePtr<uint8_t[]> message(build_message(message_len)); 341 std::unique_ptr<uint8_t[]> message(build_message(message_len));
342 uint8_t* signature; 342 uint8_t* signature;
343 size_t siglen; 343 size_t siglen;
344 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len, 344 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len,
@@ -360,7 +360,7 @@ TEST_F(VerificationTest, RsaShortMessage) {
360 360
361 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE}; 361 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE};
362 size_t message_len = params.modulus_size / 8; 362 size_t message_len = params.modulus_size / 8;
363 UniquePtr<uint8_t[]> message(build_message(message_len)); 363 std::unique_ptr<uint8_t[]> message(build_message(message_len));
364 uint8_t* signature; 364 uint8_t* signature;
365 size_t siglen; 365 size_t siglen;
366 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len, 366 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len,
@@ -382,7 +382,7 @@ TEST_F(VerificationTest, RsaLongMessage) {
382 382
383 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE}; 383 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE};
384 size_t message_len = params.modulus_size / 8; 384 size_t message_len = params.modulus_size / 8;
385 UniquePtr<uint8_t[]> message(build_message(message_len + 1)); 385 std::unique_ptr<uint8_t[]> message(build_message(message_len + 1));
386 uint8_t* signature; 386 uint8_t* signature;
387 size_t siglen; 387 size_t siglen;
388 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len, 388 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len,
@@ -422,7 +422,7 @@ TEST_F(VerificationTest, EcdsaLargeMessageSuccess) {
422 422
423 keymaster_ec_sign_params_t sig_params = {DIGEST_NONE}; 423 keymaster_ec_sign_params_t sig_params = {DIGEST_NONE};
424 size_t message_len = 1024 * 7; 424 size_t message_len = 1024 * 7;
425 UniquePtr<uint8_t[]> message(new uint8_t[message_len]); 425 std::unique_ptr<uint8_t[]> message(new uint8_t[message_len]);
426 // contents of message don't matter. 426 // contents of message don't matter.
427 uint8_t* signature; 427 uint8_t* signature;
428 size_t siglen; 428 size_t siglen;
@@ -453,7 +453,7 @@ TEST_F(ImportKeyTest, RsaSuccess) {
453 453
454 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE}; 454 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE};
455 size_t message_size = 1024 /* key size */ / 8; 455 size_t message_size = 1024 /* key size */ / 8;
456 UniquePtr<uint8_t[]> message(new uint8_t[message_size]); 456 std::unique_ptr<uint8_t[]> message(new uint8_t[message_size]);
457 memset(message.get(), 'a', message_size); 457 memset(message.get(), 'a', message_size);
458 uint8_t* signature; 458 uint8_t* signature;
459 size_t siglen; 459 size_t siglen;
@@ -491,9 +491,9 @@ struct EVP_PKEY_CTX_Delete {
491 491
492static void VerifySignature(const uint8_t* key, size_t key_len, const uint8_t* signature, 492static void VerifySignature(const uint8_t* key, size_t key_len, const uint8_t* signature,
493 size_t signature_len, const uint8_t* message, size_t message_len) { 493 size_t signature_len, const uint8_t* message, size_t message_len) {
494 UniquePtr<EVP_PKEY, EVP_PKEY_Delete> pkey(d2i_PUBKEY(NULL, &key, key_len)); 494 std::unique_ptr<EVP_PKEY, EVP_PKEY_Delete> pkey(d2i_PUBKEY(NULL, &key, key_len));
495 ASSERT_TRUE(pkey.get() != NULL); 495 ASSERT_TRUE(pkey.get() != NULL);
496 UniquePtr<EVP_PKEY_CTX, EVP_PKEY_CTX_Delete> ctx(EVP_PKEY_CTX_new(pkey.get(), NULL)); 496 std::unique_ptr<EVP_PKEY_CTX, EVP_PKEY_CTX_Delete> ctx(EVP_PKEY_CTX_new(pkey.get(), NULL));
497 ASSERT_TRUE(ctx.get() != NULL); 497 ASSERT_TRUE(ctx.get() != NULL);
498 ASSERT_EQ(1, EVP_PKEY_verify_init(ctx.get())); 498 ASSERT_EQ(1, EVP_PKEY_verify_init(ctx.get()));
499 if (EVP_PKEY_type(pkey->type) == EVP_PKEY_RSA) 499 if (EVP_PKEY_type(pkey->type) == EVP_PKEY_RSA)
@@ -518,7 +518,7 @@ TEST_F(ExportKeyTest, RsaSuccess) {
518 // Sign a message so we can verify it with the exported pubkey. 518 // Sign a message so we can verify it with the exported pubkey.
519 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE}; 519 keymaster_rsa_sign_params_t sig_params = {DIGEST_NONE, PADDING_NONE};
520 size_t message_len = params.modulus_size / 8; 520 size_t message_len = params.modulus_size / 8;
521 UniquePtr<uint8_t[]> message(build_message(message_len)); 521 std::unique_ptr<uint8_t[]> message(build_message(message_len));
522 uint8_t* signature; 522 uint8_t* signature;
523 size_t siglen; 523 size_t siglen;
524 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len, 524 EXPECT_EQ(KM_ERROR_OK, device.sign_data(&sig_params, ptr, size, message.get(), message_len,