ecc_p224.h 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <span>
  5. namespace sunrise::middleware::crypto::ecc {
  6. /** secp224r1 coordinates and shared secrets are 28 bytes. */
  7. inline constexpr std::size_t kFieldSize = 28;
  8. /** An exported key travels in a fixed field, zero padded past the encoding it carries. */
  9. inline constexpr std::size_t kExportedKeySize = 100;
  10. /** One completed agreement. */
  11. struct Agreement {
  12. /** Our public key, encoded the way the peer's importer expects. */
  13. std::array<std::byte, kExportedKeySize> publicKey{};
  14. /** The x coordinate of the agreed point, high byte first. */
  15. std::array<std::byte, kFieldSize> sharedSecret{};
  16. };
  17. /**
  18. * Generates one key pair and agrees a secret with the peer's exported public key.
  19. * The pair is ephemeral and is destroyed before this returns; only the agreement survives.
  20. * @param peerPublicKey Peer's exported key, padding included.
  21. * @param output Receives the public key and the secret only on success.
  22. * @return True when the peer key parsed and Windows completed the agreement.
  23. */
  24. [[nodiscard]] bool agree(std::span<const std::byte> peerPublicKey, Agreement& output) noexcept;
  25. } // namespace sunrise::middleware::crypto::ecc