Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: tests/vboot_common2_tests.c

Issue 2809037: Make vboot_reference build in MSVC command line environment. (Closed) Base URL: ssh://git@chromiumos-git/vboot_reference.git
Patch Set: Integrated trunk changes. Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/timer_utils.h ('k') | tests/vboot_common3_tests.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 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 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 * 4 *
5 * Tests for firmware image library. 5 * Tests for firmware image library.
6 */ 6 */
7 7
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 10
(...skipping 16 matching lines...) Expand all
27 "PublicKeyToRSA() invalid algorithm"); 27 "PublicKeyToRSA() invalid algorithm");
28 28
29 PublicKeyCopy(key, orig_key); 29 PublicKeyCopy(key, orig_key);
30 key->key_size -= 1; 30 key->key_size -= 1;
31 TEST_EQ((size_t)PublicKeyToRSA(key), 0, 31 TEST_EQ((size_t)PublicKeyToRSA(key), 0,
32 "PublicKeyToRSA() invalid size"); 32 "PublicKeyToRSA() invalid size");
33 33
34 rsa = PublicKeyToRSA(orig_key); 34 rsa = PublicKeyToRSA(orig_key);
35 TEST_NEQ((size_t)rsa, 0, "PublicKeyToRSA() ok"); 35 TEST_NEQ((size_t)rsa, 0, "PublicKeyToRSA() ok");
36 if (rsa) { 36 if (rsa) {
37 TEST_EQ(rsa->algorithm, key->algorithm, "PublicKeyToRSA() algorithm"); 37 TEST_EQ((int)rsa->algorithm, (int)key->algorithm,
38 "PublicKeyToRSA() algorithm");
38 RSAPublicKeyFree(rsa); 39 RSAPublicKeyFree(rsa);
39 } 40 }
40 } 41 }
41 42
42 43
43 static void VerifyDataTest(const VbPublicKey* public_key, 44 static void VerifyDataTest(const VbPublicKey* public_key,
44 const VbPrivateKey* private_key) { 45 const VbPrivateKey* private_key) {
45 46
46 const uint8_t test_data[] = "This is some test data to sign."; 47 const uint8_t test_data[] = "This is some test data to sign.";
47 VbSignature* sig; 48 VbSignature* sig;
(...skipping 22 matching lines...) Expand all
70 static void VerifyDigestTest(const VbPublicKey* public_key, 71 static void VerifyDigestTest(const VbPublicKey* public_key,
71 const VbPrivateKey* private_key) { 72 const VbPrivateKey* private_key) {
72 73
73 const uint8_t test_data[] = "This is some other test data to sign."; 74 const uint8_t test_data[] = "This is some other test data to sign.";
74 VbSignature* sig; 75 VbSignature* sig;
75 RSAPublicKey* rsa; 76 RSAPublicKey* rsa;
76 uint8_t* digest; 77 uint8_t* digest;
77 78
78 sig = CalculateSignature(test_data, sizeof(test_data), private_key); 79 sig = CalculateSignature(test_data, sizeof(test_data), private_key);
79 rsa = PublicKeyToRSA(public_key); 80 rsa = PublicKeyToRSA(public_key);
80 digest = DigestBuf(test_data, sizeof(test_data), public_key->algorithm); 81 digest = DigestBuf(test_data, sizeof(test_data), (int)public_key->algorithm);
81 TEST_NEQ(sig && rsa && digest, 0, "VerifyData() prerequisites"); 82 TEST_NEQ(sig && rsa && digest, 0, "VerifyData() prerequisites");
82 if (!sig || !rsa || !digest) 83 if (!sig || !rsa || !digest)
83 return; 84 return;
84 85
85 TEST_EQ(VerifyDigest(digest, sig, rsa), 0, "VerifyDigest() ok"); 86 TEST_EQ(VerifyDigest(digest, sig, rsa), 0, "VerifyDigest() ok");
86 87
87 GetSignatureData(sig)[0] ^= 0x5A; 88 GetSignatureData(sig)[0] ^= 0x5A;
88 TEST_EQ(VerifyDigest(digest, sig, rsa), 1, "VerifyDigest() wrong sig"); 89 TEST_EQ(VerifyDigest(digest, sig, rsa), 1, "VerifyDigest() wrong sig");
89 90
90 RSAPublicKeyFree(rsa); 91 RSAPublicKeyFree(rsa);
(...skipping 11 matching lines...) Expand all
102 Free(sig); 103 Free(sig);
103 } 104 }
104 105
105 106
106 static void VerifyKernelPreambleTest(const VbPublicKey* public_key, 107 static void VerifyKernelPreambleTest(const VbPublicKey* public_key,
107 const VbPrivateKey* private_key) { 108 const VbPrivateKey* private_key) {
108 109
109 VbKernelPreambleHeader *hdr; 110 VbKernelPreambleHeader *hdr;
110 VbKernelPreambleHeader *h; 111 VbKernelPreambleHeader *h;
111 RSAPublicKey* rsa; 112 RSAPublicKey* rsa;
112 uint64_t hsize; 113 unsigned hsize;
113 114
114 /* Create a dummy signature */ 115 /* Create a dummy signature */
115 VbSignature *body_sig = SignatureAlloc(56, 78); 116 VbSignature *body_sig = SignatureAlloc(56, 78);
116 117
117 rsa = PublicKeyToRSA(public_key); 118 rsa = PublicKeyToRSA(public_key);
118 hdr = CreateKernelPreamble(0x1234, 0x100000, 0x300000, 0x4000, body_sig, 119 hdr = CreateKernelPreamble(0x1234, 0x100000, 0x300000, 0x4000, body_sig,
119 0, private_key); 120 0, private_key);
120 TEST_NEQ(hdr && rsa, 0, "VerifyKernelPreamble2() prerequisites"); 121 TEST_NEQ(hdr && rsa, 0, "VerifyKernelPreamble2() prerequisites");
121 if (!hdr) 122 if (!hdr)
122 return; 123 return;
123 hsize = hdr->preamble_size; 124 hsize = (unsigned) hdr->preamble_size;
124 h = (VbKernelPreambleHeader*)Malloc(hsize + 16384); 125 h = (VbKernelPreambleHeader*)Malloc(hsize + 16384);
125 126
126 TEST_EQ(VerifyKernelPreamble2(hdr, hsize, rsa), 0, 127 TEST_EQ(VerifyKernelPreamble2(hdr, hsize, rsa), 0,
127 "VerifyKernelPreamble2() ok using key"); 128 "VerifyKernelPreamble2() ok using key");
128 TEST_NEQ(VerifyKernelPreamble2(hdr, hsize - 1, rsa), 0, 129 TEST_NEQ(VerifyKernelPreamble2(hdr, hsize - 1, rsa), 0,
129 "VerifyKernelPreamble2() size--"); 130 "VerifyKernelPreamble2() size--");
130 TEST_EQ(VerifyKernelPreamble2(hdr, hsize + 1, rsa), 0, 131 TEST_EQ(VerifyKernelPreamble2(hdr, hsize + 1, rsa), 0,
131 "VerifyKernelPreamble2() size++"); 132 "VerifyKernelPreamble2() size++");
132 133
133 /* Care about major version but not minor */ 134 /* Care about major version but not minor */
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 VerifyDigestTest(public_key, private_key); 230 VerifyDigestTest(public_key, private_key);
230 VerifyKernelPreambleTest(public_key, private_key); 231 VerifyKernelPreambleTest(public_key, private_key);
231 232
232 if (public_key) 233 if (public_key)
233 Free(public_key); 234 Free(public_key);
234 if (private_key) 235 if (private_key)
235 Free(private_key); 236 Free(private_key);
236 237
237 return error_code; 238 return error_code;
238 } 239 }
OLDNEW
« no previous file with comments | « tests/timer_utils.h ('k') | tests/vboot_common3_tests.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698