2014-02-28 04:41:10 -07:00
|
|
|
// Copyright 2007,2008 Segher Boessenkool <segher@kernel.crashing.org>
|
2021-07-04 19:54:29 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-02-28 04:41:10 -07:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-05-15 13:24:45 -06:00
|
|
|
#include <array>
|
|
|
|
|
2014-02-28 04:41:10 -07:00
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
|
2018-05-15 16:04:10 -06:00
|
|
|
namespace Common::ec
|
|
|
|
{
|
2018-05-21 07:40:29 -06:00
|
|
|
using Signature = std::array<u8, 60>;
|
|
|
|
using PublicKey = std::array<u8, 60>;
|
|
|
|
|
2018-05-15 16:04:10 -06:00
|
|
|
/// Generate a signature using ECDSA.
|
2018-05-21 07:40:29 -06:00
|
|
|
Signature Sign(const u8* key, const u8* hash);
|
2017-03-08 04:40:50 -07:00
|
|
|
|
2018-05-15 10:01:28 -06:00
|
|
|
/// Check a signature using ECDSA.
|
|
|
|
///
|
|
|
|
/// @param public_key 30 byte ECC public key
|
|
|
|
/// @param signature 60 byte signature
|
|
|
|
/// @param hash Message hash
|
|
|
|
bool VerifySignature(const u8* public_key, const u8* signature, const u8* hash);
|
|
|
|
|
2018-05-15 16:04:10 -06:00
|
|
|
/// Compute a shared secret from a private key (30 bytes) and public key (60 bytes).
|
2018-05-15 13:24:45 -06:00
|
|
|
std::array<u8, 60> ComputeSharedSecret(const u8* private_key, const u8* public_key);
|
2018-05-15 16:04:10 -06:00
|
|
|
|
|
|
|
/// Convert a ECC private key (30 bytes) to a public key (60 bytes).
|
2018-05-21 07:40:29 -06:00
|
|
|
PublicKey PrivToPub(const u8* key);
|
2018-05-15 16:04:10 -06:00
|
|
|
} // namespace Common::ec
|