[email protected] | 5ee44d4 | 2012-02-08 00:14:54 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 5 | #ifndef CRYPTO_SIGNATURE_CREATOR_H_ |
6 | #define CRYPTO_SIGNATURE_CREATOR_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 8 | |
[email protected] | 71a9f84 | 2009-09-24 01:21:12 | [diff] [blame] | 9 | #include "build/build_config.h" |
10 | |||||
[email protected] | be796bb | 2010-11-18 15:43:43 | [diff] [blame] | 11 | #if defined(USE_OPENSSL) |
12 | // Forward declaration for openssl/*.h | ||||
13 | typedef struct env_md_ctx_st EVP_MD_CTX; | ||||
14 | #elif defined(USE_NSS) | ||||
[email protected] | 13555c12 | 2009-10-08 01:18:02 | [diff] [blame] | 15 | // Forward declaration. |
16 | struct SGNContextStr; | ||||
[email protected] | 71a9f84 | 2009-09-24 01:21:12 | [diff] [blame] | 17 | #elif defined(OS_MACOSX) |
[email protected] | e90ed8a | 2009-10-06 18:55:35 | [diff] [blame] | 18 | #include <Security/cssm.h> |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 19 | #endif |
20 | |||||
21 | #include <vector> | ||||
22 | |||||
23 | #include "base/basictypes.h" | ||||
[email protected] | d613a990 | 2011-08-05 20:59:11 | [diff] [blame] | 24 | #include "crypto/crypto_export.h" |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 25 | |
[email protected] | 692033a | 2010-04-09 18:40:50 | [diff] [blame] | 26 | #if defined(OS_WIN) |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 27 | #include "crypto/scoped_capi_types.h" |
[email protected] | 692033a | 2010-04-09 18:40:50 | [diff] [blame] | 28 | #endif |
29 | |||||
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 30 | namespace crypto { |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 31 | |
[email protected] | 5ee44d4 | 2012-02-08 00:14:54 | [diff] [blame^] | 32 | class RSAPrivateKey; |
33 | |||||
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 34 | // Signs data using a bare private key (as opposed to a full certificate). |
35 | // Currently can only sign data using SHA-1 with RSA encryption. | ||||
[email protected] | d613a990 | 2011-08-05 20:59:11 | [diff] [blame] | 36 | class CRYPTO_EXPORT SignatureCreator { |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 37 | public: |
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 38 | ~SignatureCreator(); |
39 | |||||
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 40 | // Create an instance. The caller must ensure that the provided PrivateKey |
41 | // instance outlives the created SignatureCreator. | ||||
42 | static SignatureCreator* Create(RSAPrivateKey* key); | ||||
43 | |||||
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 44 | // Update the signature with more data. |
45 | bool Update(const uint8* data_part, int data_part_len); | ||||
46 | |||||
47 | // Finalize the signature. | ||||
48 | bool Final(std::vector<uint8>* signature); | ||||
49 | |||||
50 | private: | ||||
51 | // Private constructor. Use the Create() method instead. | ||||
[email protected] | 71a9f84 | 2009-09-24 01:21:12 | [diff] [blame] | 52 | SignatureCreator(); |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 53 | |
54 | RSAPrivateKey* key_; | ||||
55 | |||||
[email protected] | be796bb | 2010-11-18 15:43:43 | [diff] [blame] | 56 | #if defined(USE_OPENSSL) |
57 | EVP_MD_CTX* sign_context_; | ||||
58 | #elif defined(USE_NSS) | ||||
[email protected] | 13555c12 | 2009-10-08 01:18:02 | [diff] [blame] | 59 | SGNContextStr* sign_context_; |
[email protected] | 71a9f84 | 2009-09-24 01:21:12 | [diff] [blame] | 60 | #elif defined(OS_MACOSX) |
[email protected] | e90ed8a | 2009-10-06 18:55:35 | [diff] [blame] | 61 | CSSM_CC_HANDLE sig_handle_; |
[email protected] | 71a9f84 | 2009-09-24 01:21:12 | [diff] [blame] | 62 | #elif defined(OS_WIN) |
[email protected] | 692033a | 2010-04-09 18:40:50 | [diff] [blame] | 63 | ScopedHCRYPTHASH hash_object_; |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 64 | #endif |
65 | |||||
66 | DISALLOW_COPY_AND_ASSIGN(SignatureCreator); | ||||
67 | }; | ||||
68 | |||||
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 69 | } // namespace crypto |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 70 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 71 | #endif // CRYPTO_SIGNATURE_CREATOR_H_ |