blob: e9cb3f80cb96cb465f9945e81a0311a9a28d2625 [file] [log] [blame]
Avi Drissman201a9a832022-09-13 19:39:251// Copyright 2012 The Chromium Authors
[email protected]e4c18472012-01-25 00:56:432// 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
Hubert Chao7248d5832021-07-21 16:33:2614#include "base/containers/span.h"
[email protected]e4c18472012-01-25 00:56:4315#include "crypto/crypto_export.h"
16
17namespace crypto {
18
19class ECPrivateKey;
[email protected]6b2e61f2012-02-28 08:06:5420class ECSignatureCreator;
21
[email protected]e4c18472012-01-25 00:56:4322// Signs data using a bare private key (as opposed to a full certificate).
23// We need this class because SignatureCreator is hardcoded to use
24// RSAPrivateKey.
25class CRYPTO_EXPORT ECSignatureCreator {
26 public:
[email protected]6b2e61f2012-02-28 08:06:5427 virtual ~ECSignatureCreator() {}
[email protected]e4c18472012-01-25 00:56:4328
29 // Create an instance. The caller must ensure that the provided PrivateKey
30 // instance outlives the created ECSignatureCreator.
[email protected]7c3090a02012-09-19 15:11:3331 // TODO(rch): This is currently hard coded to use SHA256. Ideally, we should
[email protected]e4c18472012-01-25 00:56:4332 // pass in the hash algorithm identifier.
rsleeviffe5a132016-06-28 01:51:5233 static std::unique_ptr<ECSignatureCreator> Create(ECPrivateKey* key);
[email protected]e4c18472012-01-25 00:56:4334
Hubert Chao7248d5832021-07-21 16:33:2635 // Signs |data| and writes the results into |signature| as a DER encoded
36 // ECDSA-Sig-Value from RFC 3279.
[email protected]e4c18472012-01-25 00:56:4337 //
38 // ECDSA-Sig-Value ::= SEQUENCE {
39 // r INTEGER,
40 // s INTEGER }
Hubert Chao7248d5832021-07-21 16:33:2641 virtual bool Sign(base::span<const uint8_t> data,
avidd373b8b2015-12-21 21:34:4342 std::vector<uint8_t>* signature) = 0;
[email protected]7c3090a02012-09-19 15:11:3343
44 // DecodeSignature converts from a DER encoded ECDSA-Sig-Value (as produced
45 // by Sign) to a `raw' ECDSA signature which consists of a pair of
46 // big-endian, zero-padded, 256-bit integers, r and s. On success it returns
47 // true and puts the raw signature into |out_raw_sig|.
48 // (Only P-256 signatures are supported.)
avidd373b8b2015-12-21 21:34:4349 virtual bool DecodeSignature(const std::vector<uint8_t>& signature,
50 std::vector<uint8_t>* out_raw_sig) = 0;
[email protected]e4c18472012-01-25 00:56:4351};
52
53} // namespace crypto
54
55#endif // CRYPTO_EC_SIGNATURE_CREATOR_H_