libswarm-ng

C implementation of BMT hasher, Swarmhash and Single Owner Chunk for swarm
git clone git://git.defalsify.org/libswarm-ng.git
Log | Files | Refs | Submodules | README

commit 14d73b0d9f9e99f626cd30b4300a62601b0bfcf3
parent 98fd2307066fa973bf2aad98ff60f7e8dce6714a
Author: nolash <dev@holbrook.no>
Date:   Thu, 16 Sep 2021 23:28:48 +0200

Add soc verify

Diffstat:
Msrc/soc.c | 12+++++++++++-
Msrc/soc.h | 3++-
Mtest/check_soc.c | 24+++++++++++++++++-------
3 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/src/soc.c b/src/soc.c @@ -90,7 +90,7 @@ int soc_digest(const soc_chunk_t *chunk, unsigned char *z) { return 0; } -int soc_verify(soc_chunk_t *chunk) { +int soc_verify(const soc_chunk_t *chunk, const keystore_key_t *key_cmp) { int r; unsigned char b[96]; keystore_key_t key; @@ -106,5 +106,15 @@ int soc_verify(soc_chunk_t *chunk) { return 1; } + r = key_from_public(&key); + if (r != 0) { + return 1; + } + + r = memcmp(key.label, key_cmp->label, SWARM_ADDRESS_SIZE); + if (r != 0) { + return 1; + } + return 0; } diff --git a/src/soc.h b/src/soc.h @@ -3,6 +3,7 @@ #include "def.h" #include "chunk.h" +#include "keystore.h" #define SWARM_SOC_TOPIC_SIZE 20 #define SWARM_SOC_INDEX_SIZE SWARM_WORD_SIZE @@ -18,6 +19,6 @@ int soc_identifier(char *z, const char *topic, const char *index); int soc_address(char *z, const char *identifier, const char *address); int soc_digest(const soc_chunk_t* chunk, unsigned char *z); unsigned char* soc_serialize(const soc_chunk_t *chunk, unsigned char *z, size_t *sz); -int soc_verify(soc_chunk_t *chunk); +int soc_verify(const soc_chunk_t *chunk, const keystore_key_t *key_cmp); #endif // _LIBSWARM_SOC_H diff --git a/test/check_soc.c b/test/check_soc.c @@ -57,20 +57,30 @@ START_TEST(check_soc_verify) { soc_chunk_t chunk; keystore_key_t key; keystore_key_t *key_returned; - struct block_generator bg; + keystore_t keystore; + keystore_t *keystore_returned; + unsigned char digest[96]; - bg.v = 0; - bg.m = 256; + keystore_returned = keystore_init(&keystore); + ck_assert_ptr_nonnull(keystore_returned); + + hex2bin(TEST_PRIVATE_KEY, key.pk); + + key_returned = keystore_put(&keystore, &key, NULL, 0); + ck_assert_ptr_nonnull(key_returned); - hex2bin("TEST_PRIVATE_KEY", key.pk); r = key_from_private(&key); ck_assert_int_eq(r, 0); - *(chunk.signature+64) = 0x01; - r = soc_verify(&chunk); + r = soc_digest(&chunk, digest); + ck_assert_int_eq(r, 0); + + keystore_sign(&keystore, chunk.signature, 0, digest); + + r = soc_verify(&chunk, &key); ck_assert_int_eq(r, 0); - //key_returned = key_recover(&key, chunk.signature, digest); + keystore_free(&keystore); } END_TEST