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.
5 #ifndef CRYPTO_SIGNATURE_CREATOR_H_
6 #define CRYPTO_SIGNATURE_CREATOR_H_
13 #include "base/macros.h"
14 #include "build/build_config.h"
15 #include "crypto/crypto_export.h"
17 // Forward declaration for openssl/*.h
18 typedef struct env_md_ctx_st EVP_MD_CTX;
24 // Signs data using a bare private key (as opposed to a full certificate).
25 // Currently can only sign data using SHA-1 or SHA-256 with RSA PKCS#1v1.5.
26 class CRYPTO_EXPORT SignatureCreator {
28 // The set of supported hash functions. Extend as required.
36 // Create an instance. The caller must ensure that the provided PrivateKey
37 // instance outlives the created SignatureCreator. Uses the HashAlgorithm
39 static std::unique_ptr<SignatureCreator> Create(RSAPrivateKey* key,
40 HashAlgorithm hash_alg);
42 // Signs the precomputed |hash_alg| digest |data| using private |key| as
43 // specified in PKCS #1 v1.5.
44 static bool Sign(RSAPrivateKey* key,
45 HashAlgorithm hash_alg,
48 std::vector<uint8_t>* signature);
50 // Update the signature with more data.
51 bool Update(const uint8_t* data_part, int data_part_len);
53 // Finalize the signature.
54 bool Final(std::vector<uint8_t>* signature);
57 // Private constructor. Use the Create() method instead.
60 EVP_MD_CTX* sign_context_;
62 DISALLOW_COPY_AND_ASSIGN(SignatureCreator);
67 #endif // CRYPTO_SIGNATURE_CREATOR_H_