forked from planet-nine-app/sessionless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce dependency on modern C++ features
- Loading branch information
Your Name
committed
May 25, 2024
1 parent
45acf0d
commit 7e43f8e
Showing
3 changed files
with
42 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,32 @@ | ||
#ifndef SESSIONLESS_HPP | ||
#define SESSIONLESS_HPP | ||
|
||
#include <array> | ||
#include <cstddef> | ||
|
||
static constexpr size_t SHA256_SIZE_BYTES = 32; | ||
static constexpr size_t PRIVATE_KEY_SIZE_BYTES = SHA256_SIZE_BYTES; | ||
static constexpr size_t PUBLIC_KEY_SIZE_BYTES = 33; | ||
static constexpr size_t SIGNATURE_SIZE_BYTES = 64; | ||
|
||
using PublicKey = std::array<unsigned char, PUBLIC_KEY_SIZE_BYTES>; | ||
using PrivateKey = std::array<unsigned char, PRIVATE_KEY_SIZE_BYTES>; | ||
using Signature = std::array<unsigned char, SIGNATURE_SIZE_BYTES>; | ||
#define SHA256_SIZE_BYTES 32 | ||
#define PRIVATE_KEY_SIZE_BYTES SHA256_SIZE_BYTES | ||
#define PUBLIC_KEY_SIZE_BYTES 33 | ||
#define SIGNATURE_SIZE_BYTES 64 | ||
|
||
struct Keys | ||
{ | ||
PublicKey publicKey; | ||
PrivateKey privateKey; | ||
unsigned char publicKey[PUBLIC_KEY_SIZE_BYTES]; | ||
unsigned char privateKey[PRIVATE_KEY_SIZE_BYTES]; | ||
}; | ||
|
||
namespace sessionless | ||
{ | ||
bool generateKeys(Keys &keys); | ||
bool sign(const unsigned char *message, const size_t length, const PrivateKey privateKey, Signature &signature); | ||
bool verifySignature(Signature signature, PublicKey publicKey, const unsigned char *message, const size_t length); | ||
|
||
bool sign(const unsigned char *message, | ||
const size_t msgLengthBytes, | ||
const unsigned char *privateKey, | ||
unsigned char *signature); | ||
|
||
bool verifySignature(const unsigned char *signature, | ||
const unsigned char *publicKey, | ||
const unsigned char *message, | ||
const size_t msgLengthBytes); | ||
}; | ||
|
||
#endif |