Skip to content

Commit

Permalink
Test serialization of group-public-key.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zane Beckwith committed Sep 27, 2017
1 parent 6a1980d commit 457a751
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include(CTest)
set(CURRENT_TEST_BINARY_DIR ${CMAKE_BINARY_DIR}/testBin/)

set(TEST_SRCS
group_public_key-tests.c
sign-and-verify-tests.c
issuer_keypair-tests.c
credential-tests.c
Expand Down
85 changes: 85 additions & 0 deletions test/group_public_key-tests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/******************************************************************************
*
* Copyright 2017 Xaptum, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*
*****************************************************************************/

#include "ecdaa-test-utils.h"

#include <ecdaa/group_public_key_BN254.h>

#include "../src/amcl-extensions/ecp2_BN254.h"

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

static void serialize_then_deserialize_basepoints();
static void lengths_same();
static void deserialize_garbage_fails();

int main()
{
serialize_then_deserialize_basepoints();
lengths_same();
deserialize_garbage_fails();

return 0;
}

static void serialize_then_deserialize_basepoints()
{
printf("Starting group_public_key::serialize_then_deserialize_basepoints...\n");

struct ecdaa_group_public_key_BN254 gpk;

ecp2_BN254_set_to_generator(&gpk.X);
ecp2_BN254_set_to_generator(&gpk.Y);


uint8_t buffer[ECDAA_GROUP_PUBLIC_KEY_BN254_LENGTH];

ecdaa_group_public_key_BN254_serialize(buffer, &gpk);

struct ecdaa_group_public_key_BN254 gpk_deserialized;
TEST_ASSERT(0 == ecdaa_group_public_key_BN254_deserialize(&gpk_deserialized, buffer));

TEST_ASSERT(ECP2_BN254_equals(&gpk.X, &gpk_deserialized.X));
TEST_ASSERT(ECP2_BN254_equals(&gpk.Y, &gpk_deserialized.Y));

printf("\tsuccess\n");
}

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

TEST_ASSERT(ECDAA_GROUP_PUBLIC_KEY_BN254_LENGTH == ecdaa_group_public_key_BN254_length());

printf("\tsuccess\n");
}

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

uint8_t buffer[ECDAA_GROUP_PUBLIC_KEY_BN254_LENGTH] = {0};
memset(buffer, 1, sizeof(buffer)); // All 1's
buffer[0] = 0x4;

struct ecdaa_group_public_key_BN254 gpk_deserialized;
TEST_ASSERT(-1 == ecdaa_group_public_key_BN254_deserialize(&gpk_deserialized, buffer));

printf("\tsuccess\n");
}

0 comments on commit 457a751

Please sign in to comment.