gluon-lib-ecdsa: make hashing it's own function

This commit is contained in:
Maciej Krüger 2021-12-21 10:14:17 +01:00 committed by Alexander List
parent 6a8ec191a5
commit 7b4e0bb547
3 changed files with 20 additions and 11 deletions

View File

@ -32,12 +32,17 @@ limitations under the License.
#define ECDSA "gluon.ecdsa"
// TODO: fix all the memory leaks
static bool verify(lua_State *L, const char *data, const char *sig, const char *key) {
struct verify_params params = {
.good_signatures = 1,
.data = data
.good_signatures = 1
};
if (!hash_data(&params, data)) {
return luaL_error(L, "failed hashing data");
}
if (!load_signatures(&params, 1, &sig, false)) {
return luaL_error(L, "failed loading signature");
}

View File

@ -11,16 +11,9 @@
#include <limits.h>
bool do_verify(struct verify_params* params) {
ecdsa_sha256_context_t hash_ctx;
ecdsa_sha256_init(&hash_ctx);
ecdsa_sha256_update(&hash_ctx, params->data, strlen(params->data));
ecc_int256_t hash;
ecdsa_sha256_final(&hash_ctx, hash.p);
ecdsa_verify_context_t ctxs[params->n_signatures];
for (size_t i = 0; i < params->n_signatures; i++)
ecdsa_verify_prepare_legacy(&ctxs[i], &hash, params->signatures[i]);
ecdsa_verify_prepare_legacy(&ctxs[i], &params->hash, params->signatures[i]);
long unsigned int good_signatures = ecdsa_verify_list_legacy(ctxs, params->n_signatures, params->pubkeys, params->n_pubkeys);
@ -31,6 +24,16 @@ bool do_verify(struct verify_params* params) {
return true;
}
int hash_data(struct verify_params* params, const char* data) {
ecdsa_sha256_context_t hash_ctx;
ecdsa_sha256_init(&hash_ctx);
ecdsa_sha256_update(&hash_ctx, data, strlen(data));
ecdsa_sha256_final(&hash_ctx, params->hash.p);
return 1;
}
int load_pubkeys(struct verify_params* params, const size_t n_pubkeys, const char **pubkeys_str, const bool ignore_pubkeys) {
params->n_pubkeys = n_pubkeys;
params->pubkeys = safe_malloc(n_pubkeys * sizeof(ecc_25519_work_t));

View File

@ -2,7 +2,7 @@
#include <ecdsautil/sha256.h>
struct verify_params {
const char* data;
ecc_int256_t hash;
size_t n_signatures;
ecdsa_signature_t **signatures;
@ -14,5 +14,6 @@ struct verify_params {
};
bool do_verify(struct verify_params* params);
int hash_data(struct verify_params* params, const char* data);
int load_pubkeys(struct verify_params* params, const size_t n_pubkeys, const char **pubkeys_str, const bool ignore_pubkeys);
int load_signatures(struct verify_params* params, const size_t n_signatures, const char **signatures_str, const bool ignore_signatures);