Adapt signature abstractions to cryptographic standarts
This commit is contained in:
parent
e48b8a266b
commit
dd10c8e347
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define PROTOCOL 6
|
#define PROTOCOL 7
|
||||||
#define SUB_PROTOCOL 1
|
#define SUB_PROTOCOL 1
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -224,9 +224,7 @@ namespace utils::cryptography
|
|||||||
{
|
{
|
||||||
this->free();
|
this->free();
|
||||||
|
|
||||||
if (ecc_import(cs(key.data()), ul(key.size()),
|
if (ecc_import(cs(key.data()), ul(key.size()), &this->key_storage_) != CRYPT_OK)
|
||||||
&this->key_storage_) != CRYPT_OK
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
ZeroMemory(&this->key_storage_, sizeof(this->key_storage_));
|
ZeroMemory(&this->key_storage_, sizeof(this->key_storage_));
|
||||||
}
|
}
|
||||||
@ -258,6 +256,16 @@ namespace utils::cryptography
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ecc::key::set_openssl(const std::string& key)
|
||||||
|
{
|
||||||
|
this->free();
|
||||||
|
|
||||||
|
if (ecc_import_openssl(cs(key.data()), ul(key.size()), &this->key_storage_) != CRYPT_OK)
|
||||||
|
{
|
||||||
|
ZeroMemory(&this->key_storage_, sizeof(this->key_storage_));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ecc::key::free()
|
void ecc::key::free()
|
||||||
{
|
{
|
||||||
if (this->is_valid())
|
if (this->is_valid())
|
||||||
@ -310,7 +318,9 @@ namespace utils::cryptography
|
|||||||
uint8_t buffer[512];
|
uint8_t buffer[512];
|
||||||
unsigned long length = sizeof(buffer);
|
unsigned long length = sizeof(buffer);
|
||||||
|
|
||||||
ecc_sign_hash(cs(message.data()), ul(message.size()), buffer, &length, prng_.get_state(), prng_.get_id(),
|
const auto hash = sha512::compute(message);
|
||||||
|
|
||||||
|
ecc_sign_hash(cs(hash.data()), ul(hash.size()), buffer, &length, prng_.get_state(), prng_.get_id(),
|
||||||
&key.get());
|
&key.get());
|
||||||
|
|
||||||
return std::string(cs(buffer), length);
|
return std::string(cs(buffer), length);
|
||||||
@ -320,11 +330,13 @@ namespace utils::cryptography
|
|||||||
{
|
{
|
||||||
if (!key.is_valid()) return false;
|
if (!key.is_valid()) return false;
|
||||||
|
|
||||||
|
const auto hash = sha512::compute(message);
|
||||||
|
|
||||||
auto result = 0;
|
auto result = 0;
|
||||||
return (ecc_verify_hash(cs(signature.data()),
|
return (ecc_verify_hash(cs(signature.data()),
|
||||||
ul(signature.size()),
|
ul(signature.size()),
|
||||||
cs(message.data()),
|
cs(hash.data()),
|
||||||
ul(message.size()), &result,
|
ul(hash.size()), &result,
|
||||||
&key.get()) == CRYPT_OK && result != 0);
|
&key.get()) == CRYPT_OK && result != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ namespace utils::cryptography
|
|||||||
std::string serialize(int type = PK_PRIVATE) const;
|
std::string serialize(int type = PK_PRIVATE) const;
|
||||||
|
|
||||||
std::string get_openssl() const;
|
std::string get_openssl() const;
|
||||||
|
void set_openssl(const std::string& key);
|
||||||
|
|
||||||
void free();
|
void free();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user