Gaurav Shah | ce0cc30 | 2010-03-24 13:48:55 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | #ifndef VBOOT_REFERENCE_TEST_COMMON_H_ |
| 8 | #define VBOOT_REFERENCE_TEST_COMMON_H_ |
| 9 | |
Gaurav Shah | 3199eed | 2010-03-25 13:04:45 -0700 | [diff] [blame] | 10 | #include <stdint.h> |
| 11 | |
| 12 | #include "firmware_image.h" |
| 13 | #include "kernel_image.h" |
| 14 | |
Gaurav Shah | ce0cc30 | 2010-03-24 13:48:55 -0700 | [diff] [blame] | 15 | extern int gTestSuccess; |
Gaurav Shah | bcd8f4a | 2010-05-26 13:19:00 -0700 | [diff] [blame^] | 16 | |
Gaurav Shah | 3199eed | 2010-03-25 13:04:45 -0700 | [diff] [blame] | 17 | /* Return 1 if result is equal to expected_result, else return 0. |
| 18 | * Also update the global gTestSuccess flag if test fails. */ |
| 19 | int TEST_EQ(int result, int expected_result, char* testname); |
Gaurav Shah | bcd8f4a | 2010-05-26 13:19:00 -0700 | [diff] [blame^] | 20 | /* Return 0 if result is equal to not_expected_result, else return 1. |
| 21 | * Also update the global gTestSuccess flag if test fails. */ |
| 22 | int TEST_NEQ(int result, int not_expected_result, char* testname); |
Gaurav Shah | 3199eed | 2010-03-25 13:04:45 -0700 | [diff] [blame] | 23 | |
| 24 | /* Test firmware image generation functions. */ |
| 25 | FirmwareImage* GenerateTestFirmwareImage(int algorithm, |
| 26 | const uint8_t* firmware_sign_key, |
| 27 | int firmware_key_version, |
| 28 | int firmware_version, |
Gaurav Shah | e450be4 | 2010-03-29 21:27:08 -0700 | [diff] [blame] | 29 | uint64_t firmware_len, |
Gaurav Shah | 3199eed | 2010-03-25 13:04:45 -0700 | [diff] [blame] | 30 | const char* root_key_file, |
Gaurav Shah | 463be3f | 2010-03-29 16:13:45 -0700 | [diff] [blame] | 31 | const char* firmware_key_file, |
| 32 | uint8_t firmware_data_fill_char); |
Gaurav Shah | 0265882 | 2010-04-18 16:35:07 -0700 | [diff] [blame] | 33 | uint8_t* GenerateTestVerificationBlob(int algorithm, |
| 34 | const uint8_t* firmware_sign_key, |
| 35 | int firmware_key_version, |
| 36 | int firmware_version, |
| 37 | uint64_t firmware_len, |
| 38 | const char* root_key_file, |
| 39 | const char* firmware_key_file); |
Gaurav Shah | 3199eed | 2010-03-25 13:04:45 -0700 | [diff] [blame] | 40 | |
| 41 | /* Test kernel image generation functions. */ |
| 42 | KernelImage* GenerateTestKernelImage(int firmware_sign_algorithm, |
| 43 | int kernel_sign_algorithm, |
| 44 | const uint8_t* kernel_sign_key, |
| 45 | int kernel_key_version, |
| 46 | int kernel_version, |
Gaurav Shah | e450be4 | 2010-03-29 21:27:08 -0700 | [diff] [blame] | 47 | uint64_t kernel_len, |
Gaurav Shah | 3199eed | 2010-03-25 13:04:45 -0700 | [diff] [blame] | 48 | const char* firmware_key_file, |
Gaurav Shah | 463be3f | 2010-03-29 16:13:45 -0700 | [diff] [blame] | 49 | const char* kernel_key_file, |
| 50 | uint8_t kernel_data_fill_char); |
Gaurav Shah | 3199eed | 2010-03-25 13:04:45 -0700 | [diff] [blame] | 51 | uint8_t* GenerateTestKernelBlob(int firmware_sign_algorithm, |
| 52 | int kernel_sign_algorithm, |
| 53 | const uint8_t* kernel_sign_key, |
| 54 | int kernel_key_version, |
| 55 | int kernel_version, |
Gaurav Shah | e450be4 | 2010-03-29 21:27:08 -0700 | [diff] [blame] | 56 | uint64_t kernel_len, |
Gaurav Shah | 3199eed | 2010-03-25 13:04:45 -0700 | [diff] [blame] | 57 | const char* firmware_key_file, |
| 58 | const char* kernel_key_file); |
Gaurav Shah | a82bf26 | 2010-03-26 10:38:08 -0700 | [diff] [blame] | 59 | |
Gaurav Shah | 0265882 | 2010-04-18 16:35:07 -0700 | [diff] [blame] | 60 | /* Generates a test verification block for rollback tests with a given |
| 61 | * [firmware_key_version] and [firmware_version]. The firmware length is |
| 62 | * assumed to be 1 bytes, and containing { 'F' }. |
| 63 | */ |
| 64 | uint8_t* GenerateRollbackTestVerificationBlob(int firmware_key_version, |
| 65 | int firmware_version); |
Gaurav Shah | ce0cc30 | 2010-03-24 13:48:55 -0700 | [diff] [blame] | 66 | |
Gaurav Shah | a82bf26 | 2010-03-26 10:38:08 -0700 | [diff] [blame] | 67 | /* Generates a test kernel iamge for rollback tests with a given |
| 68 | * [kernel_key_version} and [kernel_version]. If [is_corrupt] is 1, |
| 69 | * then the image has invalid signatures and will fail verification. */ |
| 70 | uint8_t* GenerateRollbackTestKernelBlob(int kernel_key_version, |
| 71 | int kernel_version, |
| 72 | int is_corrupt); |
Gaurav Shah | ce0cc30 | 2010-03-24 13:48:55 -0700 | [diff] [blame] | 73 | #endif /* VBOOT_REFERENCE_TEST_COMMON_H_ */ |