tpm2-testhelper.cc 8.8 KB

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