123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- /*############################################################################
- # Copyright 2017 Intel Corporation
- #
- # 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.
- ############################################################################*/
- /// Unit tests of serialization implementation.
- /*! \file */
- #include <gtest/gtest.h>
- #include <stdint.h>
- #include <cstring>
- #include "epid/member/tiny/math/unittests/cmp-testhelper.h"
- extern "C" {
- #include "epid/common/types.h"
- #include "epid/member/tiny/math/mathtypes.h"
- #include "epid/member/tiny/math/serialize.h"
- }
- bool operator==(OctStr32 const& lhs, OctStr32 const& rhs) {
- return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
- }
- bool operator==(BigNumStr const& lhs, BigNumStr const& rhs) {
- return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
- }
- bool operator==(FpElemStr const& lhs, FpElemStr const& rhs) {
- return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
- }
- bool operator==(FqElemStr const& lhs, FqElemStr const& rhs) {
- return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
- }
- bool operator==(G1ElemStr const& lhs, G1ElemStr const& rhs) {
- return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
- }
- bool operator==(G2ElemStr const& lhs, G2ElemStr const& rhs) {
- return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
- }
- bool operator==(Fq12ElemStr const& lhs, Fq12ElemStr const& rhs) {
- return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
- }
- namespace {
- ////////////////////////////////////////////////////////////////////////
- // Uint32Serialize
- TEST(TinySerializeTest, Uint32SerializeWorks) {
- OctStr32 octstr = {0};
- const OctStr32 expected_octstr = {0x01, 0x02, 0x03, 0x04};
- const uint32_t num = 0x01020304;
- Uint32Serialize(&octstr, num);
- EXPECT_EQ(expected_octstr, octstr);
- }
- ////////////////////////////////////////////////////////////////////////
- // Uint32Deserialize
- TEST(TinySerializeTest, Uint32DeserializeWorks) {
- const OctStr32 octstr = {0x01, 0x02, 0x03, 0x04};
- uint32_t num = 0;
- const uint32_t expected_num = 0x01020304;
- Uint32Deserialize(&num, &octstr);
- EXPECT_EQ(expected_num, num);
- }
- ////////////////////////////////////////////////////////////////////////
- // VliSerialize
- TEST(TinySerializeTest, VliSerializeWorks) {
- const VeryLargeInt vli = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
- 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
- BigNumStr serialize_vli = {0};
- const BigNumStr expected_serialize_vli = {
- 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
- 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
- 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
- VliSerialize(&serialize_vli, &vli);
- EXPECT_EQ(expected_serialize_vli, serialize_vli);
- }
- ////////////////////////////////////////////////////////////////////////
- // VliDeserialize
- TEST(TinySerializeTest, VliDeserializeWorks) {
- VeryLargeInt vli = {0};
- const VeryLargeInt expected_vli = {0x01020304, 0x05060708, 0x090A0B0C,
- 0x0D0E0F10, 0x11121314, 0x15161718,
- 0x191A1B1C, 0x1D1E1F20};
- const BigNumStr serialize_vli = {
- 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
- 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
- 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
- VliDeserialize(&vli, &serialize_vli);
- EXPECT_EQ(expected_vli, vli);
- }
- ////////////////////////////////////////////////////////////////////////
- // FqSerialize
- TEST(TinySerializeTest, FqSerializeWorks) {
- const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
- 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
- FqElemStr serialize_fqelm = {0};
- const FqElemStr expected_serialize_fqelm = {
- 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
- 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
- 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
- FqSerialize(&serialize_fqelm, &fqelm);
- EXPECT_EQ(expected_serialize_fqelm, serialize_fqelm);
- }
- ////////////////////////////////////////////////////////////////////////
- // FqDeserialize
- TEST(TinySerializeTest, FqDeserializeWorks) {
- const FqElemStr serialize_fqelm = {
- 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
- 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
- 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
- FqElem fqelm = {0};
- const FqElem expected_fqelm = {0x01020304, 0x05060708, 0x090A0B0C,
- 0x0D0E0F10, 0x11121314, 0x15161718,
- 0x191A1B1C, 0x1D1E1F20};
- FqDeserialize(&fqelm, &serialize_fqelm);
- EXPECT_EQ(expected_fqelm, fqelm);
- }
- ////////////////////////////////////////////////////////////////////////
- // Fq12Serialize
- TEST(TinySerializeTest, Fq12SerializeWorks) {
- const Fq12Elem fq12elm = {
- {{
- {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- {0x00000200, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- },
- {
- {0x00030000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- {0x04000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- },
- {
- {0x00000000, 0x00000005, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000600, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- }},
- {{
- {0x00000000, 0x00070000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x08000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- },
- {
- {0x00000000, 0x00000000, 0x00000009, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000000, 0x00000A00, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- },
- {
- {0x00000000, 0x00000000, 0x000B0000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000000, 0x0C000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- }}};
- Fq12ElemStr serialized_fq12elm = {0};
- const Fq12ElemStr expected_serialized_fq12elm = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- };
- Fq12Serialize(&serialized_fq12elm, &fq12elm);
- EXPECT_EQ(expected_serialized_fq12elm, serialized_fq12elm);
- }
- ////////////////////////////////////////////////////////////////////////
- // Fq12Deserialize
- TEST(TinySerializeTest, Fq12DeserializeWorks) {
- const Fq12ElemStr serialized_fq12elm = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- };
- Fq12Elem fq12elm = {0};
- const Fq12Elem expected_fq12elm = {
- {{
- {0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- {0x00000200, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- },
- {
- {0x00030000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- {0x04000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- },
- {
- {0x00000000, 0x00000005, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000600, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- }},
- {{
- {0x00000000, 0x00070000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x08000000, 0x00000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- },
- {
- {0x00000000, 0x00000000, 0x00000009, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000000, 0x00000A00, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- },
- {
- {0x00000000, 0x00000000, 0x000B0000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000000, 0x0C000000, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0x00000000},
- }}};
- Fq12Deserialize(&fq12elm, &serialized_fq12elm);
- EXPECT_EQ(expected_fq12elm, fq12elm);
- }
- ////////////////////////////////////////////////////////////////////////
- // FpSerialize
- TEST(TinySerializeTest, FpSerializeWorks) {
- const FpElem fpelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
- 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
- FpElemStr serialize_fpelm = {0};
- const FpElemStr expected_serialize_fpelm = {
- 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
- 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
- 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
- FpSerialize(&serialize_fpelm, &fpelm);
- EXPECT_EQ(expected_serialize_fpelm, serialize_fpelm);
- }
- ////////////////////////////////////////////////////////////////////////
- // FpDeserialize
- TEST(TinySerializeTest, FpDeserializeWorks) {
- const FpElemStr serialize_fpelm = {
- 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
- 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
- 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
- FpElem fpelm = {0};
- const FpElem expected_fpelm = {0x01020304, 0x05060708, 0x090A0B0C,
- 0x0D0E0F10, 0x11121314, 0x15161718,
- 0x191A1B1C, 0x1D1E1F20};
- FpDeserialize(&fpelm, &serialize_fpelm);
- EXPECT_EQ(expected_fpelm, fpelm);
- }
- ////////////////////////////////////////////////////////////////////////
- // EFqSerialize
- TEST(TinySerializeTest, EFqSerializeWorks) {
- const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
- 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
- const EccPointFq efq_point = {fqelm, fqelm};
- const FqElemStr serialize_fqelm = {
- 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
- 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
- 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
- G1ElemStr efq_point_serialize = {0};
- const G1ElemStr expected_efq_point_serialize = {serialize_fqelm,
- serialize_fqelm};
- EFqSerialize(&efq_point_serialize, &efq_point);
- EXPECT_EQ(expected_efq_point_serialize, efq_point_serialize);
- }
- ////////////////////////////////////////////////////////////////////////
- // EFqDeserialize
- TEST(TinySerializeTest, EFqDeserializeWorks) {
- const FqElemStr serialize_fqelm = {
- 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
- 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
- 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
- const G1ElemStr serialize_efq_point = {serialize_fqelm, serialize_fqelm};
- EccPointFq efq_point = {0};
- const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
- 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
- const EccPointFq expected_efq_point = {fqelm, fqelm};
- EFqDeserialize(&efq_point, &serialize_efq_point);
- EXPECT_EQ(expected_efq_point, efq_point);
- }
- ////////////////////////////////////////////////////////////////////////
- // EFq2Serialize
- TEST(TinySerializeTest, EFq2SerializeWorks) {
- const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
- 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
- const EccPointFq2 efq2_point = {{fqelm, fqelm}, {fqelm, fqelm}};
- const FqElemStr serialize_fqelm = {
- 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
- 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
- 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
- G2ElemStr efq2_point_serialize = {0};
- const G2ElemStr expected_efq2_point_serialize = {
- {serialize_fqelm, serialize_fqelm}, {serialize_fqelm, serialize_fqelm}};
- EFq2Serialize(&efq2_point_serialize, &efq2_point);
- EXPECT_EQ(expected_efq2_point_serialize, efq2_point_serialize);
- }
- ////////////////////////////////////////////////////////////////////////
- // EFq2Deserialize
- TEST(TinySerializeTest, EFq2DeserializeWorks) {
- const FqElemStr serialize_fqelm = {
- 0x1D, 0x1E, 0x1F, 0x20, 0x19, 0x1A, 0x1B, 0x1C, 0x15, 0x16, 0x17,
- 0x18, 0x11, 0x12, 0x13, 0x14, 0x0D, 0x0E, 0x0F, 0x10, 0x09, 0x0A,
- 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04};
- const G2ElemStr serialize_efq2_point = {{serialize_fqelm, serialize_fqelm},
- {serialize_fqelm, serialize_fqelm}};
- EccPointFq2 efq2_point = {0};
- const FqElem fqelm = {0x01020304, 0x05060708, 0x090A0B0C, 0x0D0E0F10,
- 0x11121314, 0x15161718, 0x191A1B1C, 0x1D1E1F20};
- const EccPointFq2 expected_efq2_point = {{fqelm, fqelm}, {fqelm, fqelm}};
- EFq2Deserialize(&efq2_point, &serialize_efq2_point);
- EXPECT_EQ(expected_efq2_point, efq2_point);
- }
- } // namespace
|