blob: 72e09dfe9d7941598c894fd3bc2ffc2aac082314 [file] [log] [blame]
[email protected]e4c18472012-01-25 00:56:431// 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_EC_SIGNATURE_CREATOR_H_
6#define CRYPTO_EC_SIGNATURE_CREATOR_H_
[email protected]e4c18472012-01-25 00:56:437
avidd373b8b2015-12-21 21:34:438#include <stdint.h>
9
rsleeviffe5a132016-06-28 01:51:5210#include <memory>
[email protected]7c3090a02012-09-19 15:11:3311#include <string>
[email protected]e4c18472012-01-25 00:56:4312#include <vector>
13
[email protected]e4c18472012-01-25 00:56:4314#include "crypto/crypto_export.h"
15
16namespace crypto {
17
18class ECPrivateKey;
[email protected]6b2e61f2012-02-28 08:06:5419class ECSignatureCreator;
20
21class CRYPTO_EXPORT ECSignatureCreatorFactory {
22 public:
23 virtual ~ECSignatureCreatorFactory() {}
24
rsleeviffe5a132016-06-28 01:51:5225 virtual std::unique_ptr<ECSignatureCreator> Create(ECPrivateKey* key) = 0;
[email protected]6b2e61f2012-02-28 08:06:5426};
[email protected]e4c18472012-01-25 00:56:4327
28// Signs data using a bare private key (as opposed to a full certificate).
29// We need this class because SignatureCreator is hardcoded to use
30// RSAPrivateKey.
31class CRYPTO_EXPORT ECSignatureCreator {
32 public:
[email protected]6b2e61f2012-02-28 08:06:5433 virtual ~ECSignatureCreator() {}
[email protected]e4c18472012-01-25 00:56:4334
35 // Create an instance. The caller must ensure that the provided PrivateKey
36 // instance outlives the created ECSignatureCreator.
[email protected]7c3090a02012-09-19 15:11:3337 // TODO(rch): This is currently hard coded to use SHA256. Ideally, we should
[email protected]e4c18472012-01-25 00:56:4338 // pass in the hash algorithm identifier.
rsleeviffe5a132016-06-28 01:51:5239 static std::unique_ptr<ECSignatureCreator> Create(ECPrivateKey* key);
[email protected]e4c18472012-01-25 00:56:4340
[email protected]6b2e61f2012-02-28 08:06:5441 // Set a factory to make the Create function return non-standard
42 // ECSignatureCreator objects. Because the ECDSA algorithm involves
43 // randomness, this is useful for higher-level tests that want to have
44 // deterministic mocked output to compare.
45 static void SetFactoryForTesting(ECSignatureCreatorFactory* factory);
46
[email protected]e4c18472012-01-25 00:56:4347 // Signs |data_len| bytes from |data| and writes the results into
48 // |signature| as a DER encoded ECDSA-Sig-Value from RFC 3279.
49 //
50 // ECDSA-Sig-Value ::= SEQUENCE {
51 // r INTEGER,
52 // s INTEGER }
avidd373b8b2015-12-21 21:34:4353 virtual bool Sign(const uint8_t* data,
[email protected]6b2e61f2012-02-28 08:06:5454 int data_len,
avidd373b8b2015-12-21 21:34:4355 std::vector<uint8_t>* signature) = 0;
[email protected]7c3090a02012-09-19 15:11:3356
57 // DecodeSignature converts from a DER encoded ECDSA-Sig-Value (as produced
58 // by Sign) to a `raw' ECDSA signature which consists of a pair of
59 // big-endian, zero-padded, 256-bit integers, r and s. On success it returns
60 // true and puts the raw signature into |out_raw_sig|.
61 // (Only P-256 signatures are supported.)
avidd373b8b2015-12-21 21:34:4362 virtual bool DecodeSignature(const std::vector<uint8_t>& signature,
63 std::vector<uint8_t>* out_raw_sig) = 0;
[email protected]e4c18472012-01-25 00:56:4364};
65
66} // namespace crypto
67
68#endif // CRYPTO_EC_SIGNATURE_CREATOR_H_