blob: 674bd4cccb241253629856ee238d7723220844fd [file] [log] [blame]
[email protected]5ee44d42012-02-08 00:14:541// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]28ae8fe2009-06-05 18:25:062// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]4b559b4d2011-04-14 17:37:145#ifndef CRYPTO_SIGNATURE_CREATOR_H_
6#define CRYPTO_SIGNATURE_CREATOR_H_
[email protected]28ae8fe2009-06-05 18:25:067
avidd373b8b2015-12-21 21:34:438#include <stdint.h>
9
rsleeviffe5a132016-06-28 01:51:5210#include <memory>
[email protected]28ae8fe2009-06-05 18:25:0611#include <vector>
12
avidd373b8b2015-12-21 21:34:4313#include "base/macros.h"
[email protected]c9c251d2014-07-22 00:09:2514#include "build/build_config.h"
[email protected]d613a9902011-08-05 20:59:1115#include "crypto/crypto_export.h"
[email protected]28ae8fe2009-06-05 18:25:0616
[email protected]5123d9c2013-06-27 09:18:4317// Forward declaration for openssl/*.h
18typedef struct env_md_ctx_st EVP_MD_CTX;
[email protected]692033a2010-04-09 18:40:5019
[email protected]4b559b4d2011-04-14 17:37:1420namespace crypto {
[email protected]28ae8fe2009-06-05 18:25:0621
[email protected]5ee44d42012-02-08 00:14:5422class RSAPrivateKey;
23
[email protected]28ae8fe2009-06-05 18:25:0624// Signs data using a bare private key (as opposed to a full certificate).
dougsteed0cf460ec2014-09-19 18:46:0925// Currently can only sign data using SHA-1 or SHA-256 with RSA PKCS#1v1.5.
[email protected]d613a9902011-08-05 20:59:1126class CRYPTO_EXPORT SignatureCreator {
[email protected]28ae8fe2009-06-05 18:25:0627 public:
dougsteed0cf460ec2014-09-19 18:46:0928 // The set of supported hash functions. Extend as required.
29 enum HashAlgorithm {
30 SHA1,
31 SHA256,
32 };
33
[email protected]a502bbe72011-01-07 18:06:4534 ~SignatureCreator();
35
[email protected]28ae8fe2009-06-05 18:25:0636 // Create an instance. The caller must ensure that the provided PrivateKey
dougsteed0cf460ec2014-09-19 18:46:0937 // instance outlives the created SignatureCreator. Uses the HashAlgorithm
38 // specified.
rsleeviffe5a132016-06-28 01:51:5239 static std::unique_ptr<SignatureCreator> Create(RSAPrivateKey* key,
40 HashAlgorithm hash_alg);
dougsteed0cf460ec2014-09-19 18:46:0941
42 // Signs the precomputed |hash_alg| digest |data| using private |key| as
[email protected]ed31834b2013-07-09 08:32:4043 // specified in PKCS #1 v1.5.
44 static bool Sign(RSAPrivateKey* key,
dougsteed0cf460ec2014-09-19 18:46:0945 HashAlgorithm hash_alg,
avidd373b8b2015-12-21 21:34:4346 const uint8_t* data,
[email protected]ed31834b2013-07-09 08:32:4047 int data_len,
avidd373b8b2015-12-21 21:34:4348 std::vector<uint8_t>* signature);
[email protected]ed31834b2013-07-09 08:32:4049
[email protected]28ae8fe2009-06-05 18:25:0650 // Update the signature with more data.
avidd373b8b2015-12-21 21:34:4351 bool Update(const uint8_t* data_part, int data_part_len);
[email protected]28ae8fe2009-06-05 18:25:0652
53 // Finalize the signature.
avidd373b8b2015-12-21 21:34:4354 bool Final(std::vector<uint8_t>* signature);
[email protected]28ae8fe2009-06-05 18:25:0655
56 private:
57 // Private constructor. Use the Create() method instead.
[email protected]71a9f842009-09-24 01:21:1258 SignatureCreator();
[email protected]28ae8fe2009-06-05 18:25:0659
[email protected]be796bb2010-11-18 15:43:4360 EVP_MD_CTX* sign_context_;
[email protected]28ae8fe2009-06-05 18:25:0661
62 DISALLOW_COPY_AND_ASSIGN(SignatureCreator);
63};
64
[email protected]4b559b4d2011-04-14 17:37:1465} // namespace crypto
[email protected]28ae8fe2009-06-05 18:25:0666
[email protected]4b559b4d2011-04-14 17:37:1467#endif // CRYPTO_SIGNATURE_CREATOR_H_