blob: 47128fed1b88116f4a754f0ad865845c516c605d [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
[email protected]7c3090a02012-09-19 15:11:3310#include <string>
[email protected]e4c18472012-01-25 00:56:4311#include <vector>
12
[email protected]e4c18472012-01-25 00:56:4313#include "crypto/crypto_export.h"
14
15namespace crypto {
16
17class ECPrivateKey;
[email protected]6b2e61f2012-02-28 08:06:5418class ECSignatureCreator;
19
20class CRYPTO_EXPORT ECSignatureCreatorFactory {
21 public:
22 virtual ~ECSignatureCreatorFactory() {}
23
24 virtual ECSignatureCreator* Create(ECPrivateKey* key) = 0;
25};
[email protected]e4c18472012-01-25 00:56:4326
27// Signs data using a bare private key (as opposed to a full certificate).
28// We need this class because SignatureCreator is hardcoded to use
29// RSAPrivateKey.
30class CRYPTO_EXPORT ECSignatureCreator {
31 public:
[email protected]6b2e61f2012-02-28 08:06:5432 virtual ~ECSignatureCreator() {}
[email protected]e4c18472012-01-25 00:56:4333
34 // Create an instance. The caller must ensure that the provided PrivateKey
35 // instance outlives the created ECSignatureCreator.
[email protected]7c3090a02012-09-19 15:11:3336 // TODO(rch): This is currently hard coded to use SHA256. Ideally, we should
[email protected]e4c18472012-01-25 00:56:4337 // pass in the hash algorithm identifier.
38 static ECSignatureCreator* Create(ECPrivateKey* key);
39
[email protected]6b2e61f2012-02-28 08:06:5440 // Set a factory to make the Create function return non-standard
41 // ECSignatureCreator objects. Because the ECDSA algorithm involves
42 // randomness, this is useful for higher-level tests that want to have
43 // deterministic mocked output to compare.
44 static void SetFactoryForTesting(ECSignatureCreatorFactory* factory);
45
[email protected]e4c18472012-01-25 00:56:4346 // Signs |data_len| bytes from |data| and writes the results into
47 // |signature| as a DER encoded ECDSA-Sig-Value from RFC 3279.
48 //
49 // ECDSA-Sig-Value ::= SEQUENCE {
50 // r INTEGER,
51 // s INTEGER }
avidd373b8b2015-12-21 21:34:4352 virtual bool Sign(const uint8_t* data,
[email protected]6b2e61f2012-02-28 08:06:5453 int data_len,
avidd373b8b2015-12-21 21:34:4354 std::vector<uint8_t>* signature) = 0;
[email protected]7c3090a02012-09-19 15:11:3355
56 // DecodeSignature converts from a DER encoded ECDSA-Sig-Value (as produced
57 // by Sign) to a `raw' ECDSA signature which consists of a pair of
58 // big-endian, zero-padded, 256-bit integers, r and s. On success it returns
59 // true and puts the raw signature into |out_raw_sig|.
60 // (Only P-256 signatures are supported.)
avidd373b8b2015-12-21 21:34:4361 virtual bool DecodeSignature(const std::vector<uint8_t>& signature,
62 std::vector<uint8_t>* out_raw_sig) = 0;
[email protected]e4c18472012-01-25 00:56:4363};
64
65} // namespace crypto
66
67#endif // CRYPTO_EC_SIGNATURE_CREATOR_H_