Skip to content

Commit

Permalink
Save work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zane Beckwith committed Sep 27, 2017
1 parent 7f0b3f5 commit 8e520d5
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
28 changes: 27 additions & 1 deletion test/ecp2_BN254-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
#include <stdio.h>

static void g2_basepoint_not_inf();

static void g2_serialize_then_deserialize_basepoint();
static void g2_lengths_same();

int main()
{
g2_basepoint_not_inf();
g2_serialize_then_deserialize_basepoint();
g2_lengths_same();

return 0;
}
Expand All @@ -44,3 +47,26 @@ void g2_basepoint_not_inf()
printf("\tsuccess\n");
}

static void g2_serialize_then_deserialize_basepoint()
{
printf("Starting pairing_curve_utils::g1_basepoint_not_inf...\n");

ECP2_BN254 point;
ecp2_BN254_set_to_generator(&point);

uint8_t buffer[ECP2_BN254_LENGTH];

ecp2_BN254_serialize(buffer, &point);

ECP2_BN254 deserialized_point;
TEST_ASSERT(0 == ecp2_BN254_deserialize(&deserialized_point, buffer));

TEST_ASSERT(ECP2_BN254_equals(&point, &deserialized_point));

printf("\tsuccess\n");
}

static void g2_lengths_same()
{
TEST_ASSERT(ECP2_BN254_LENGTH == ecp2_BN254_length());
}
51 changes: 51 additions & 0 deletions test/ecp_BN254-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@
#include "../src/amcl-extensions/ecp_BN254.h"

#include <stdio.h>
#include <string.h>

static void g1_basepoint_not_inf();
static void g1_serialize_then_deserialize_basepoint();
static void g1_lengths_same();
static void g1_deserialize_badformat_fails();
static void g1_deserialize_badcoords_fails();

int main()
{
g1_basepoint_not_inf();
g1_serialize_then_deserialize_basepoint();
g1_lengths_same();
g1_deserialize_badformat_fails();
g1_deserialize_badcoords_fails();

return 0;
}
Expand All @@ -43,3 +52,45 @@ void g1_basepoint_not_inf()
printf("\tsuccess\n");
}

static void g1_serialize_then_deserialize_basepoint()
{
printf("Starting pairing_curve_utils::g1_serialize_then_deserialize_basepoint...\n");

ECP_BN254 point;
ecp_BN254_set_to_generator(&point);

uint8_t buffer[ECP_BN254_LENGTH];

ecp_BN254_serialize(buffer, &point);

ECP_BN254 deserialized_point;
TEST_ASSERT(0 == ecp_BN254_deserialize(&deserialized_point, buffer));

TEST_ASSERT(ECP_BN254_equals(&point, &deserialized_point));

printf("\tsuccess\n");
}

static void g1_lengths_same()
{
TEST_ASSERT(ECP_BN254_LENGTH == ecp_BN254_length());
}

static void g1_deserialize_badformat_fails()
{
uint8_t buffer[ECP_BN254_LENGTH] = {0};
buffer[0] = 0x3;

ECP_BN254 point;
TEST_ASSERT(-2 == ecp_BN254_deserialize(&point, buffer));
}

static void g1_deserialize_badcoords_fails()
{
uint8_t buffer[ECP_BN254_LENGTH] = {0};
memset(buffer, 1, sizeof(buffer));
buffer[0] = 0x4;

ECP_BN254 point;
TEST_ASSERT(-1 == ecp_BN254_deserialize(&point, buffer));
}

0 comments on commit 8e520d5

Please sign in to comment.