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 <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 std::string data("Hello, World!"); | 48 std::string data("Hello, World!"); |
49 std::vector<uint8> signature; | 49 std::vector<uint8> signature; |
50 ASSERT_TRUE(signer->Sign(reinterpret_cast<const uint8*>(data.c_str()), | 50 ASSERT_TRUE(signer->Sign(reinterpret_cast<const uint8*>(data.c_str()), |
51 data.size(), | 51 data.size(), |
52 &signature)); | 52 &signature)); |
53 | 53 |
54 std::vector<uint8> public_key_info; | 54 std::vector<uint8> public_key_info; |
55 ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info)); | 55 ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info)); |
56 | 56 |
57 // This is the algorithm ID for SHA-256 with EC encryption. | 57 // This is the algorithm ID for ECDSA with SHA-256. Parameters are ABSENT. |
| 58 // RFC 5758: |
| 59 // ecdsa-with-SHA256 OBJECT IDENTIFIER ::= { iso(1) member-body(2) |
| 60 // us(840) ansi-X9-62(10045) signatures(4) ecdsa-with-SHA2(3) 2 } |
| 61 // ... |
| 62 // When the ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with-SHA384, or |
| 63 // ecdsa-with-SHA512 algorithm identifier appears in the algorithm field |
| 64 // as an AlgorithmIdentifier, the encoding MUST omit the parameters |
| 65 // field. That is, the AlgorithmIdentifier SHALL be a SEQUENCE of one |
| 66 // component, the OID ecdsa-with-SHA224, ecdsa-with-SHA256, ecdsa-with- |
| 67 // SHA384, or ecdsa-with-SHA512. |
| 68 // See also RFC 5480, Appendix A. |
58 const uint8 kECDSAWithSHA256AlgorithmID[] = { | 69 const uint8 kECDSAWithSHA256AlgorithmID[] = { |
59 0x30, 0x0c, | 70 0x30, 0x0a, |
60 0x06, 0x08, | 71 0x06, 0x08, |
61 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, | 72 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, |
62 0x05, 0x00 | |
63 }; | 73 }; |
64 crypto::SignatureVerifier verifier; | 74 crypto::SignatureVerifier verifier; |
65 ASSERT_TRUE(verifier.VerifyInit( | 75 ASSERT_TRUE(verifier.VerifyInit( |
66 kECDSAWithSHA256AlgorithmID, sizeof(kECDSAWithSHA256AlgorithmID), | 76 kECDSAWithSHA256AlgorithmID, sizeof(kECDSAWithSHA256AlgorithmID), |
67 &signature[0], signature.size(), | 77 &signature[0], signature.size(), |
68 &public_key_info.front(), public_key_info.size())); | 78 &public_key_info.front(), public_key_info.size())); |
69 | 79 |
70 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), | 80 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), |
71 data.size()); | 81 data.size()); |
72 ASSERT_TRUE(verifier.VerifyFinal()); | 82 ASSERT_TRUE(verifier.VerifyFinal()); |
73 } | 83 } |
74 #endif // !defined(USE_OPENSSL) | 84 #endif // !defined(USE_OPENSSL) |
OLD | NEW |