OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ec_signature_creator.h" | 5 #include "crypto/ec_signature_creator.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 29 matching lines...) Expand all Loading... |
40 ASSERT_TRUE(signer.get()); | 40 ASSERT_TRUE(signer.get()); |
41 | 41 |
42 std::string data("Hello, World!"); | 42 std::string data("Hello, World!"); |
43 std::vector<uint8_t> signature; | 43 std::vector<uint8_t> signature; |
44 ASSERT_TRUE(signer->Sign(reinterpret_cast<const uint8_t*>(data.c_str()), | 44 ASSERT_TRUE(signer->Sign(reinterpret_cast<const uint8_t*>(data.c_str()), |
45 data.size(), &signature)); | 45 data.size(), &signature)); |
46 | 46 |
47 std::vector<uint8_t> public_key_info; | 47 std::vector<uint8_t> public_key_info; |
48 ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info)); | 48 ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info)); |
49 | 49 |
50 // This is the algorithm ID for ECDSA with SHA-256. Parameters are ABSENT. | |
51 // RFC 5758: | |
52 // ecdsa-with-SHA256 OBJECT IDENTIFIER ::= { iso(1) member-body(2) | |
53 // us(840) ansi-X9-62(10045) signatures(4) ecdsa-with-SHA2(3) 2 } | |
54 // ... | |
55 // When the ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with-SHA384, or | |
56 // ecdsa-with-SHA512 algorithm identifier appears in the algorithm field | |
57 // as an AlgorithmIdentifier, the encoding MUST omit the parameters | |
58 // field. That is, the AlgorithmIdentifier SHALL be a SEQUENCE of one | |
59 // component, the OID ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with- | |
60 // SHA384, or ecdsa-with-SHA512. | |
61 // See also RFC 5480, Appendix A. | |
62 const uint8_t kECDSAWithSHA256AlgorithmID[] = { | |
63 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, | |
64 }; | |
65 crypto::SignatureVerifier verifier; | 50 crypto::SignatureVerifier verifier; |
66 ASSERT_TRUE(verifier.VerifyInit( | 51 ASSERT_TRUE(verifier.VerifyInit( |
67 kECDSAWithSHA256AlgorithmID, sizeof(kECDSAWithSHA256AlgorithmID), | 52 crypto::SignatureVerifier::ECDSA_SHA256, &signature[0], signature.size(), |
68 &signature[0], signature.size(), | |
69 &public_key_info.front(), public_key_info.size())); | 53 &public_key_info.front(), public_key_info.size())); |
70 | 54 |
71 verifier.VerifyUpdate(reinterpret_cast<const uint8_t*>(data.c_str()), | 55 verifier.VerifyUpdate(reinterpret_cast<const uint8_t*>(data.c_str()), |
72 data.size()); | 56 data.size()); |
73 ASSERT_TRUE(verifier.VerifyFinal()); | 57 ASSERT_TRUE(verifier.VerifyFinal()); |
74 } | 58 } |
OLD | NEW |