OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium 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 #include "crypto/signature_verifier.h" | 5 #include "crypto/signature_verifier.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 10 #include "base/macros.h" |
7 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
9 | 13 |
10 TEST(SignatureVerifierTest, BasicTest) { | 14 TEST(SignatureVerifierTest, BasicTest) { |
11 // The input data in this test comes from real certificates. | 15 // The input data in this test comes from real certificates. |
12 // | 16 // |
13 // tbs_certificate ("to-be-signed certificate", the part of a certificate | 17 // tbs_certificate ("to-be-signed certificate", the part of a certificate |
14 // that is signed), signature_algorithm, and algorithm come from the | 18 // that is signed), signature_algorithm, and algorithm come from the |
15 // certificate of bugs.webkit.org. | 19 // certificate of bugs.webkit.org. |
16 // | 20 // |
17 // public_key_info comes from the certificate of the issuer, Go Daddy Secure | 21 // public_key_info comes from the certificate of the issuer, Go Daddy Secure |
18 // Certification Authority. | 22 // Certification Authority. |
19 // | 23 // |
20 // The bytes in the array initializers are formatted to expose the DER | 24 // The bytes in the array initializers are formatted to expose the DER |
21 // encoding of the ASN.1 structures. | 25 // encoding of the ASN.1 structures. |
22 | 26 |
23 // The data that is signed is the following ASN.1 structure: | 27 // The data that is signed is the following ASN.1 structure: |
24 // TBSCertificate ::= SEQUENCE { | 28 // TBSCertificate ::= SEQUENCE { |
25 // ... -- omitted, not important | 29 // ... -- omitted, not important |
26 // } | 30 // } |
27 const uint8 tbs_certificate[1017] = { | 31 const uint8_t tbs_certificate[1017] = { |
28 0x30, 0x82, 0x03, 0xf5, // a SEQUENCE of length 1013 (0x3f5) | 32 0x30, 0x82, 0x03, 0xf5, // a SEQUENCE of length 1013 (0x3f5) |
29 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x03, 0x43, 0xdd, 0x63, 0x30, 0x0d, | 33 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x03, 0x43, 0xdd, 0x63, 0x30, 0x0d, |
30 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, | 34 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, |
31 0x00, 0x30, 0x81, 0xca, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, | 35 0x00, 0x30, 0x81, 0xca, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, |
32 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, | 36 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, |
33 0x04, 0x08, 0x13, 0x07, 0x41, 0x72, 0x69, 0x7a, 0x6f, 0x6e, 0x61, 0x31, | 37 0x04, 0x08, 0x13, 0x07, 0x41, 0x72, 0x69, 0x7a, 0x6f, 0x6e, 0x61, 0x31, |
34 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x0a, 0x53, 0x63, | 38 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x0a, 0x53, 0x63, |
35 0x6f, 0x74, 0x74, 0x73, 0x64, 0x61, 0x6c, 0x65, 0x31, 0x1a, 0x30, 0x18, | 39 0x6f, 0x74, 0x74, 0x73, 0x64, 0x61, 0x6c, 0x65, 0x31, 0x1a, 0x30, 0x18, |
36 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x11, 0x47, 0x6f, 0x44, 0x61, 0x64, | 40 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x11, 0x47, 0x6f, 0x44, 0x61, 0x64, |
37 0x64, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e, | 41 0x64, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e, |
38 0x31, 0x33, 0x30, 0x31, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x2a, 0x68, | 42 0x31, 0x33, 0x30, 0x31, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x2a, 0x68, |
39 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, | 43 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, |
40 0x69, 0x63, 0x61, 0x74, 0x65, 0x73, 0x2e, 0x67, 0x6f, 0x64, 0x61, 0x64, | 44 0x69, 0x63, 0x61, 0x74, 0x65, 0x73, 0x2e, 0x67, 0x6f, 0x64, 0x61, 0x64, |
41 0x64, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x65, 0x70, 0x6f, 0x73, | 45 0x64, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x65, 0x70, 0x6f, 0x73, |
42 0x69, 0x74, 0x6f, 0x72, 0x79, 0x31, 0x30, 0x30, 0x2e, 0x06, 0x03, 0x55, | 46 0x69, 0x74, 0x6f, 0x72, 0x79, 0x31, 0x30, 0x30, 0x2e, 0x06, 0x03, 0x55, |
43 0x04, 0x03, 0x13, 0x27, 0x47, 0x6f, 0x20, 0x44, 0x61, 0x64, 0x64, 0x79, | 47 0x04, 0x03, 0x13, 0x27, 0x47, 0x6f, 0x20, 0x44, 0x61, 0x64, 0x64, 0x79, |
44 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x20, 0x43, 0x65, 0x72, 0x74, | 48 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x20, 0x43, 0x65, 0x72, 0x74, |
45 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x41, 0x75, | 49 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x41, 0x75, |
46 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x31, 0x11, 0x30, 0x0f, 0x06, | 50 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x31, 0x11, 0x30, 0x0f, 0x06, |
47 0x03, 0x55, 0x04, 0x05, 0x13, 0x08, 0x30, 0x37, 0x39, 0x36, 0x39, 0x32, | 51 0x03, 0x55, 0x04, 0x05, 0x13, 0x08, 0x30, 0x37, 0x39, 0x36, 0x39, 0x32, |
48 0x38, 0x37, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x38, 0x30, 0x33, 0x31, 0x38, | 52 0x38, 0x37, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x38, 0x30, 0x33, 0x31, 0x38, |
49 0x32, 0x33, 0x33, 0x35, 0x31, 0x39, 0x5a, 0x17, 0x0d, 0x31, 0x31, 0x30, | 53 0x32, 0x33, 0x33, 0x35, 0x31, 0x39, 0x5a, 0x17, 0x0d, 0x31, 0x31, 0x30, |
50 0x33, 0x31, 0x38, 0x32, 0x33, 0x33, 0x35, 0x31, 0x39, 0x5a, 0x30, 0x79, | 54 0x33, 0x31, 0x38, 0x32, 0x33, 0x33, 0x35, 0x31, 0x39, 0x5a, 0x30, 0x79, |
51 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, | 55 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, |
52 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a, | 56 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a, |
53 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61, 0x31, 0x12, | 57 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61, 0x31, 0x12, |
54 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x09, 0x43, 0x75, 0x70, | 58 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x09, 0x43, 0x75, 0x70, |
55 0x65, 0x72, 0x74, 0x69, 0x6e, 0x6f, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, | 59 0x65, 0x72, 0x74, 0x69, 0x6e, 0x6f, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, |
56 0x55, 0x04, 0x0a, 0x13, 0x0a, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x49, | 60 0x55, 0x04, 0x0a, 0x13, 0x0a, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x49, |
57 0x6e, 0x63, 0x2e, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0b, | 61 0x6e, 0x63, 0x2e, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0b, |
58 0x13, 0x0c, 0x4d, 0x61, 0x63, 0x20, 0x4f, 0x53, 0x20, 0x46, 0x6f, 0x72, | 62 0x13, 0x0c, 0x4d, 0x61, 0x63, 0x20, 0x4f, 0x53, 0x20, 0x46, 0x6f, 0x72, |
59 0x67, 0x65, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, | 63 0x67, 0x65, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, |
60 0x0c, 0x2a, 0x2e, 0x77, 0x65, 0x62, 0x6b, 0x69, 0x74, 0x2e, 0x6f, 0x72, | 64 0x0c, 0x2a, 0x2e, 0x77, 0x65, 0x62, 0x6b, 0x69, 0x74, 0x2e, 0x6f, 0x72, |
61 0x67, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, | 65 0x67, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, |
62 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, | 66 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, |
63 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xa7, 0x62, 0x79, 0x41, 0xda, 0x28, | 67 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xa7, 0x62, 0x79, 0x41, 0xda, 0x28, |
64 0xf2, 0xc0, 0x4f, 0xe0, 0x25, 0xaa, 0xa1, 0x2e, 0x3b, 0x30, 0x94, 0xb5, | 68 0xf2, 0xc0, 0x4f, 0xe0, 0x25, 0xaa, 0xa1, 0x2e, 0x3b, 0x30, 0x94, 0xb5, |
65 0xc9, 0x26, 0x3a, 0x1b, 0xe2, 0xd0, 0xcc, 0xa2, 0x95, 0xe2, 0x91, 0xc0, | 69 0xc9, 0x26, 0x3a, 0x1b, 0xe2, 0xd0, 0xcc, 0xa2, 0x95, 0xe2, 0x91, 0xc0, |
66 0xf0, 0x40, 0x9e, 0x27, 0x6e, 0xbd, 0x6e, 0xde, 0x7c, 0xb6, 0x30, 0x5c, | 70 0xf0, 0x40, 0x9e, 0x27, 0x6e, 0xbd, 0x6e, 0xde, 0x7c, 0xb6, 0x30, 0x5c, |
67 0xb8, 0x9b, 0x01, 0x2f, 0x92, 0x04, 0xa1, 0xef, 0x4a, 0xb1, 0x6c, 0xb1, | 71 0xb8, 0x9b, 0x01, 0x2f, 0x92, 0x04, 0xa1, 0xef, 0x4a, 0xb1, 0x6c, 0xb1, |
68 0x7e, 0x8e, 0xcd, 0xa6, 0xf4, 0x40, 0x73, 0x1f, 0x2c, 0x96, 0xad, 0xff, | 72 0x7e, 0x8e, 0xcd, 0xa6, 0xf4, 0x40, 0x73, 0x1f, 0x2c, 0x96, 0xad, 0xff, |
69 0x2a, 0x6d, 0x0e, 0xba, 0x52, 0x84, 0x83, 0xb0, 0x39, 0xee, 0xc9, 0x39, | 73 0x2a, 0x6d, 0x0e, 0xba, 0x52, 0x84, 0x83, 0xb0, 0x39, 0xee, 0xc9, 0x39, |
70 0xdc, 0x1e, 0x34, 0xd0, 0xd8, 0x5d, 0x7a, 0x09, 0xac, 0xa9, 0xee, 0xca, | 74 0xdc, 0x1e, 0x34, 0xd0, 0xd8, 0x5d, 0x7a, 0x09, 0xac, 0xa9, 0xee, 0xca, |
71 0x65, 0xf6, 0x85, 0x3a, 0x6b, 0xee, 0xe4, 0x5c, 0x5e, 0xf8, 0xda, 0xd1, | 75 0x65, 0xf6, 0x85, 0x3a, 0x6b, 0xee, 0xe4, 0x5c, 0x5e, 0xf8, 0xda, 0xd1, |
72 0xce, 0x88, 0x47, 0xcd, 0x06, 0x21, 0xe0, 0xb9, 0x4b, 0xe4, 0x07, 0xcb, | 76 0xce, 0x88, 0x47, 0xcd, 0x06, 0x21, 0xe0, 0xb9, 0x4b, 0xe4, 0x07, 0xcb, |
73 0x57, 0xdc, 0xca, 0x99, 0x54, 0xf7, 0x0e, 0xd5, 0x17, 0x95, 0x05, 0x2e, | 77 0x57, 0xdc, 0xca, 0x99, 0x54, 0xf7, 0x0e, 0xd5, 0x17, 0x95, 0x05, 0x2e, |
74 0xe9, 0xb1, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x01, 0xce, 0x30, | 78 0xe9, 0xb1, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x01, 0xce, 0x30, |
75 0x82, 0x01, 0xca, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, | 79 0x82, 0x01, 0xca, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, |
76 0x30, 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, | 80 0x30, 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, |
77 0x02, 0x05, 0xa0, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x16, | 81 0x02, 0x05, 0xa0, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x16, |
78 0x30, 0x14, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, | 82 0x30, 0x14, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, |
79 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x57, | 83 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x57, |
80 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x50, 0x30, 0x4e, 0x30, 0x4c, 0xa0, | 84 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x50, 0x30, 0x4e, 0x30, 0x4c, 0xa0, |
81 0x4a, 0xa0, 0x48, 0x86, 0x46, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, | 85 0x4a, 0xa0, 0x48, 0x86, 0x46, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, |
82 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x73, | 86 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x73, |
83 0x2e, 0x67, 0x6f, 0x64, 0x61, 0x64, 0x64, 0x79, 0x2e, 0x63, 0x6f, 0x6d, | 87 0x2e, 0x67, 0x6f, 0x64, 0x61, 0x64, 0x64, 0x79, 0x2e, 0x63, 0x6f, 0x6d, |
84 0x2f, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x2f, | 88 0x2f, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x6f, 0x72, 0x79, 0x2f, |
85 0x67, 0x6f, 0x64, 0x61, 0x64, 0x64, 0x79, 0x65, 0x78, 0x74, 0x65, 0x6e, | 89 0x67, 0x6f, 0x64, 0x61, 0x64, 0x64, 0x79, 0x65, 0x78, 0x74, 0x65, 0x6e, |
86 0x64, 0x65, 0x64, 0x69, 0x73, 0x73, 0x75, 0x69, 0x6e, 0x67, 0x33, 0x2e, | 90 0x64, 0x65, 0x64, 0x69, 0x73, 0x73, 0x75, 0x69, 0x6e, 0x67, 0x33, 0x2e, |
87 0x63, 0x72, 0x6c, 0x30, 0x52, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04, 0x4b, | 91 0x63, 0x72, 0x6c, 0x30, 0x52, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04, 0x4b, |
88 0x30, 0x49, 0x30, 0x47, 0x06, 0x0b, 0x60, 0x86, 0x48, 0x01, 0x86, 0xfd, | 92 0x30, 0x49, 0x30, 0x47, 0x06, 0x0b, 0x60, 0x86, 0x48, 0x01, 0x86, 0xfd, |
89 0x6d, 0x01, 0x07, 0x17, 0x02, 0x30, 0x38, 0x30, 0x36, 0x06, 0x08, 0x2b, | 93 0x6d, 0x01, 0x07, 0x17, 0x02, 0x30, 0x38, 0x30, 0x36, 0x06, 0x08, 0x2b, |
90 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, 0x01, 0x16, 0x2a, 0x68, 0x74, 0x74, | 94 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, 0x01, 0x16, 0x2a, 0x68, 0x74, 0x74, |
91 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, | 95 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, |
92 0x61, 0x74, 0x65, 0x73, 0x2e, 0x67, 0x6f, 0x64, 0x61, 0x64, 0x64, 0x79, | 96 0x61, 0x74, 0x65, 0x73, 0x2e, 0x67, 0x6f, 0x64, 0x61, 0x64, 0x64, 0x79, |
93 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, | 97 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, |
94 0x6f, 0x72, 0x79, 0x30, 0x7f, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, | 98 0x6f, 0x72, 0x79, 0x30, 0x7f, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, |
95 0x07, 0x01, 0x01, 0x04, 0x73, 0x30, 0x71, 0x30, 0x23, 0x06, 0x08, 0x2b, | 99 0x07, 0x01, 0x01, 0x04, 0x73, 0x30, 0x71, 0x30, 0x23, 0x06, 0x08, 0x2b, |
96 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x86, 0x17, 0x68, 0x74, 0x74, | 100 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x86, 0x17, 0x68, 0x74, 0x74, |
97 0x70, 0x3a, 0x2f, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2e, 0x67, 0x6f, 0x64, | 101 0x70, 0x3a, 0x2f, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2e, 0x67, 0x6f, 0x64, |
98 0x61, 0x64, 0x64, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x4a, 0x06, 0x08, | 102 0x61, 0x64, 0x64, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x4a, 0x06, 0x08, |
99 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x3e, 0x68, 0x74, | 103 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x3e, 0x68, 0x74, |
100 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, | 104 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, |
101 0x63, 0x61, 0x74, 0x65, 0x73, 0x2e, 0x67, 0x6f, 0x64, 0x61, 0x64, 0x64, | 105 0x63, 0x61, 0x74, 0x65, 0x73, 0x2e, 0x67, 0x6f, 0x64, 0x61, 0x64, 0x64, |
102 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, | 106 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x65, 0x70, 0x6f, 0x73, 0x69, |
103 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x67, 0x64, 0x5f, 0x69, 0x6e, 0x74, 0x65, | 107 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x67, 0x64, 0x5f, 0x69, 0x6e, 0x74, 0x65, |
104 0x72, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x74, 0x65, 0x2e, 0x63, 0x72, 0x74, | 108 0x72, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x74, 0x65, 0x2e, 0x63, 0x72, 0x74, |
105 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x48, | 109 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x48, |
106 0xdf, 0x60, 0x32, 0xcc, 0x89, 0x01, 0xb6, 0xdc, 0x2f, 0xe3, 0x73, 0xb5, | 110 0xdf, 0x60, 0x32, 0xcc, 0x89, 0x01, 0xb6, 0xdc, 0x2f, 0xe3, 0x73, 0xb5, |
107 0x9c, 0x16, 0x58, 0x32, 0x68, 0xa9, 0xc3, 0x30, 0x1f, 0x06, 0x03, 0x55, | 111 0x9c, 0x16, 0x58, 0x32, 0x68, 0xa9, 0xc3, 0x30, 0x1f, 0x06, 0x03, 0x55, |
108 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xfd, 0xac, 0x61, 0x32, | 112 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xfd, 0xac, 0x61, 0x32, |
109 0x93, 0x6c, 0x45, 0xd6, 0xe2, 0xee, 0x85, 0x5f, 0x9a, 0xba, 0xe7, 0x76, | 113 0x93, 0x6c, 0x45, 0xd6, 0xe2, 0xee, 0x85, 0x5f, 0x9a, 0xba, 0xe7, 0x76, |
110 0x99, 0x68, 0xcc, 0xe7, 0x30, 0x23, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, | 114 0x99, 0x68, 0xcc, 0xe7, 0x30, 0x23, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, |
111 0x1c, 0x30, 0x1a, 0x82, 0x0c, 0x2a, 0x2e, 0x77, 0x65, 0x62, 0x6b, 0x69, | 115 0x1c, 0x30, 0x1a, 0x82, 0x0c, 0x2a, 0x2e, 0x77, 0x65, 0x62, 0x6b, 0x69, |
112 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x82, 0x0a, 0x77, 0x65, 0x62, 0x6b, 0x69, | 116 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x82, 0x0a, 0x77, 0x65, 0x62, 0x6b, 0x69, |
113 0x74, 0x2e, 0x6f, 0x72, 0x67 | 117 0x74, 0x2e, 0x6f, 0x72, 0x67}; |
114 }; | |
115 | 118 |
116 // The signature algorithm is specified as the following ASN.1 structure: | 119 // The signature algorithm is specified as the following ASN.1 structure: |
117 // AlgorithmIdentifier ::= SEQUENCE { | 120 // AlgorithmIdentifier ::= SEQUENCE { |
118 // algorithm OBJECT IDENTIFIER, | 121 // algorithm OBJECT IDENTIFIER, |
119 // parameters ANY DEFINED BY algorithm OPTIONAL } | 122 // parameters ANY DEFINED BY algorithm OPTIONAL } |
120 // | 123 // |
121 const uint8 signature_algorithm[15] = { | 124 const uint8_t signature_algorithm[15] = { |
122 0x30, 0x0d, // a SEQUENCE of length 13 (0xd) | 125 0x30, 0x0d, // a SEQUENCE of length 13 (0xd) |
123 0x06, 0x09, // an OBJECT IDENTIFIER of length 9 | 126 0x06, 0x09, // an OBJECT IDENTIFIER of length 9 |
124 // 1.2.840.113549.1.1.5 - sha1WithRSAEncryption | 127 // 1.2.840.113549.1.1.5 - sha1WithRSAEncryption |
125 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, | 128 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, |
126 0x05, 0x00, // a NULL of length 0 | 129 0x00, // a NULL of length 0 |
127 }; | 130 }; |
128 | 131 |
129 // RSA signature, a big integer in the big-endian byte order. | 132 // RSA signature, a big integer in the big-endian byte order. |
130 const uint8 signature[256] = { | 133 const uint8_t signature[256] = { |
131 0x1e, 0x6a, 0xe7, 0xe0, 0x4f, 0xe7, 0x4d, 0xd0, 0x69, 0x7c, 0xf8, 0x8f, | 134 0x1e, 0x6a, 0xe7, 0xe0, 0x4f, 0xe7, 0x4d, 0xd0, 0x69, 0x7c, 0xf8, 0x8f, |
132 0x99, 0xb4, 0x18, 0x95, 0x36, 0x24, 0x0f, 0x0e, 0xa3, 0xea, 0x34, 0x37, | 135 0x99, 0xb4, 0x18, 0x95, 0x36, 0x24, 0x0f, 0x0e, 0xa3, 0xea, 0x34, 0x37, |
133 0xf4, 0x7d, 0xd5, 0x92, 0x35, 0x53, 0x72, 0x76, 0x3f, 0x69, 0xf0, 0x82, | 136 0xf4, 0x7d, 0xd5, 0x92, 0x35, 0x53, 0x72, 0x76, 0x3f, 0x69, 0xf0, 0x82, |
134 0x56, 0xe3, 0x94, 0x7a, 0x1d, 0x1a, 0x81, 0xaf, 0x9f, 0xc7, 0x43, 0x01, | 137 0x56, 0xe3, 0x94, 0x7a, 0x1d, 0x1a, 0x81, 0xaf, 0x9f, 0xc7, 0x43, 0x01, |
135 0x64, 0xd3, 0x7c, 0x0d, 0xc8, 0x11, 0x4e, 0x4a, 0xe6, 0x1a, 0xc3, 0x01, | 138 0x64, 0xd3, 0x7c, 0x0d, 0xc8, 0x11, 0x4e, 0x4a, 0xe6, 0x1a, 0xc3, 0x01, |
136 0x74, 0xe8, 0x35, 0x87, 0x5c, 0x61, 0xaa, 0x8a, 0x46, 0x06, 0xbe, 0x98, | 139 0x74, 0xe8, 0x35, 0x87, 0x5c, 0x61, 0xaa, 0x8a, 0x46, 0x06, 0xbe, 0x98, |
137 0x95, 0x24, 0x9e, 0x01, 0xe3, 0xe6, 0xa0, 0x98, 0xee, 0x36, 0x44, 0x56, | 140 0x95, 0x24, 0x9e, 0x01, 0xe3, 0xe6, 0xa0, 0x98, 0xee, 0x36, 0x44, 0x56, |
138 0x8d, 0x23, 0x9c, 0x65, 0xea, 0x55, 0x6a, 0xdf, 0x66, 0xee, 0x45, 0xe8, | 141 0x8d, 0x23, 0x9c, 0x65, 0xea, 0x55, 0x6a, 0xdf, 0x66, 0xee, 0x45, 0xe8, |
139 0xa0, 0xe9, 0x7d, 0x9a, 0xba, 0x94, 0xc5, 0xc8, 0xc4, 0x4b, 0x98, 0xff, | 142 0xa0, 0xe9, 0x7d, 0x9a, 0xba, 0x94, 0xc5, 0xc8, 0xc4, 0x4b, 0x98, 0xff, |
140 0x9a, 0x01, 0x31, 0x6d, 0xf9, 0x2b, 0x58, 0xe7, 0xe7, 0x2a, 0xc5, 0x4d, | 143 0x9a, 0x01, 0x31, 0x6d, 0xf9, 0x2b, 0x58, 0xe7, 0xe7, 0x2a, 0xc5, 0x4d, |
141 0xbb, 0xbb, 0xcd, 0x0d, 0x70, 0xe1, 0xad, 0x03, 0xf5, 0xfe, 0xf4, 0x84, | 144 0xbb, 0xbb, 0xcd, 0x0d, 0x70, 0xe1, 0xad, 0x03, 0xf5, 0xfe, 0xf4, 0x84, |
142 0x71, 0x08, 0xd2, 0xbc, 0x04, 0x7b, 0x26, 0x1c, 0xa8, 0x0f, 0x9c, 0xd8, | 145 0x71, 0x08, 0xd2, 0xbc, 0x04, 0x7b, 0x26, 0x1c, 0xa8, 0x0f, 0x9c, 0xd8, |
143 0x12, 0x6a, 0x6f, 0x2b, 0x67, 0xa1, 0x03, 0x80, 0x9a, 0x11, 0x0b, 0xe9, | 146 0x12, 0x6a, 0x6f, 0x2b, 0x67, 0xa1, 0x03, 0x80, 0x9a, 0x11, 0x0b, 0xe9, |
144 0xe0, 0xb5, 0xb3, 0xb8, 0x19, 0x4e, 0x0c, 0xa4, 0xd9, 0x2b, 0x3b, 0xc2, | 147 0xe0, 0xb5, 0xb3, 0xb8, 0x19, 0x4e, 0x0c, 0xa4, 0xd9, 0x2b, 0x3b, 0xc2, |
145 0xca, 0x20, 0xd3, 0x0c, 0xa4, 0xff, 0x93, 0x13, 0x1f, 0xfc, 0xba, 0x94, | 148 0xca, 0x20, 0xd3, 0x0c, 0xa4, 0xff, 0x93, 0x13, 0x1f, 0xfc, 0xba, 0x94, |
146 0x93, 0x8c, 0x64, 0x15, 0x2e, 0x28, 0xa9, 0x55, 0x8c, 0x2c, 0x48, 0xd3, | 149 0x93, 0x8c, 0x64, 0x15, 0x2e, 0x28, 0xa9, 0x55, 0x8c, 0x2c, 0x48, 0xd3, |
147 0xd3, 0xc1, 0x50, 0x69, 0x19, 0xe8, 0x34, 0xd3, 0xf1, 0x04, 0x9f, 0x0a, | 150 0xd3, 0xc1, 0x50, 0x69, 0x19, 0xe8, 0x34, 0xd3, 0xf1, 0x04, 0x9f, 0x0a, |
148 0x7a, 0x21, 0x87, 0xbf, 0xb9, 0x59, 0x37, 0x2e, 0xf4, 0x71, 0xa5, 0x3e, | 151 0x7a, 0x21, 0x87, 0xbf, 0xb9, 0x59, 0x37, 0x2e, 0xf4, 0x71, 0xa5, 0x3e, |
149 0xbe, 0xcd, 0x70, 0x83, 0x18, 0xf8, 0x8a, 0x72, 0x85, 0x45, 0x1f, 0x08, | 152 0xbe, 0xcd, 0x70, 0x83, 0x18, 0xf8, 0x8a, 0x72, 0x85, 0x45, 0x1f, 0x08, |
150 0x01, 0x6f, 0x37, 0xf5, 0x2b, 0x7b, 0xea, 0xb9, 0x8b, 0xa3, 0xcc, 0xfd, | 153 0x01, 0x6f, 0x37, 0xf5, 0x2b, 0x7b, 0xea, 0xb9, 0x8b, 0xa3, 0xcc, 0xfd, |
151 0x35, 0x52, 0xdd, 0x66, 0xde, 0x4f, 0x30, 0xc5, 0x73, 0x81, 0xb6, 0xe8, | 154 0x35, 0x52, 0xdd, 0x66, 0xde, 0x4f, 0x30, 0xc5, 0x73, 0x81, 0xb6, 0xe8, |
152 0x3c, 0xd8, 0x48, 0x8a | 155 0x3c, 0xd8, 0x48, 0x8a}; |
153 }; | |
154 | 156 |
155 // The public key is specified as the following ASN.1 structure: | 157 // The public key is specified as the following ASN.1 structure: |
156 // SubjectPublicKeyInfo ::= SEQUENCE { | 158 // SubjectPublicKeyInfo ::= SEQUENCE { |
157 // algorithm AlgorithmIdentifier, | 159 // algorithm AlgorithmIdentifier, |
158 // subjectPublicKey BIT STRING } | 160 // subjectPublicKey BIT STRING } |
159 const uint8 public_key_info[294] = { | 161 const uint8_t public_key_info[294] = { |
160 0x30, 0x82, 0x01, 0x22, // a SEQUENCE of length 290 (0x122) | 162 0x30, 0x82, 0x01, 0x22, // a SEQUENCE of length 290 (0x122) |
161 // algorithm | 163 // algorithm |
162 0x30, 0x0d, // a SEQUENCE of length 13 | 164 0x30, 0x0d, // a SEQUENCE of length 13 |
163 0x06, 0x09, // an OBJECT IDENTIFIER of length 9 | 165 0x06, 0x09, // an OBJECT IDENTIFIER of length 9 |
164 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, | 166 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, |
165 0x05, 0x00, // a NULL of length 0 | 167 0x00, // a NULL of length 0 |
166 // subjectPublicKey | 168 // subjectPublicKey |
167 0x03, 0x82, 0x01, 0x0f, // a BIT STRING of length 271 (0x10f) | 169 0x03, 0x82, 0x01, 0x0f, // a BIT STRING of length 271 (0x10f) |
168 0x00, // number of unused bits | 170 0x00, // number of unused bits |
169 0x30, 0x82, 0x01, 0x0a, // a SEQUENCE of length 266 (0x10a) | 171 0x30, 0x82, 0x01, 0x0a, // a SEQUENCE of length 266 (0x10a) |
170 // modulus | 172 // modulus |
171 0x02, 0x82, 0x01, 0x01, // an INTEGER of length 257 (0x101) | 173 0x02, 0x82, 0x01, 0x01, // an INTEGER of length 257 (0x101) |
172 0x00, 0xc4, 0x2d, 0xd5, 0x15, 0x8c, 0x9c, 0x26, 0x4c, 0xec, | 174 0x00, 0xc4, 0x2d, 0xd5, 0x15, 0x8c, 0x9c, 0x26, 0x4c, 0xec, 0x32, 0x35, |
173 0x32, 0x35, 0xeb, 0x5f, 0xb8, 0x59, 0x01, 0x5a, 0xa6, 0x61, | 175 0xeb, 0x5f, 0xb8, 0x59, 0x01, 0x5a, 0xa6, 0x61, 0x81, 0x59, 0x3b, 0x70, |
174 0x81, 0x59, 0x3b, 0x70, 0x63, 0xab, 0xe3, 0xdc, 0x3d, 0xc7, | 176 0x63, 0xab, 0xe3, 0xdc, 0x3d, 0xc7, 0x2a, 0xb8, 0xc9, 0x33, 0xd3, 0x79, |
175 0x2a, 0xb8, 0xc9, 0x33, 0xd3, 0x79, 0xe4, 0x3a, 0xed, 0x3c, | 177 0xe4, 0x3a, 0xed, 0x3c, 0x30, 0x23, 0x84, 0x8e, 0xb3, 0x30, 0x14, 0xb6, |
176 0x30, 0x23, 0x84, 0x8e, 0xb3, 0x30, 0x14, 0xb6, 0xb2, 0x87, | 178 0xb2, 0x87, 0xc3, 0x3d, 0x95, 0x54, 0x04, 0x9e, 0xdf, 0x99, 0xdd, 0x0b, |
177 0xc3, 0x3d, 0x95, 0x54, 0x04, 0x9e, 0xdf, 0x99, 0xdd, 0x0b, | 179 0x25, 0x1e, 0x21, 0xde, 0x65, 0x29, 0x7e, 0x35, 0xa8, 0xa9, 0x54, 0xeb, |
178 0x25, 0x1e, 0x21, 0xde, 0x65, 0x29, 0x7e, 0x35, 0xa8, 0xa9, | 180 0xf6, 0xf7, 0x32, 0x39, 0xd4, 0x26, 0x55, 0x95, 0xad, 0xef, 0xfb, 0xfe, |
179 0x54, 0xeb, 0xf6, 0xf7, 0x32, 0x39, 0xd4, 0x26, 0x55, 0x95, | 181 0x58, 0x86, 0xd7, 0x9e, 0xf4, 0x00, 0x8d, 0x8c, 0x2a, 0x0c, 0xbd, 0x42, |
180 0xad, 0xef, 0xfb, 0xfe, 0x58, 0x86, 0xd7, 0x9e, 0xf4, 0x00, | 182 0x04, 0xce, 0xa7, 0x3f, 0x04, 0xf6, 0xee, 0x80, 0xf2, 0xaa, 0xef, 0x52, |
181 0x8d, 0x8c, 0x2a, 0x0c, 0xbd, 0x42, 0x04, 0xce, 0xa7, 0x3f, | 183 0xa1, 0x69, 0x66, 0xda, 0xbe, 0x1a, 0xad, 0x5d, 0xda, 0x2c, 0x66, 0xea, |
182 0x04, 0xf6, 0xee, 0x80, 0xf2, 0xaa, 0xef, 0x52, 0xa1, 0x69, | 184 0x1a, 0x6b, 0xbb, 0xe5, 0x1a, 0x51, 0x4a, 0x00, 0x2f, 0x48, 0xc7, 0x98, |
183 0x66, 0xda, 0xbe, 0x1a, 0xad, 0x5d, 0xda, 0x2c, 0x66, 0xea, | 185 0x75, 0xd8, 0xb9, 0x29, 0xc8, 0xee, 0xf8, 0x66, 0x6d, 0x0a, 0x9c, 0xb3, |
184 0x1a, 0x6b, 0xbb, 0xe5, 0x1a, 0x51, 0x4a, 0x00, 0x2f, 0x48, | 186 0xf3, 0xfc, 0x78, 0x7c, 0xa2, 0xf8, 0xa3, 0xf2, 0xb5, 0xc3, 0xf3, 0xb9, |
185 0xc7, 0x98, 0x75, 0xd8, 0xb9, 0x29, 0xc8, 0xee, 0xf8, 0x66, | 187 0x7a, 0x91, 0xc1, 0xa7, 0xe6, 0x25, 0x2e, 0x9c, 0xa8, 0xed, 0x12, 0x65, |
186 0x6d, 0x0a, 0x9c, 0xb3, 0xf3, 0xfc, 0x78, 0x7c, 0xa2, 0xf8, | 188 0x6e, 0x6a, 0xf6, 0x12, 0x44, 0x53, 0x70, 0x30, 0x95, 0xc3, 0x9c, 0x2b, |
187 0xa3, 0xf2, 0xb5, 0xc3, 0xf3, 0xb9, 0x7a, 0x91, 0xc1, 0xa7, | 189 0x58, 0x2b, 0x3d, 0x08, 0x74, 0x4a, 0xf2, 0xbe, 0x51, 0xb0, 0xbf, 0x87, |
188 0xe6, 0x25, 0x2e, 0x9c, 0xa8, 0xed, 0x12, 0x65, 0x6e, 0x6a, | 190 0xd0, 0x4c, 0x27, 0x58, 0x6b, 0xb5, 0x35, 0xc5, 0x9d, 0xaf, 0x17, 0x31, |
189 0xf6, 0x12, 0x44, 0x53, 0x70, 0x30, 0x95, 0xc3, 0x9c, 0x2b, | 191 0xf8, 0x0b, 0x8f, 0xee, 0xad, 0x81, 0x36, 0x05, 0x89, 0x08, 0x98, 0xcf, |
190 0x58, 0x2b, 0x3d, 0x08, 0x74, 0x4a, 0xf2, 0xbe, 0x51, 0xb0, | 192 0x3a, 0xaf, 0x25, 0x87, 0xc0, 0x49, 0xea, 0xa7, 0xfd, 0x67, 0xf7, 0x45, |
191 0xbf, 0x87, 0xd0, 0x4c, 0x27, 0x58, 0x6b, 0xb5, 0x35, 0xc5, | 193 0x8e, 0x97, 0xcc, 0x14, 0x39, 0xe2, 0x36, 0x85, 0xb5, 0x7e, 0x1a, 0x37, |
192 0x9d, 0xaf, 0x17, 0x31, 0xf8, 0x0b, 0x8f, 0xee, 0xad, 0x81, | 194 0xfd, 0x16, 0xf6, 0x71, 0x11, 0x9a, 0x74, 0x30, 0x16, 0xfe, 0x13, 0x94, |
193 0x36, 0x05, 0x89, 0x08, 0x98, 0xcf, 0x3a, 0xaf, 0x25, 0x87, | 195 0xa3, 0x3f, 0x84, 0x0d, 0x4f, |
194 0xc0, 0x49, 0xea, 0xa7, 0xfd, 0x67, 0xf7, 0x45, 0x8e, 0x97, | 196 // public exponent |
195 0xcc, 0x14, 0x39, 0xe2, 0x36, 0x85, 0xb5, 0x7e, 0x1a, 0x37, | 197 0x02, 0x03, // an INTEGER of length 3 |
196 0xfd, 0x16, 0xf6, 0x71, 0x11, 0x9a, 0x74, 0x30, 0x16, 0xfe, | 198 0x01, 0x00, 0x01}; |
197 0x13, 0x94, 0xa3, 0x3f, 0x84, 0x0d, 0x4f, | |
198 // public exponent | |
199 0x02, 0x03, // an INTEGER of length 3 | |
200 0x01, 0x00, 0x01 | |
201 }; | |
202 | 199 |
203 // We use the signature verifier to perform four signature verification | 200 // We use the signature verifier to perform four signature verification |
204 // tests. | 201 // tests. |
205 crypto::SignatureVerifier verifier; | 202 crypto::SignatureVerifier verifier; |
206 bool ok; | 203 bool ok; |
207 | 204 |
208 // Test 1: feed all of the data to the verifier at once (a single | 205 // Test 1: feed all of the data to the verifier at once (a single |
209 // VerifyUpdate call). | 206 // VerifyUpdate call). |
210 ok = verifier.VerifyInit(signature_algorithm, | 207 ok = verifier.VerifyInit(signature_algorithm, |
211 sizeof(signature_algorithm), | 208 sizeof(signature_algorithm), |
(...skipping 11 matching lines...) Expand all Loading... |
223 signature, sizeof(signature), | 220 signature, sizeof(signature), |
224 public_key_info, sizeof(public_key_info)); | 221 public_key_info, sizeof(public_key_info)); |
225 EXPECT_TRUE(ok); | 222 EXPECT_TRUE(ok); |
226 verifier.VerifyUpdate(tbs_certificate, 256); | 223 verifier.VerifyUpdate(tbs_certificate, 256); |
227 verifier.VerifyUpdate(tbs_certificate + 256, 256); | 224 verifier.VerifyUpdate(tbs_certificate + 256, 256); |
228 verifier.VerifyUpdate(tbs_certificate + 512, sizeof(tbs_certificate) - 512); | 225 verifier.VerifyUpdate(tbs_certificate + 512, sizeof(tbs_certificate) - 512); |
229 ok = verifier.VerifyFinal(); | 226 ok = verifier.VerifyFinal(); |
230 EXPECT_TRUE(ok); | 227 EXPECT_TRUE(ok); |
231 | 228 |
232 // Test 3: verify the signature with incorrect data. | 229 // Test 3: verify the signature with incorrect data. |
233 uint8 bad_tbs_certificate[sizeof(tbs_certificate)]; | 230 uint8_t bad_tbs_certificate[sizeof(tbs_certificate)]; |
234 memcpy(bad_tbs_certificate, tbs_certificate, sizeof(tbs_certificate)); | 231 memcpy(bad_tbs_certificate, tbs_certificate, sizeof(tbs_certificate)); |
235 bad_tbs_certificate[10] += 1; // Corrupt one byte of the data. | 232 bad_tbs_certificate[10] += 1; // Corrupt one byte of the data. |
236 ok = verifier.VerifyInit(signature_algorithm, | 233 ok = verifier.VerifyInit(signature_algorithm, |
237 sizeof(signature_algorithm), | 234 sizeof(signature_algorithm), |
238 signature, sizeof(signature), | 235 signature, sizeof(signature), |
239 public_key_info, sizeof(public_key_info)); | 236 public_key_info, sizeof(public_key_info)); |
240 EXPECT_TRUE(ok); | 237 EXPECT_TRUE(ok); |
241 verifier.VerifyUpdate(bad_tbs_certificate, sizeof(bad_tbs_certificate)); | 238 verifier.VerifyUpdate(bad_tbs_certificate, sizeof(bad_tbs_certificate)); |
242 ok = verifier.VerifyFinal(); | 239 ok = verifier.VerifyFinal(); |
243 EXPECT_FALSE(ok); | 240 EXPECT_FALSE(ok); |
244 | 241 |
245 // Test 4: verify a bad signature. | 242 // Test 4: verify a bad signature. |
246 uint8 bad_signature[sizeof(signature)]; | 243 uint8_t bad_signature[sizeof(signature)]; |
247 memcpy(bad_signature, signature, sizeof(signature)); | 244 memcpy(bad_signature, signature, sizeof(signature)); |
248 bad_signature[10] += 1; // Corrupt one byte of the signature. | 245 bad_signature[10] += 1; // Corrupt one byte of the signature. |
249 ok = verifier.VerifyInit(signature_algorithm, | 246 ok = verifier.VerifyInit(signature_algorithm, |
250 sizeof(signature_algorithm), | 247 sizeof(signature_algorithm), |
251 bad_signature, sizeof(bad_signature), | 248 bad_signature, sizeof(bad_signature), |
252 public_key_info, sizeof(public_key_info)); | 249 public_key_info, sizeof(public_key_info)); |
253 | 250 |
254 // A crypto library (e.g., NSS) may detect that the signature is corrupted | 251 // A crypto library (e.g., NSS) may detect that the signature is corrupted |
255 // and cause VerifyInit to return false, so it is fine for 'ok' to be false. | 252 // and cause VerifyInit to return false, so it is fine for 'ok' to be false. |
256 if (ok) { | 253 if (ok) { |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 { message_10_1, salt_10_1, signature_10_1 }, | 970 { message_10_1, salt_10_1, signature_10_1 }, |
974 { message_10_2, salt_10_2, signature_10_2 }, | 971 { message_10_2, salt_10_2, signature_10_2 }, |
975 { message_10_3, salt_10_3, signature_10_3 }, | 972 { message_10_3, salt_10_3, signature_10_3 }, |
976 { message_10_4, salt_10_4, signature_10_4 }, | 973 { message_10_4, salt_10_4, signature_10_4 }, |
977 { message_10_5, salt_10_5, signature_10_5 }, | 974 { message_10_5, salt_10_5, signature_10_5 }, |
978 { message_10_6, salt_10_6, signature_10_6 }, | 975 { message_10_6, salt_10_6, signature_10_6 }, |
979 } | 976 } |
980 }, | 977 }, |
981 }; | 978 }; |
982 | 979 |
983 static uint8 HexDigitValue(char digit) { | 980 static uint8_t HexDigitValue(char digit) { |
984 if ('0' <= digit && digit <= '9') | 981 if ('0' <= digit && digit <= '9') |
985 return digit - '0'; | 982 return digit - '0'; |
986 if ('a' <= digit && digit <= 'f') | 983 if ('a' <= digit && digit <= 'f') |
987 return digit - 'a' + 10; | 984 return digit - 'a' + 10; |
988 return digit - 'A' + 10; | 985 return digit - 'A' + 10; |
989 } | 986 } |
990 | 987 |
991 static bool DecodeTestInput(const char* in, std::vector<uint8>* out) { | 988 static bool DecodeTestInput(const char* in, std::vector<uint8_t>* out) { |
992 out->clear(); | 989 out->clear(); |
993 while (in[0] != '\0') { | 990 while (in[0] != '\0') { |
994 if (!isxdigit(in[0]) || !isxdigit(in[1]) || in[2] != ' ') | 991 if (!isxdigit(in[0]) || !isxdigit(in[1]) || in[2] != ' ') |
995 return false; | 992 return false; |
996 uint8 octet = HexDigitValue(in[0]) * 16 + HexDigitValue(in[1]); | 993 uint8_t octet = HexDigitValue(in[0]) * 16 + HexDigitValue(in[1]); |
997 out->push_back(octet); | 994 out->push_back(octet); |
998 in += 3; | 995 in += 3; |
999 } | 996 } |
1000 return true; | 997 return true; |
1001 } | 998 } |
1002 | 999 |
1003 // PrependASN1Length prepends an ASN.1 serialized length to the beginning of | 1000 // PrependASN1Length prepends an ASN.1 serialized length to the beginning of |
1004 // |out|. | 1001 // |out|. |
1005 static void PrependASN1Length(std::vector<uint8>* out, size_t len) { | 1002 static void PrependASN1Length(std::vector<uint8_t>* out, size_t len) { |
1006 if (len < 128) { | 1003 if (len < 128) { |
1007 out->insert(out->begin(), static_cast<uint8>(len)); | 1004 out->insert(out->begin(), static_cast<uint8_t>(len)); |
1008 } else if (len < 256) { | 1005 } else if (len < 256) { |
1009 out->insert(out->begin(), static_cast<uint8>(len)); | 1006 out->insert(out->begin(), static_cast<uint8_t>(len)); |
1010 out->insert(out->begin(), 0x81); | 1007 out->insert(out->begin(), 0x81); |
1011 } else if (len < 0x10000) { | 1008 } else if (len < 0x10000) { |
1012 out->insert(out->begin(), static_cast<uint8>(len)); | 1009 out->insert(out->begin(), static_cast<uint8_t>(len)); |
1013 out->insert(out->begin(), static_cast<uint8>(len >> 8)); | 1010 out->insert(out->begin(), static_cast<uint8_t>(len >> 8)); |
1014 out->insert(out->begin(), 0x82); | 1011 out->insert(out->begin(), 0x82); |
1015 } else { | 1012 } else { |
1016 CHECK(false) << "ASN.1 length not handled: " << len; | 1013 CHECK(false) << "ASN.1 length not handled: " << len; |
1017 } | 1014 } |
1018 } | 1015 } |
1019 | 1016 |
1020 static bool EncodeRSAPublicKey(const std::vector<uint8>& modulus_n, | 1017 static bool EncodeRSAPublicKey(const std::vector<uint8_t>& modulus_n, |
1021 const std::vector<uint8>& public_exponent_e, | 1018 const std::vector<uint8_t>& public_exponent_e, |
1022 std::vector<uint8>* public_key_info) { | 1019 std::vector<uint8_t>* public_key_info) { |
1023 // The public key is specified as the following ASN.1 structure: | 1020 // The public key is specified as the following ASN.1 structure: |
1024 // SubjectPublicKeyInfo ::= SEQUENCE { | 1021 // SubjectPublicKeyInfo ::= SEQUENCE { |
1025 // algorithm AlgorithmIdentifier, | 1022 // algorithm AlgorithmIdentifier, |
1026 // subjectPublicKey BIT STRING } | 1023 // subjectPublicKey BIT STRING } |
1027 // | 1024 // |
1028 // The signature algorithm is specified as the following ASN.1 structure: | 1025 // The signature algorithm is specified as the following ASN.1 structure: |
1029 // AlgorithmIdentifier ::= SEQUENCE { | 1026 // AlgorithmIdentifier ::= SEQUENCE { |
1030 // algorithm OBJECT IDENTIFIER, | 1027 // algorithm OBJECT IDENTIFIER, |
1031 // parameters ANY DEFINED BY algorithm OPTIONAL } | 1028 // parameters ANY DEFINED BY algorithm OPTIONAL } |
1032 // | 1029 // |
1033 // An RSA public key is specified as the following ASN.1 structure: | 1030 // An RSA public key is specified as the following ASN.1 structure: |
1034 // RSAPublicKey ::= SEQUENCE { | 1031 // RSAPublicKey ::= SEQUENCE { |
1035 // modulus INTEGER, -- n | 1032 // modulus INTEGER, -- n |
1036 // publicExponent INTEGER -- e | 1033 // publicExponent INTEGER -- e |
1037 // } | 1034 // } |
1038 static const uint8 kIntegerTag = 0x02; | 1035 static const uint8_t kIntegerTag = 0x02; |
1039 static const uint8 kBitStringTag = 0x03; | 1036 static const uint8_t kBitStringTag = 0x03; |
1040 static const uint8 kSequenceTag = 0x30; | 1037 static const uint8_t kSequenceTag = 0x30; |
1041 public_key_info->clear(); | 1038 public_key_info->clear(); |
1042 | 1039 |
1043 // Encode the public exponent e as an INTEGER. | 1040 // Encode the public exponent e as an INTEGER. |
1044 public_key_info->insert(public_key_info->begin(), | 1041 public_key_info->insert(public_key_info->begin(), |
1045 public_exponent_e.begin(), | 1042 public_exponent_e.begin(), |
1046 public_exponent_e.end()); | 1043 public_exponent_e.end()); |
1047 PrependASN1Length(public_key_info, public_exponent_e.size()); | 1044 PrependASN1Length(public_key_info, public_exponent_e.size()); |
1048 public_key_info->insert(public_key_info->begin(), kIntegerTag); | 1045 public_key_info->insert(public_key_info->begin(), kIntegerTag); |
1049 | 1046 |
1050 // Encode the modulus n as an INTEGER. | 1047 // Encode the modulus n as an INTEGER. |
(...skipping 11 matching lines...) Expand all Loading... |
1062 PrependASN1Length(public_key_info, public_key_info->size()); | 1059 PrependASN1Length(public_key_info, public_key_info->size()); |
1063 public_key_info->insert(public_key_info->begin(), kSequenceTag); | 1060 public_key_info->insert(public_key_info->begin(), kSequenceTag); |
1064 | 1061 |
1065 // Encode the BIT STRING. | 1062 // Encode the BIT STRING. |
1066 // Number of unused bits. | 1063 // Number of unused bits. |
1067 public_key_info->insert(public_key_info->begin(), 0x00); | 1064 public_key_info->insert(public_key_info->begin(), 0x00); |
1068 PrependASN1Length(public_key_info, public_key_info->size()); | 1065 PrependASN1Length(public_key_info, public_key_info->size()); |
1069 public_key_info->insert(public_key_info->begin(), kBitStringTag); | 1066 public_key_info->insert(public_key_info->begin(), kBitStringTag); |
1070 | 1067 |
1071 // Encode the AlgorithmIdentifier. | 1068 // Encode the AlgorithmIdentifier. |
1072 static const uint8 algorithm[] = { | 1069 static const uint8_t algorithm[] = { |
1073 0x30, 0x0d, // a SEQUENCE of length 13 | 1070 0x30, 0x0d, // a SEQUENCE of length 13 |
1074 0x06, 0x09, // an OBJECT IDENTIFIER of length 9 | 1071 0x06, 0x09, // an OBJECT IDENTIFIER of length 9 |
1075 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, | 1072 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, |
1076 0x05, 0x00, | |
1077 }; | 1073 }; |
1078 public_key_info->insert(public_key_info->begin(), | 1074 public_key_info->insert(public_key_info->begin(), |
1079 algorithm, algorithm + sizeof(algorithm)); | 1075 algorithm, algorithm + sizeof(algorithm)); |
1080 | 1076 |
1081 // Encode the outermost SEQUENCE. | 1077 // Encode the outermost SEQUENCE. |
1082 PrependASN1Length(public_key_info, public_key_info->size()); | 1078 PrependASN1Length(public_key_info, public_key_info->size()); |
1083 public_key_info->insert(public_key_info->begin(), kSequenceTag); | 1079 public_key_info->insert(public_key_info->begin(), kSequenceTag); |
1084 | 1080 |
1085 return true; | 1081 return true; |
1086 } | 1082 } |
1087 | 1083 |
1088 TEST(SignatureVerifierTest, VerifyRSAPSS) { | 1084 TEST(SignatureVerifierTest, VerifyRSAPSS) { |
1089 for (unsigned int i = 0; i < arraysize(pss_test); i++) { | 1085 for (unsigned int i = 0; i < arraysize(pss_test); i++) { |
1090 SCOPED_TRACE(i); | 1086 SCOPED_TRACE(i); |
1091 std::vector<uint8> modulus_n; | 1087 std::vector<uint8_t> modulus_n; |
1092 std::vector<uint8> public_exponent_e; | 1088 std::vector<uint8_t> public_exponent_e; |
1093 ASSERT_TRUE(DecodeTestInput(pss_test[i].modulus_n, &modulus_n)); | 1089 ASSERT_TRUE(DecodeTestInput(pss_test[i].modulus_n, &modulus_n)); |
1094 ASSERT_TRUE(DecodeTestInput(pss_test[i].public_exponent_e, | 1090 ASSERT_TRUE(DecodeTestInput(pss_test[i].public_exponent_e, |
1095 &public_exponent_e)); | 1091 &public_exponent_e)); |
1096 std::vector<uint8> public_key_info; | 1092 std::vector<uint8_t> public_key_info; |
1097 ASSERT_TRUE(EncodeRSAPublicKey(modulus_n, public_exponent_e, | 1093 ASSERT_TRUE(EncodeRSAPublicKey(modulus_n, public_exponent_e, |
1098 &public_key_info)); | 1094 &public_key_info)); |
1099 | 1095 |
1100 for (unsigned int j = 0; j < arraysize(pss_test[i].example); j++) { | 1096 for (unsigned int j = 0; j < arraysize(pss_test[i].example); j++) { |
1101 SCOPED_TRACE(j); | 1097 SCOPED_TRACE(j); |
1102 std::vector<uint8> message; | 1098 std::vector<uint8_t> message; |
1103 std::vector<uint8> salt; | 1099 std::vector<uint8_t> salt; |
1104 std::vector<uint8> signature; | 1100 std::vector<uint8_t> signature; |
1105 ASSERT_TRUE(DecodeTestInput(pss_test[i].example[j].message, &message)); | 1101 ASSERT_TRUE(DecodeTestInput(pss_test[i].example[j].message, &message)); |
1106 ASSERT_TRUE(DecodeTestInput(pss_test[i].example[j].salt, &salt)); | 1102 ASSERT_TRUE(DecodeTestInput(pss_test[i].example[j].salt, &salt)); |
1107 ASSERT_TRUE(DecodeTestInput(pss_test[i].example[j].signature, | 1103 ASSERT_TRUE(DecodeTestInput(pss_test[i].example[j].signature, |
1108 &signature)); | 1104 &signature)); |
1109 | 1105 |
1110 crypto::SignatureVerifier verifier; | 1106 crypto::SignatureVerifier verifier; |
1111 bool ok; | 1107 bool ok; |
1112 | 1108 |
1113 // Positive test. | 1109 // Positive test. |
1114 ok = verifier.VerifyInitRSAPSS(crypto::SignatureVerifier::SHA1, | 1110 ok = verifier.VerifyInitRSAPSS(crypto::SignatureVerifier::SHA1, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 &public_key_info[0], | 1154 &public_key_info[0], |
1159 public_key_info.size()); | 1155 public_key_info.size()); |
1160 signature[0] -= 1; | 1156 signature[0] -= 1; |
1161 ASSERT_TRUE(ok); | 1157 ASSERT_TRUE(ok); |
1162 verifier.VerifyUpdate(&message[0], message.size()); | 1158 verifier.VerifyUpdate(&message[0], message.size()); |
1163 ok = verifier.VerifyFinal(); | 1159 ok = verifier.VerifyFinal(); |
1164 EXPECT_FALSE(ok); | 1160 EXPECT_FALSE(ok); |
1165 } | 1161 } |
1166 } | 1162 } |
1167 } | 1163 } |
OLD | NEW |