Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CRYPTO_SIGNATURE_CREATOR_H_ |
| 6 | #define CRYPTO_SIGNATURE_CREATOR_H_ |
| 7 | |
| 8 | #include "build/build_config.h" |
| 9 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
| 12 | #include "base/basictypes.h" |
| 13 | #include "crypto/crypto_export.h" |
| 14 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 15 | #if defined(USE_OPENSSL) |
| 16 | // Forward declaration for openssl/*.h |
| 17 | typedef struct env_md_ctx_st EVP_MD_CTX; |
| 18 | #elif defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) |
| 19 | // Forward declaration. |
| 20 | struct SGNContextStr; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 21 | #endif |
| 22 | |
| 23 | namespace crypto { |
| 24 | |
| 25 | class RSAPrivateKey; |
| 26 | |
| 27 | // Signs data using a bare private key (as opposed to a full certificate). |
| 28 | // Currently can only sign data using SHA-1 with RSA encryption. |
| 29 | class CRYPTO_EXPORT SignatureCreator { |
| 30 | public: |
| 31 | ~SignatureCreator(); |
| 32 | |
| 33 | // Create an instance. The caller must ensure that the provided PrivateKey |
| 34 | // instance outlives the created SignatureCreator. |
| 35 | static SignatureCreator* Create(RSAPrivateKey* key); |
| 36 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 37 | // Signs the precomputed SHA-1 digest |data| using private |key| as |
| 38 | // specified in PKCS #1 v1.5. |
| 39 | static bool Sign(RSAPrivateKey* key, |
| 40 | const uint8* data, |
| 41 | int data_len, |
| 42 | std::vector<uint8>* signature); |
| 43 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [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. |
| 52 | SignatureCreator(); |
| 53 | |
| 54 | RSAPrivateKey* key_; |
| 55 | |
| 56 | #if defined(USE_OPENSSL) |
| 57 | EVP_MD_CTX* sign_context_; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 58 | #elif defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 59 | SGNContextStr* sign_context_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 60 | #endif |
| 61 | |
| 62 | DISALLOW_COPY_AND_ASSIGN(SignatureCreator); |
| 63 | }; |
| 64 | |
| 65 | } // namespace crypto |
| 66 | |
| 67 | #endif // CRYPTO_SIGNATURE_CREATOR_H_ |