Skip to content

Commit

Permalink
Test serialization of signatures.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zane Beckwith committed Sep 27, 2017
1 parent dd54d44 commit 4cdc876
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set(CURRENT_TEST_BINARY_DIR ${CMAKE_BINARY_DIR}/testBin/)

set(TEST_SRCS
group_public_key-tests.c
sign-and-verify-tests.c
signature-tests.c
issuer_keypair-tests.c
credential-tests.c
member_keypair-tests.c
Expand Down
64 changes: 61 additions & 3 deletions test/sign-and-verify-tests.c → test/signature-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@

static void sign_then_verify_good();
static void sign_then_verify_on_rev_list();
static void lengths_same();
static void serialize_deserialize();
static void deserialize_garbage_fails();

typedef struct sign_and_verify_fixture {
struct ecdaa_prng prng;
Expand All @@ -56,6 +59,9 @@ int main()
{
sign_then_verify_good();
sign_then_verify_on_rev_list();
lengths_same();
serialize_deserialize();
deserialize_garbage_fails();
}

static void setup(sign_and_verify_fixture* fixture)
Expand All @@ -78,7 +84,7 @@ static void setup(sign_and_verify_fixture* fixture)
ecdaa_credential_BN254_generate(&fixture->cred, &cred_sig, &fixture->isk, &fixture->pk, &fixture->prng);

fixture->msg = (uint8_t*) "Test message";
fixture->msg_len = strlen((char*)fixture->msg);
fixture->msg_len = (uint32_t)strlen((char*)fixture->msg);

fixture->sk_rev_list.length=0;
fixture->sk_rev_list.list=NULL;
Expand All @@ -91,7 +97,7 @@ static void teardown(sign_and_verify_fixture *fixture)

static void sign_then_verify_good()
{
printf("Starting sign-and-verify::sign_then_verify_good...\n");
printf("Starting signature::sign_then_verify_good...\n");

sign_and_verify_fixture fixture;
setup(&fixture);
Expand All @@ -108,7 +114,7 @@ static void sign_then_verify_good()

static void sign_then_verify_on_rev_list()
{
printf("Starting sign-and-verify::sign_then_verify_on_rev_list...\n");
printf("Starting signature::sign_then_verify_on_rev_list...\n");

sign_and_verify_fixture fixture;
setup(&fixture);
Expand All @@ -127,3 +133,55 @@ static void sign_then_verify_on_rev_list()

printf("\tsuccess\n");
}

static void lengths_same()
{
printf("Starting signature::lengths_same...\n");

TEST_ASSERT(ECDAA_SIGNATURE_BN254_LENGTH == ecdaa_signature_BN254_length());

printf("\tsuccess\n");
}

static void serialize_deserialize()
{
printf("Starting signature::serialize_deserialize...\n");

sign_and_verify_fixture fixture;
setup(&fixture);

struct ecdaa_signature_BN254 sig;
TEST_ASSERT(0 == ecdaa_signature_BN254_sign(&sig, fixture.msg, fixture.msg_len, &fixture.sk, &fixture.cred, &fixture.prng));

TEST_ASSERT(0 == ecdaa_signature_BN254_verify(&sig, &fixture.ipk.gpk, &fixture.sk_rev_list, fixture.msg, fixture.msg_len));

uint8_t buffer[ECDAA_SIGNATURE_BN254_LENGTH];
ecdaa_signature_BN254_serialize(buffer, &sig);
struct ecdaa_signature_BN254 sig_deserialized;
TEST_ASSERT(0 == ecdaa_signature_BN254_deserialize(&sig_deserialized, buffer));
TEST_ASSERT(0 == ecdaa_signature_BN254_deserialize_and_verify(&sig_deserialized, &fixture.ipk.gpk, &fixture.sk_rev_list, buffer, fixture.msg, fixture.msg_len));

teardown(&fixture);

printf("\tsuccess\n");
}

static void deserialize_garbage_fails()
{
printf("Starting signature::serialize_deserialize...\n");

struct ecdaa_signature_BN254 sig;
BIG_256_56_zero(sig.c);
BIG_256_56_zero(sig.s);
ecp_BN254_set_to_generator(&sig.R);
ecp_BN254_set_to_generator(&sig.S);
ecp_BN254_set_to_generator(&sig.T);
ecp_BN254_set_to_generator(&sig.W);

uint8_t buffer[ECDAA_SIGNATURE_BN254_LENGTH];
ecdaa_signature_BN254_serialize(buffer, &sig);
struct ecdaa_signature_BN254 sig_deserialized;
TEST_ASSERT(0 != ecdaa_signature_BN254_deserialize(&sig_deserialized, buffer));

printf("\tsuccess\n");
}

0 comments on commit 4cdc876

Please sign in to comment.