p256_key_util.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2015 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 COMPONENTS_GCM_DRIVER_CRYPTO_P256_KEY_UTIL_H_
  5. #define COMPONENTS_GCM_DRIVER_CRYPTO_P256_KEY_UTIL_H_
  6. #include <string>
  7. #include "base/strings/string_piece.h"
  8. namespace crypto {
  9. class ECPrivateKey;
  10. }
  11. namespace gcm {
  12. // Writes the public key associated with the |key| to |*public_key| in
  13. // uncompressed point format. That is, a 65-octet sequence that starts with a
  14. // 0x04 octet. Returns whether the public key could be extracted successfully.
  15. [[nodiscard]] bool GetRawPublicKey(const crypto::ECPrivateKey& key,
  16. std::string* public_key);
  17. // Writes the private key associated with the |key| to |*private_key| as a PKCS
  18. // #8 PrivateKeyInfo block. Returns whether the private key could be extracted
  19. // successfully.
  20. [[nodiscard]] bool GetRawPrivateKey(const crypto::ECPrivateKey& key,
  21. std::string* private_key);
  22. // Computes the shared secret between |key| and |peer_public_key|.The
  23. // |peer_public_key| must be an octet string in uncompressed form per
  24. // SEC1 2.3.3.
  25. //
  26. // Returns whether the secret could be computed, and was written to the out
  27. // argument.
  28. [[nodiscard]] bool ComputeSharedP256Secret(
  29. crypto::ECPrivateKey& key,
  30. const base::StringPiece& peer_public_key,
  31. std::string* out_shared_secret);
  32. } // namespace gcm
  33. #endif // COMPONENTS_GCM_DRIVER_CRYPTO_P256_KEY_UTIL_H_