123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- /*############################################################################
- # 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.
- ############################################################################*/
- /*!
- * \file
- * \brief Provision compressed unit tests.
- */
- #include <cstring>
- #include <vector>
- #include "epid/common-testhelper/epid_gtest-testhelper.h"
- #include "gtest/gtest.h"
- #include "epid/common-testhelper/errors-testhelper.h"
- #include "epid/common-testhelper/mem_params-testhelper.h"
- #include "epid/common-testhelper/prng-testhelper.h"
- #include "epid/member/unittests/member-testhelper.h"
- extern "C" {
- #include "epid/member/api.h"
- #include "epid/member/src/context.h"
- }
- namespace {
- EpidStatus ProvisionCompressedAndStart(
- MemberCtx* ctx, GroupPubKey const* pub_key,
- CompressedPrivKey const* compressed_privkey,
- MemberPrecomp const* precomp_str) {
- EpidStatus sts;
- sts = EpidProvisionCompressed(ctx, pub_key, compressed_privkey, precomp_str);
- if (sts != kEpidNoErr) {
- return sts;
- }
- sts = EpidMemberStartup(ctx);
- return sts;
- }
- TEST_F(EpidMemberTest, ProvisionCompressedFailsGivenNullParameters) {
- Prng prng;
- GroupPubKey pub_key = this->kGrpXKey;
- CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey;
- // Note: this MemberPrecomp is for the wrong group, however it should not
- // be checked in Provision because doing so would negate the performance
- // boost of using the precomp.
- MemberPrecomp precomp = this->kMemberPrecomp;
- MemberParams params = {0};
- SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms);
- MemberCtxObj member(¶ms);
- EXPECT_EQ(kEpidBadArgErr,
- EpidProvisionCompressed(nullptr, &pub_key, &priv_key, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- EpidProvisionCompressed(member, nullptr, &priv_key, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- EpidProvisionCompressed(member, &pub_key, nullptr, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- EpidProvisionCompressed(nullptr, &pub_key, &priv_key, nullptr));
- EXPECT_EQ(kEpidBadArgErr,
- EpidProvisionCompressed(member, nullptr, &priv_key, nullptr));
- EXPECT_EQ(kEpidBadArgErr,
- EpidProvisionCompressed(member, &pub_key, nullptr, nullptr));
- }
- TEST_F(EpidMemberTest, ProvisionCompressedSucceedsGivenValidParameters) {
- Prng prng;
- GroupPubKey pub_key = this->kGrpXKey;
- CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey;
- // Note: this MemberPrecomp is for the wrong group, however it should not
- // be checked in Provision because doing so would negate the performance
- // boost of using the precomp.
- MemberPrecomp precomp = this->kMemberPrecomp;
- MemberParams params = {0};
- SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms);
- MemberCtxObj member(¶ms);
- EXPECT_EQ(kEpidNoErr,
- EpidProvisionCompressed(member, &pub_key, &priv_key, &precomp));
- EXPECT_EQ(kEpidNoErr,
- EpidProvisionCompressed(member, &pub_key, &priv_key, nullptr));
- }
- TEST_F(EpidMemberTest, ProvisionCompressedFailsForInvalidGroupPubKey) {
- Prng prng;
- GroupPubKey pub_key = this->kGrpXKey;
- CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey;
- // Note: this MemberPrecomp is for the wrong group, however it should not
- // be checked in Provision because doing so would negate the performance
- // boost of using the precomp.
- MemberPrecomp precomp = this->kMemberPrecomp;
- MemberParams params = {0};
- SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms);
- MemberCtxObj member(¶ms);
- pub_key = this->kGrpXKey;
- pub_key.h1.x.data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
- pub_key = this->kGrpXKey;
- pub_key.h1.y.data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
- pub_key = this->kGrpXKey;
- pub_key.w.x[0].data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
- pub_key = this->kGrpXKey;
- pub_key.w.x[1].data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
- pub_key = this->kGrpXKey;
- pub_key.w.y[0].data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
- pub_key = this->kGrpXKey;
- pub_key.w.y[1].data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
- }
- TEST_F(EpidMemberTest, ProvisionCompressedFailsForInvalidPrivateKey) {
- Prng prng;
- GroupPubKey pub_key = this->kGrpXKey;
- CompressedPrivKey priv_key = this->kGrpXMember9CompressedKey;
- // Note: this MemberPrecomp is for the wrong group, however it should not
- // be checked in Provision because doing so would negate the performance
- // boost of using the precomp.
- MemberPrecomp precomp = this->kMemberPrecomp;
- MemberParams params = {0};
- SetMemberParams(&Prng::Generate, &prng, nullptr, ¶ms);
- MemberCtxObj member(¶ms);
- priv_key = this->kGrpXMember9CompressedKey;
- priv_key.ax.data.data[0]++;
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
- priv_key = this->kGrpXMember9CompressedKey;
- priv_key.seed.data[0]++;
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, &precomp));
- EXPECT_EQ(kEpidBadArgErr,
- ProvisionCompressedAndStart(member, &pub_key, &priv_key, nullptr));
- }
- } // namespace
|