[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 1 | // Copyright (c) 2011 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] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 25 | #include "crypto/rsa_private_key.h" |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 26 | |
[email protected] | 692033a | 2010-04-09 18:40:50 | [diff] [blame] | 27 | #if defined(OS_WIN) |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 28 | #include "crypto/scoped_capi_types.h" |
[email protected] | 692033a | 2010-04-09 18:40:50 | [diff] [blame] | 29 | #endif |
30 | |||||
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 31 | namespace crypto { |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 32 | |
33 | // Signs data using a bare private key (as opposed to a full certificate). | ||||
34 | // Currently can only sign data using SHA-1 with RSA encryption. | ||||
[email protected] | d613a990 | 2011-08-05 20:59:11 | [diff] [blame^] | 35 | class CRYPTO_EXPORT SignatureCreator { |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 36 | public: |
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 37 | ~SignatureCreator(); |
38 | |||||
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 39 | // Create an instance. The caller must ensure that the provided PrivateKey |
40 | // instance outlives the created SignatureCreator. | ||||
41 | static SignatureCreator* Create(RSAPrivateKey* key); | ||||
42 | |||||
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 43 | // Update the signature with more data. |
44 | bool Update(const uint8* data_part, int data_part_len); | ||||
45 | |||||
46 | // Finalize the signature. | ||||
47 | bool Final(std::vector<uint8>* signature); | ||||
48 | |||||
49 | private: | ||||
50 | // Private constructor. Use the Create() method instead. | ||||
[email protected] | 71a9f84 | 2009-09-24 01:21:12 | [diff] [blame] | 51 | SignatureCreator(); |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 52 | |
53 | RSAPrivateKey* key_; | ||||
54 | |||||
[email protected] | be796bb | 2010-11-18 15:43:43 | [diff] [blame] | 55 | #if defined(USE_OPENSSL) |
56 | EVP_MD_CTX* sign_context_; | ||||
57 | #elif defined(USE_NSS) | ||||
[email protected] | 13555c12 | 2009-10-08 01:18:02 | [diff] [blame] | 58 | SGNContextStr* sign_context_; |
[email protected] | 71a9f84 | 2009-09-24 01:21:12 | [diff] [blame] | 59 | #elif defined(OS_MACOSX) |
[email protected] | e90ed8a | 2009-10-06 18:55:35 | [diff] [blame] | 60 | CSSM_CC_HANDLE sig_handle_; |
[email protected] | 71a9f84 | 2009-09-24 01:21:12 | [diff] [blame] | 61 | #elif defined(OS_WIN) |
[email protected] | 692033a | 2010-04-09 18:40:50 | [diff] [blame] | 62 | ScopedHCRYPTHASH hash_object_; |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 63 | #endif |
64 | |||||
65 | DISALLOW_COPY_AND_ASSIGN(SignatureCreator); | ||||
66 | }; | ||||
67 | |||||
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 68 | } // namespace crypto |
[email protected] | 28ae8fe | 2009-06-05 18:25:06 | [diff] [blame] | 69 | |
[email protected] | 4b559b4d | 2011-04-14 17:37:14 | [diff] [blame] | 70 | #endif // CRYPTO_SIGNATURE_CREATOR_H_ |