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 #ifndef CRYPTO_EC_SIGNATURE_CREATOR_H_ | 5 #ifndef CRYPTO_EC_SIGNATURE_CREATOR_H_ |
6 #define CRYPTO_EC_SIGNATURE_CREATOR_H_ | 6 #define CRYPTO_EC_SIGNATURE_CREATOR_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "crypto/crypto_export.h" | 12 #include "crypto/crypto_export.h" |
13 | 13 |
14 namespace crypto { | 14 namespace crypto { |
15 | 15 |
16 class ECPrivateKey; | 16 class ECPrivateKey; |
17 class ECSignatureCreator; | |
18 | |
19 class CRYPTO_EXPORT ECSignatureCreatorFactory { | |
20 public: | |
21 virtual ECSignatureCreator* Create(ECPrivateKey* key) = 0; | |
Ryan Hamilton
2012/02/23 04:36:12
Do you need a virtual destructor?
mattm
2012/02/23 04:44:57
yep
| |
22 }; | |
17 | 23 |
18 // Signs data using a bare private key (as opposed to a full certificate). | 24 // Signs data using a bare private key (as opposed to a full certificate). |
19 // We need this class because SignatureCreator is hardcoded to use | 25 // We need this class because SignatureCreator is hardcoded to use |
20 // RSAPrivateKey. | 26 // RSAPrivateKey. |
21 class CRYPTO_EXPORT ECSignatureCreator { | 27 class CRYPTO_EXPORT ECSignatureCreator { |
22 public: | 28 public: |
23 ~ECSignatureCreator(); | 29 virtual ~ECSignatureCreator() {} |
24 | 30 |
25 // Create an instance. The caller must ensure that the provided PrivateKey | 31 // Create an instance. The caller must ensure that the provided PrivateKey |
26 // instance outlives the created ECSignatureCreator. | 32 // instance outlives the created ECSignatureCreator. |
27 // TODO(rch): This is currently hard coded to use SHA1. Ideally, we should | 33 // TODO(rch): This is currently hard coded to use SHA1. Ideally, we should |
28 // pass in the hash algorithm identifier. | 34 // pass in the hash algorithm identifier. |
29 static ECSignatureCreator* Create(ECPrivateKey* key); | 35 static ECSignatureCreator* Create(ECPrivateKey* key); |
30 | 36 |
37 // Set a factory to make the Create function return non-standard | |
38 // ECSignatureCreator objects. Because the elliptic curve signature algorithm | |
39 // involves randomness, this is useful for higher-level tests that want to | |
40 // have deterministic output to compare. | |
41 static void SetFactoryForTesting(ECSignatureCreatorFactory* factory); | |
42 | |
31 // Signs |data_len| bytes from |data| and writes the results into | 43 // Signs |data_len| bytes from |data| and writes the results into |
32 // |signature| as a DER encoded ECDSA-Sig-Value from RFC 3279. | 44 // |signature| as a DER encoded ECDSA-Sig-Value from RFC 3279. |
33 // | 45 // |
34 // ECDSA-Sig-Value ::= SEQUENCE { | 46 // ECDSA-Sig-Value ::= SEQUENCE { |
35 // r INTEGER, | 47 // r INTEGER, |
36 // s INTEGER } | 48 // s INTEGER } |
37 bool Sign(const uint8* data, | 49 virtual bool Sign(const uint8* data, |
38 int data_len, | 50 int data_len, |
39 std::vector<uint8>* signature); | 51 std::vector<uint8>* signature) = 0; |
40 | 52 |
41 private: | 53 protected: |
42 // Private constructor. Use the Create() method instead. | 54 static ECSignatureCreator* CreatePlatformImpl(ECPrivateKey* key); |
43 explicit ECSignatureCreator(ECPrivateKey* key); | |
44 | |
45 ECPrivateKey* key_; | |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(ECSignatureCreator); | |
48 }; | 55 }; |
49 | 56 |
50 } // namespace crypto | 57 } // namespace crypto |
51 | 58 |
52 #endif // CRYPTO_EC_SIGNATURE_CREATOR_H_ | 59 #endif // CRYPTO_EC_SIGNATURE_CREATOR_H_ |
OLD | NEW |