Sesame-Device/include/relay/interface/CryptoSource.h
2023-12-13 13:20:57 +01:00

68 lines
2.1 KiB
C++

#pragma once
#include <stdint.h>
#include "relay/CryptoPrimitives.h"
/**
* @brief An abstract definition of an instance capable of crypto operations
*
*/
class CryptoSource {
public:
/**
* @brief Indicate that the crypto functions can be used.
*
* @return true The crypto functions are available
* @return false Some error prevents the use of the crypto functions.
*/
virtual
bool isAvailable() = 0;
/**
* @brief Create a new random private key
*
* @param key The output buffer where the key will be stored
* @return true The key was created
* @return false The key could not be created
*/
virtual
bool createPrivateKey(PrivateKey* key) = 0;
/**
* @brief Create a the public key corresponding to a private key
*
* @param privateKey The private key to use
* @param publicKey The output buffer where the public key will be stored
* @return true The key was created
* @return false The key could not be created
*/
virtual
bool createPublicKey(const PrivateKey* privateKey, PublicKey* publicKey) = 0;
/**
* @brief Sign a message
*
* @param message The message payload to include in the message
* @param length The length of the payload
* @param signature The output buffer where the signature is written
* @return true The signature was created
* @return false The signature creation failed
*/
virtual
bool sign(const uint8_t *message, uint16_t length, Signature* signature, const PrivateKey* privateKey, const PublicKey* publicKey) = 0;
/**
* @brief Verify a message
*
* @param signature The message signature
* @param publicKey The public key with which the message was signed
* @param message The pointer to the message data
* @param length The length of the message
* @return true The signature is valid
* @return false The signature is invalid
*/
virtual
bool verify(const Signature* signature, const PublicKey* publicKey, const void *message, uint16_t length) = 0;
};