/src/mozilla-central/security/pkix/test/lib/pkixtestalg.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This code is made available to you under your choice of the following sets |
4 | | * of licensing terms: |
5 | | */ |
6 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
7 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
8 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
9 | | */ |
10 | | /* Copyright 2015 Mozilla Contributors |
11 | | * |
12 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
13 | | * you may not use this file except in compliance with the License. |
14 | | * You may obtain a copy of the License at |
15 | | * |
16 | | * http://www.apache.org/licenses/LICENSE-2.0 |
17 | | * |
18 | | * Unless required by applicable law or agreed to in writing, software |
19 | | * distributed under the License is distributed on an "AS IS" BASIS, |
20 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
21 | | * See the License for the specific language governing permissions and |
22 | | * limitations under the License. |
23 | | */ |
24 | | |
25 | | #include "pkixtestutil.h" |
26 | | |
27 | | #include "pkixder.h" |
28 | | |
29 | | // python DottedOIDToCode.py --prefixdefine PREFIX_1_2_840_10040 1.2.840.10040 |
30 | 0 | #define PREFIX_1_2_840_10040 0x2a, 0x86, 0x48, 0xce, 0x38 |
31 | | |
32 | | // python DottedOIDToCode.py --prefixdefine PREFIX_1_2_840_10045 1.2.840.10045 |
33 | | #define PREFIX_1_2_840_10045 0x2a, 0x86, 0x48, 0xce, 0x3d |
34 | | |
35 | | // python DottedOIDToCode.py --prefixdefine PREFIX_1_2_840_113549 1.2.840.113549 |
36 | 114 | #define PREFIX_1_2_840_113549 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d |
37 | | |
38 | | namespace mozilla { namespace pkix { namespace test { |
39 | | |
40 | | namespace { |
41 | | |
42 | | enum class NULLParam { NO, YES }; |
43 | | |
44 | | template <size_t SIZE> |
45 | | ByteString |
46 | | OID(const uint8_t (&rawValue)[SIZE]) |
47 | 114 | { |
48 | 114 | return TLV(der::OIDTag, ByteString(rawValue, SIZE)); |
49 | 114 | } Unexecuted instantiation: pkixtestalg.cpp:std::__1::basic_string<unsigned char, std::__1::char_traits<unsigned char>, std::__1::allocator<unsigned char> > mozilla::pkix::test::(anonymous namespace)::OID<7ul>(unsigned char const (&) [7ul]) pkixtestalg.cpp:std::__1::basic_string<unsigned char, std::__1::char_traits<unsigned char>, std::__1::allocator<unsigned char> > mozilla::pkix::test::(anonymous namespace)::OID<9ul>(unsigned char const (&) [9ul]) Line | Count | Source | 47 | 114 | { | 48 | 114 | return TLV(der::OIDTag, ByteString(rawValue, SIZE)); | 49 | 114 | } |
|
50 | | |
51 | | template <size_t SIZE> |
52 | | ByteString |
53 | | SimpleAlgID(const uint8_t (&rawValue)[SIZE], |
54 | | NULLParam nullParam = NULLParam::NO) |
55 | 114 | { |
56 | 114 | ByteString sequenceValue(OID(rawValue)); |
57 | 114 | if (nullParam == NULLParam::YES) { |
58 | 57 | sequenceValue.append(TLV(der::NULLTag, ByteString())); |
59 | 57 | } |
60 | 114 | return TLV(der::SEQUENCE, sequenceValue); |
61 | 114 | } |
62 | | |
63 | | template <size_t SIZE> |
64 | | ByteString |
65 | | DERInteger(const uint8_t (&rawValue)[SIZE]) |
66 | 0 | { |
67 | 0 | ByteString value(rawValue, SIZE); |
68 | 0 | if (value[0] & 0x80u) { |
69 | 0 | // Prefix with a leading zero to disambiguate this from a negative value. |
70 | 0 | value.insert(value.begin(), 0x00); |
71 | 0 | } |
72 | 0 | return TLV(der::INTEGER, value); |
73 | 0 | } Unexecuted instantiation: pkixtestalg.cpp:std::__1::basic_string<unsigned char, std::__1::char_traits<unsigned char>, std::__1::allocator<unsigned char> > mozilla::pkix::test::(anonymous namespace)::DERInteger<256ul>(unsigned char const (&) [256ul]) Unexecuted instantiation: pkixtestalg.cpp:std::__1::basic_string<unsigned char, std::__1::char_traits<unsigned char>, std::__1::allocator<unsigned char> > mozilla::pkix::test::(anonymous namespace)::DERInteger<32ul>(unsigned char const (&) [32ul]) |
74 | | |
75 | | // Generated with "openssl dsaparam -C -noout 2048" and reformatted. |
76 | | // openssl 1.0 or later must be used so that a 256-bit Q value is |
77 | | // generated. |
78 | | static const uint8_t DSS_P_RAW[] = |
79 | | { |
80 | | 0xB3,0xCD,0x29,0x44,0xF0,0x25,0xA7,0x73,0xFC,0x86,0x70,0xA2, |
81 | | 0x69,0x5A,0x97,0x3F,0xBD,0x1C,0x6F,0xAA,0x4A,0x40,0x42,0x8E, |
82 | | 0xCF,0xAE,0x62,0x12,0xED,0xB4,0xFD,0x05,0xC2,0xAE,0xB1,0x8C, |
83 | | 0xFC,0xBE,0x38,0x90,0xBB,0x7C,0xFF,0x16,0xF4,0xED,0xCE,0x72, |
84 | | 0x12,0x93,0x83,0xF0,0xA4,0xA1,0x71,0xDC,0x4B,0xF0,0x4E,0x3A, |
85 | | 0x2B,0xFA,0x17,0xB7,0xB3,0x2A,0xCC,0x2C,0xD3,0xC8,0x21,0x49, |
86 | | 0x7A,0x83,0x71,0x8B,0x3D,0x62,0x96,0xDC,0xAD,0xA8,0x03,0xBE, |
87 | | 0x1D,0x33,0x11,0xF3,0xEB,0xD8,0x1B,0x8D,0xDB,0x62,0x79,0x83, |
88 | | 0xF8,0x67,0x4E,0x62,0x21,0x2C,0x81,0x59,0xE8,0x73,0xD7,0xAF, |
89 | | 0xB9,0x63,0x60,0xEA,0xAE,0xEC,0x68,0x6A,0xB4,0xB0,0x65,0xBA, |
90 | | 0xA3,0x4C,0x09,0x99,0x29,0x6A,0x2E,0x2B,0xFC,0x6D,0x51,0xCA, |
91 | | 0x30,0xA2,0x2F,0x7A,0x65,0x76,0xA7,0x55,0x13,0x11,0xA0,0x02, |
92 | | 0xA2,0x59,0x4B,0xCE,0xA7,0x05,0xF6,0x07,0x35,0x9B,0x41,0xD7, |
93 | | 0x11,0x5A,0x18,0x57,0xA7,0x78,0x88,0xC3,0xA8,0xE3,0x39,0xF5, |
94 | | 0x47,0x3D,0x2E,0x18,0x54,0xB0,0xF0,0xBF,0x65,0x3F,0x77,0xC7, |
95 | | 0x11,0xB8,0x0D,0x52,0xAD,0xC8,0xE8,0x6D,0xF6,0x7E,0x88,0x65, |
96 | | 0x84,0x2B,0xF7,0xEF,0x8E,0xB5,0x7C,0xBD,0x2E,0x0D,0xF3,0xC6, |
97 | | 0xDD,0x0B,0xB4,0xF2,0x23,0x1F,0xDA,0x55,0x05,0xF5,0xDC,0x53, |
98 | | 0xA6,0x83,0xDA,0x5C,0xEF,0x29,0x02,0x78,0x68,0xD0,0xA4,0x39, |
99 | | 0x09,0x7F,0xFA,0x49,0x18,0xD0,0xB5,0x19,0x35,0x31,0x8E,0xDE, |
100 | | 0x43,0x35,0xA3,0xB9,0x6D,0xC1,0x70,0xC6,0x0D,0x18,0x24,0xEB, |
101 | | 0x1E,0x4D,0x52,0xB7, |
102 | | }; |
103 | | |
104 | | static const uint8_t DSS_Q_RAW[] = |
105 | | { |
106 | | 0x8D,0x6B,0x86,0x89,0x9C,0x8D,0x30,0x91,0xCC,0x6E,0x34,0xF1, |
107 | | 0xE8,0x9C,0x8A,0x5C,0xD6,0xAB,0x01,0x1E,0xC4,0xDB,0xFD,0x07, |
108 | | 0xEB,0x5F,0x4E,0xE8,0xFA,0xFC,0x98,0x2D, |
109 | | }; |
110 | | |
111 | | static const uint8_t DSS_G_RAW[] = |
112 | | { |
113 | | 0x0E,0x2C,0x34,0xB2,0xE1,0x66,0x49,0xB6,0x9A,0x7D,0x67,0x3E, |
114 | | 0xEE,0x98,0x35,0x18,0x28,0x35,0xFC,0x05,0x36,0x3B,0x94,0xE6, |
115 | | 0x1E,0x1C,0x5B,0x05,0x3E,0x86,0x1B,0xE3,0xED,0xD2,0xE1,0xF3, |
116 | | 0xF7,0xF7,0x60,0x6D,0x7D,0xA1,0xAF,0x9A,0xD1,0xDF,0xA2,0x9C, |
117 | | 0xFC,0xA2,0xEB,0x90,0x8B,0x1C,0x82,0x92,0x45,0x7B,0x30,0x2A, |
118 | | 0xFD,0x7A,0xE6,0x68,0x8F,0xEC,0x89,0x3A,0x9A,0xAD,0xFE,0x25, |
119 | | 0x5E,0x51,0xC5,0x29,0x45,0x7F,0xAC,0xDE,0xFC,0xB4,0x1B,0x3A, |
120 | | 0xDA,0xC7,0x21,0x68,0x87,0x27,0x8D,0x7B,0xB2,0xBB,0x41,0x60, |
121 | | 0x46,0x42,0x5B,0x6B,0xE8,0x80,0xD2,0xE4,0xA3,0x30,0x8F,0xD5, |
122 | | 0x71,0x07,0x8A,0x7B,0x32,0x56,0x84,0x41,0x1C,0xDF,0x69,0xE9, |
123 | | 0xFD,0xBA,0x48,0xE0,0x43,0xA0,0x38,0x92,0x12,0xF3,0x52,0xA5, |
124 | | 0x40,0x87,0xCB,0x34,0xBB,0x3E,0x25,0x29,0x3C,0xC6,0xA5,0x17, |
125 | | 0xFD,0x58,0x47,0x89,0xDB,0x9B,0xB9,0xCF,0xE9,0xA8,0xF2,0xEC, |
126 | | 0x55,0x76,0xF5,0xF1,0x9C,0x6E,0x0A,0x3F,0x16,0x5F,0x49,0x31, |
127 | | 0x31,0x1C,0x43,0xA2,0x83,0xDA,0xDD,0x7F,0x1C,0xEA,0x05,0x36, |
128 | | 0x7B,0xED,0x09,0xFB,0x6F,0x8A,0x2B,0x55,0xB9,0xBC,0x4A,0x8C, |
129 | | 0x28,0xC1,0x4D,0x13,0x6E,0x47,0xF4,0xAD,0x79,0x00,0xE9,0x5A, |
130 | | 0xB6,0xC7,0x73,0x28,0xA9,0x89,0xAD,0xE8,0x6E,0xC6,0x54,0xA5, |
131 | | 0x56,0x2D,0xAA,0x81,0x83,0x9E,0xC1,0x13,0x79,0xA4,0x12,0xE0, |
132 | | 0x76,0x1F,0x25,0x43,0xB6,0xDE,0x56,0xF7,0x52,0xCC,0x07,0xB8, |
133 | | 0x37,0xE2,0x8C,0xC5,0x56,0x8C,0xDD,0x63,0xF5,0xB6,0xA3,0x46, |
134 | | 0x62,0xF6,0x35,0x76, |
135 | | }; |
136 | | |
137 | | } // namespace |
138 | | |
139 | | TestSignatureAlgorithm::TestSignatureAlgorithm( |
140 | | const TestPublicKeyAlgorithm& aPublicKeyAlg, |
141 | | TestDigestAlgorithmID aDigestAlg, |
142 | | const ByteString& aAlgorithmIdentifier, |
143 | | bool aAccepted) |
144 | | : publicKeyAlg(aPublicKeyAlg) |
145 | | , digestAlg(aDigestAlg) |
146 | | , algorithmIdentifier(aAlgorithmIdentifier) |
147 | | , accepted(aAccepted) |
148 | 60 | { |
149 | 60 | } |
150 | | |
151 | 0 | ByteString DSS_P() { return ByteString(DSS_P_RAW, sizeof(DSS_P_RAW)); } |
152 | 0 | ByteString DSS_Q() { return ByteString(DSS_Q_RAW, sizeof(DSS_Q_RAW)); } |
153 | 0 | ByteString DSS_G() { return ByteString(DSS_G_RAW, sizeof(DSS_G_RAW)); } |
154 | | |
155 | | TestPublicKeyAlgorithm |
156 | | DSS() |
157 | 0 | { |
158 | 0 | static const uint8_t oidValue[] = { PREFIX_1_2_840_10040, 4, 1 }; |
159 | 0 |
|
160 | 0 | // RFC 3279 Section-2.3.2 |
161 | 0 | return TestPublicKeyAlgorithm( |
162 | 0 | TLV(der::SEQUENCE, |
163 | 0 | OID(oidValue) + |
164 | 0 | TLV(der::SEQUENCE, |
165 | 0 | DERInteger(DSS_P_RAW) + |
166 | 0 | DERInteger(DSS_Q_RAW) + |
167 | 0 | DERInteger(DSS_G_RAW)))); |
168 | 0 | } |
169 | | |
170 | | // RFC 3279 Section 2.3.1 |
171 | | TestPublicKeyAlgorithm |
172 | | RSA_PKCS1() |
173 | 57 | { |
174 | 57 | static const uint8_t rsaEncryption[] = { PREFIX_1_2_840_113549, 1, 1, 1 }; |
175 | 57 | return TestPublicKeyAlgorithm(SimpleAlgID(rsaEncryption, NULLParam::YES)); |
176 | 57 | } |
177 | | |
178 | | // RFC 3279 Section 2.2.1 |
179 | | TestSignatureAlgorithm md2WithRSAEncryption() |
180 | 15 | { |
181 | 15 | static const uint8_t oidValue[] = { PREFIX_1_2_840_113549, 1, 1, 2 }; |
182 | 15 | return TestSignatureAlgorithm(RSA_PKCS1(), TestDigestAlgorithmID::MD2, |
183 | 15 | SimpleAlgID(oidValue), false); |
184 | 15 | } |
185 | | |
186 | | // RFC 3279 Section 2.2.1 |
187 | | TestSignatureAlgorithm md5WithRSAEncryption() |
188 | 15 | { |
189 | 15 | static const uint8_t oidValue[] = { PREFIX_1_2_840_113549, 1, 1, 4 }; |
190 | 15 | return TestSignatureAlgorithm(RSA_PKCS1(), TestDigestAlgorithmID::MD5, |
191 | 15 | SimpleAlgID(oidValue), false); |
192 | 15 | } |
193 | | |
194 | | // RFC 3279 Section 2.2.1 |
195 | | TestSignatureAlgorithm sha1WithRSAEncryption() |
196 | 0 | { |
197 | 0 | static const uint8_t oidValue[] = { PREFIX_1_2_840_113549, 1, 1, 5 }; |
198 | 0 | return TestSignatureAlgorithm(RSA_PKCS1(), TestDigestAlgorithmID::SHA1, |
199 | 0 | SimpleAlgID(oidValue), true); |
200 | 0 | } |
201 | | |
202 | | // RFC 4055 Section 5 |
203 | | TestSignatureAlgorithm sha256WithRSAEncryption() |
204 | 27 | { |
205 | 27 | static const uint8_t oidValue[] = { PREFIX_1_2_840_113549, 1, 1, 11 }; |
206 | 27 | return TestSignatureAlgorithm(RSA_PKCS1(), TestDigestAlgorithmID::SHA256, |
207 | 27 | SimpleAlgID(oidValue), true); |
208 | 27 | } |
209 | | |
210 | | } } } // namespace mozilla::pkix |