ec_signature_creator.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.
  4. #ifndef CRYPTO_EC_SIGNATURE_CREATOR_H_
  5. #define CRYPTO_EC_SIGNATURE_CREATOR_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <string>
  9. #include <vector>
  10. #include "base/containers/span.h"
  11. #include "crypto/crypto_export.h"
  12. namespace crypto {
  13. class ECPrivateKey;
  14. class ECSignatureCreator;
  15. // Signs data using a bare private key (as opposed to a full certificate).
  16. // We need this class because SignatureCreator is hardcoded to use
  17. // RSAPrivateKey.
  18. class CRYPTO_EXPORT ECSignatureCreator {
  19. public:
  20. virtual ~ECSignatureCreator() {}
  21. // Create an instance. The caller must ensure that the provided PrivateKey
  22. // instance outlives the created ECSignatureCreator.
  23. // TODO(rch): This is currently hard coded to use SHA256. Ideally, we should
  24. // pass in the hash algorithm identifier.
  25. static std::unique_ptr<ECSignatureCreator> Create(ECPrivateKey* key);
  26. // Signs |data| and writes the results into |signature| as a DER encoded
  27. // ECDSA-Sig-Value from RFC 3279.
  28. //
  29. // ECDSA-Sig-Value ::= SEQUENCE {
  30. // r INTEGER,
  31. // s INTEGER }
  32. virtual bool Sign(base::span<const uint8_t> data,
  33. std::vector<uint8_t>* signature) = 0;
  34. // DecodeSignature converts from a DER encoded ECDSA-Sig-Value (as produced
  35. // by Sign) to a `raw' ECDSA signature which consists of a pair of
  36. // big-endian, zero-padded, 256-bit integers, r and s. On success it returns
  37. // true and puts the raw signature into |out_raw_sig|.
  38. // (Only P-256 signatures are supported.)
  39. virtual bool DecodeSignature(const std::vector<uint8_t>& signature,
  40. std::vector<uint8_t>* out_raw_sig) = 0;
  41. };
  42. } // namespace crypto
  43. #endif // CRYPTO_EC_SIGNATURE_CREATOR_H_