1 /*############################################################################
2 # Copyright 2017 Intel Corporation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 ############################################################################*/
16 /// TPM fixture class implementation.
17 /*! \file */
18 #include "epid/member/tpm2/unittests/tpm2-testhelper.h"
19
20 #include <climits>
21 #include <cstring>
22
23 #include "epid/common-testhelper/epid2params_wrapper-testhelper.h"
24 #include "epid/common-testhelper/epid_params-testhelper.h"
25
26 extern "C" {
27 #include "epid/common/types.h"
28 }
29
operator ==(FpElemStr const & lhs,FpElemStr const & rhs)30 bool operator==(FpElemStr const& lhs, FpElemStr const& rhs) {
31 return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
32 }
operator ==(G1ElemStr const & lhs,G1ElemStr const & rhs)33 bool operator==(G1ElemStr const& lhs, G1ElemStr const& rhs) {
34 return 0 == std::memcmp(&lhs, &rhs, sizeof(lhs));
35 }
36
37 const std::vector<uint8_t> EpidTpm2Test::kTpmFfElemStrData = {
38 0x98, 0x34, 0x87, 0x6d, 0xcf, 0xb0, 0x5c, 0xb1, 0x67, 0xa5, 0xc2,
39 0x49, 0x53, 0xeb, 0xa5, 0x8c, 0x4a, 0xc8, 0x9b, 0x1a, 0xdf, 0x57,
40 0xf2, 0x8f, 0x2f, 0x9d, 0x09, 0xaf, 0x10, 0x7e, 0xe8, 0xf0};
41
42 const G1ElemStr EpidTpm2Test::kEpidPointStr = {
43 {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}},
46 {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}};
49
50 const uint8_t
51 EpidTpm2Test::kDigestSha256[EPID_SHA256_DIGEST_BITSIZE / CHAR_BIT] = {
52 0x11, 0x40, 0xb5, 0x6c, 0x6d, 0x47, 0x09, 0x0b, 0x05, 0xd6, 0x43,
53 0x56, 0xe0, 0x7c, 0xc6, 0x8e, 0xa1, 0x65, 0x67, 0xfd, 0xa7, 0x07,
54 0x87, 0x9b, 0x36, 0x2d, 0x41, 0x35, 0x63, 0x61, 0x31, 0x22};
55
56 const FpElemStr EpidTpm2Test::kMemberFValue = {
57 0x48, 0x40, 0xb5, 0x6c, 0x6d, 0x47, 0x09, 0x0b, 0x05, 0xd6, 0x43,
58 0x56, 0xe0, 0x7c, 0xc6, 0x8e, 0xa1, 0x65, 0x67, 0xfd, 0xa7, 0x07,
59 0x87, 0x9b, 0x36, 0x2d, 0x41, 0x35, 0x63, 0x61, 0x31, 0xc7};
60 const G1ElemStr EpidTpm2Test::kP1Str = {
61 {{{0x12, 0xA6, 0x5B, 0xD6, 0x91, 0x8D, 0x50, 0xA7, 0x66, 0xEB, 0x7D,
62 0x52, 0xE3, 0x40, 0x17, 0x60, 0x7F, 0xDF, 0x6C, 0xA1, 0x2C, 0x1A,
63 0x37, 0xE0, 0x92, 0xC0, 0xF7, 0xB9, 0x76, 0xAB, 0xB1, 0x8A}}},
64 {{{0x78, 0x65, 0x28, 0xCB, 0xAF, 0x07, 0x52, 0x50, 0x55, 0x7A, 0x5F,
65 0x30, 0x0A, 0xC0, 0xB4, 0x6B, 0xEA, 0x6F, 0xE2, 0xF6, 0x6D, 0x96,
66 0xF7, 0xCD, 0xC8, 0xD3, 0x12, 0x7F, 0x1F, 0x3A, 0x8B, 0x42}}}};
67 const G1ElemStr EpidTpm2Test::kg1Str = {
68 {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
69 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
70 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}},
71 {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
72 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}}}};
74
75 const std::vector<uint8_t> EpidTpm2Test::kS2Sha256 = {0, 0, 0, 4,
76 'a', 'b', 'c'};
77 const FqElemStr EpidTpm2Test::kY2Sha256Str = {
78 {{0x8A, 0x43, 0xA1, 0x04, 0xB1, 0x3F, 0x3C, 0xB4, 0xBD, 0x67, 0x38,
79 0xB1, 0x07, 0xF0, 0x7A, 0x32, 0x7E, 0xCD, 0xF0, 0x2E, 0x62, 0x3E,
80 0x2C, 0x1F, 0x48, 0xAA, 0x0D, 0x6C, 0xDC, 0x48, 0xF9, 0xF7}}};
81 const G1ElemStr EpidTpm2Test::kP2Sha256Str = {
82 {{{0x2E, 0xBB, 0x50, 0x4D, 0x88, 0xFF, 0x25, 0x62, 0xF3, 0x71, 0x65,
83 0x81, 0xAD, 0xBE, 0x83, 0x6E, 0x54, 0xF5, 0xA6, 0x2A, 0x70, 0xE6,
84 0x18, 0x6B, 0xD5, 0x4A, 0x10, 0x3C, 0x80, 0x08, 0x95, 0x3D}}},
85 {{{0x8A, 0x43, 0xA1, 0x04, 0xB1, 0x3F, 0x3C, 0xB4, 0xBD, 0x67, 0x38,
86 0xB1, 0x07, 0xF0, 0x7A, 0x32, 0x7E, 0xCD, 0xF0, 0x2E, 0x62, 0x3E,
87 0x2C, 0x1F, 0x48, 0xAA, 0x0D, 0x6C, 0xDC, 0x48, 0xF9, 0xF7}}}};
88 const G1ElemStr EpidTpm2Test::kP2Sha256ExpF = {
89 {{{0xd0, 0xf3, 0xd9, 0xea, 0x45, 0x24, 0x96, 0xb8, 0x3e, 0x2f, 0xf2,
90 0x18, 0x12, 0xad, 0xa7, 0xab, 0xe3, 0x1e, 0xff, 0xe7, 0xf7, 0x61,
91 0x28, 0xae, 0x0a, 0x7c, 0x0f, 0xd9, 0x74, 0x0f, 0x4a, 0x94}}},
92 {{{0xb7, 0xda, 0xd5, 0x97, 0x33, 0xab, 0xb6, 0x3c, 0xf7, 0x3b, 0xec,
93 0xa4, 0x7f, 0xe6, 0x23, 0xd4, 0xf6, 0xe2, 0x9b, 0xdb, 0xa6, 0xbb,
94 0xdf, 0xee, 0x62, 0x33, 0xcd, 0x88, 0x25, 0x52, 0xba, 0x99}}}};
95
96 const std::vector<uint8_t> EpidTpm2Test::kS2Sha384 = {0, 0, 0, 0,
97 'a', 'b', 'c'};
98 const FqElemStr EpidTpm2Test::kY2Sha384Str = {
99 {{0x0E, 0x86, 0x11, 0x90, 0xAF, 0xEF, 0xEB, 0x79, 0x4B, 0x3E, 0x80,
100 0x92, 0x94, 0x3B, 0x2F, 0x5E, 0x72, 0x21, 0xEF, 0xF8, 0xBC, 0xE3,
101 0x48, 0xA9, 0xD0, 0x31, 0x19, 0xAC, 0xD1, 0xD7, 0x49, 0x87}}};
102 const G1ElemStr EpidTpm2Test::kP2Sha384Str = {
103 {{{0xE1, 0xC8, 0x28, 0xB1, 0x9A, 0xDF, 0x5D, 0x4B, 0xC4, 0x25, 0x90,
104 0xFB, 0x38, 0x20, 0xD4, 0x8B, 0x30, 0x8F, 0x95, 0x76, 0xC3, 0x7F,
105 0x9D, 0xAD, 0x94, 0xC4, 0x31, 0x80, 0xD7, 0xDF, 0xD5, 0xFE}}},
106 {{{0x0E, 0x86, 0x11, 0x90, 0xAF, 0xEF, 0xEB, 0x79, 0x4B, 0x3E, 0x80,
107 0x92, 0x94, 0x3B, 0x2F, 0x5E, 0x72, 0x21, 0xEF, 0xF8, 0xBC, 0xE3,
108 0x48, 0xA9, 0xD0, 0x31, 0x19, 0xAC, 0xD1, 0xD7, 0x49, 0x87}}}};
109 const G1ElemStr EpidTpm2Test::kP2Sha384ExpF = {
110 {{{0x97, 0x90, 0xaf, 0xe1, 0xc3, 0x7d, 0x6f, 0xf3, 0x71, 0x88, 0x6c,
111 0x8b, 0x20, 0xc8, 0x50, 0x0d, 0x74, 0x31, 0x2a, 0x7e, 0x7c, 0x8c,
112 0xba, 0xf1, 0xd9, 0xac, 0x2f, 0xb9, 0x7a, 0xbc, 0xbb, 0x58}}},
113 {{{0xad, 0x2b, 0xcf, 0x14, 0x2f, 0x60, 0xbb, 0xc8, 0xea, 0x9d, 0x8a,
114 0x54, 0xa6, 0x3b, 0x3b, 0x46, 0x84, 0xdf, 0x72, 0xe2, 0xa9, 0x91,
115 0x2b, 0x06, 0xe5, 0x7f, 0x63, 0x0e, 0x99, 0x7a, 0xe7, 0xd2}}}};
116
117 const std::vector<uint8_t> EpidTpm2Test::kS2Sha512 = {0, 0, 0, 1,
118 'a', 'b', 'c'};
119 const FqElemStr EpidTpm2Test::kY2Sha512Str = {
120 {{0x4C, 0x0E, 0xA7, 0x62, 0x17, 0xB9, 0xFB, 0xE5, 0x21, 0x7D, 0x54,
121 0x24, 0xE0, 0x2B, 0x87, 0xF7, 0x69, 0x54, 0x0C, 0xC6, 0xAD, 0xF2,
122 0xF2, 0x7B, 0xE6, 0x91, 0xD8, 0xF3, 0x40, 0x6C, 0x8F, 0x03}}};
123 const G1ElemStr EpidTpm2Test::kP2Sha512Str = {
124 {{{0x8C, 0x62, 0xA0, 0x2D, 0x55, 0x55, 0x55, 0x86, 0xBC, 0x82, 0xA6,
125 0xA2, 0x21, 0x97, 0x9B, 0x9B, 0xB4, 0x03, 0x3D, 0x83, 0xF3, 0xBA,
126 0xDA, 0x9C, 0x42, 0xF7, 0xB3, 0x94, 0x99, 0x2A, 0x96, 0xE4}}},
127 {{{0x4C, 0x0E, 0xA7, 0x62, 0x17, 0xB9, 0xFB, 0xE5, 0x21, 0x7D, 0x54,
128 0x24, 0xE0, 0x2B, 0x87, 0xF7, 0x69, 0x54, 0x0C, 0xC6, 0xAD, 0xF2,
129 0xF2, 0x7B, 0xE6, 0x91, 0xD8, 0xF3, 0x40, 0x6C, 0x8F, 0x03}}}};
130 const G1ElemStr EpidTpm2Test::kP2Sha512ExpF = {
131 {{{0xb4, 0xbc, 0x3d, 0x8c, 0x7b, 0xc3, 0x08, 0x89, 0xa3, 0x0e, 0x66,
132 0x7f, 0x6d, 0x89, 0xab, 0x9b, 0xc4, 0xda, 0x14, 0x93, 0x62, 0x32,
133 0x0d, 0xe2, 0x95, 0xb5, 0x71, 0x2d, 0x75, 0xbe, 0x63, 0xd4}}},
134 {{{0xf6, 0x20, 0x85, 0x93, 0x3f, 0xfb, 0xf3, 0xad, 0xa9, 0x7e, 0xd3,
135 0x93, 0x29, 0x22, 0x1b, 0x88, 0x56, 0xf0, 0xbd, 0x62, 0xbd, 0x63,
136 0x8b, 0xcf, 0xe1, 0x62, 0x83, 0xb6, 0x1c, 0x56, 0x29, 0xc3}}}};
137
138 const std::vector<uint8_t> EpidTpm2Test::kS2Sha512256 = {0, 0, 0, 0,
139 'a', 'b', 'c'};
140 const FqElemStr EpidTpm2Test::kY2Sha512256Str = {
141 {{0x30, 0xbe, 0x3f, 0x12, 0x00, 0x74, 0x48, 0xaa, 0x91, 0x90, 0x84,
142 0x12, 0x4d, 0x58, 0x54, 0xe7, 0x04, 0x65, 0x37, 0x97, 0x88, 0xcf,
143 0x67, 0xa0, 0x8c, 0x56, 0x93, 0xa7, 0x7f, 0xe8, 0x74, 0xfc}}};
144 const G1ElemStr EpidTpm2Test::kP2Sha512256Str = {
145 {{{0x63, 0x28, 0x40, 0x14, 0x73, 0xd5, 0x91, 0xc4, 0xa2, 0xa4, 0xb6,
146 0xd8, 0xa8, 0x75, 0x21, 0xd1, 0x26, 0x4e, 0x42, 0x13, 0x1f, 0xfa,
147 0xed, 0x90, 0x8d, 0x56, 0x34, 0x57, 0x8a, 0x3a, 0x47, 0xa0}}},
148 {{{0x30, 0xbe, 0x3f, 0x12, 0x00, 0x74, 0x48, 0xaa, 0x91, 0x90, 0x84,
149 0x12, 0x4d, 0x58, 0x54, 0xe7, 0x04, 0x65, 0x37, 0x97, 0x88, 0xcf,
150 0x67, 0xa0, 0x8c, 0x56, 0x93, 0xa7, 0x7f, 0xe8, 0x74, 0xfc}}}};
151 const G1ElemStr EpidTpm2Test::kP2Sha512256ExpF = {
152 {{{0xa7, 0xef, 0x09, 0x07, 0x5e, 0xf1, 0xce, 0x85, 0xe8, 0x85, 0x03,
153 0xbe, 0xdd, 0x2e, 0x32, 0x25, 0xab, 0x58, 0x90, 0xc4, 0x59, 0x60,
154 0x1c, 0x17, 0x3b, 0x8c, 0x62, 0x35, 0xd3, 0x9f, 0x77, 0x8f}}},
155 {{{0x38, 0xce, 0x8b, 0x36, 0xc1, 0xb1, 0xae, 0xc5, 0x61, 0x60, 0x12,
156 0xf0, 0x5b, 0xc1, 0xb8, 0x5e, 0xf3, 0xb9, 0xa6, 0x26, 0x7f, 0x27,
157 0x5b, 0x78, 0x61, 0x27, 0xe6, 0x0b, 0x38, 0x37, 0x89, 0x56}}}};
158