monotonic_counter_database_types.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (C) 2011-2018 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #ifndef _VMC_DATABASE_EXTERNAL_H
  32. #define _VMC_DATABASE_EXTERNAL_H
  33. #include "sgx_attributes.h"
  34. #include "sgx_report.h"
  35. #include "sgx_key.h"
  36. #include "pse_inc.h"
  37. #include "pse_types.h"
  38. #include "sgx_sha256_128.h"
  39. #define PSE_VMC_QUOTA_SIZE 256
  40. #define ROOT_HASH_SIZE SGX_SHA256_128_HASH_SIZE
  41. #define HASH_VALUE_SIZE SGX_SHA256_HASH_SIZE
  42. #define INIT_MAX_HASH_TREE_LAYER 14
  43. #define INIT_LEAF_NODE_ID_BASE 8192 // 2^13
  44. #define INIT_MAX_LEAF_NODE_ID 16383 // 2^14-1
  45. #define INIT_MIN_LEAF_NODE_ID (INIT_LEAF_NODE_ID_BASE)
  46. #define INIT_INTERNAL_NODE_NR ((INIT_MAX_HASH_TREE_LAYER)-2)
  47. #define INIT_TOTAL_ANCESTORS_NODE_NUMBER ((INIT_MAX_HASH_TREE_LAYER)-2)
  48. #define INIT_TOTAL_BROTHERS_NODE_NUMBER ((INIT_MAX_HASH_TREE_LAYER)-1)
  49. #define INIT_TOTAL_NODE_NUMBER_FOR_READING ((INIT_TOTAL_ANCESTORS_NODE_NUMBER)+(INIT_TOTAL_BROTHERS_NODE_NUMBER)+1)
  50. #define TREE_NODE_CACHE_SIZE static_cast<uint32_t>(sizeof(tree_node_cache_t))
  51. #define ROOT_NODE_SIZE static_cast<uint32_t>(sizeof(hash_tree_root_node_t))
  52. #define INTERNAL_NODE_SIZE static_cast<uint32_t>(sizeof(hash_tree_internal_node_t))
  53. #define LEAF_NODE_SIZE static_cast<uint32_t>(sizeof(hash_tree_leaf_node_t))
  54. #pragma pack(push, 1)
  55. // use script to generate this data set
  56. const uint8_t internal_node_hash_value_table[23][32] = {
  57. #include "hashtable.txt"
  58. };
  59. typedef struct _root_node {
  60. uint8_t hash[ROOT_HASH_SIZE];
  61. }hash_tree_root_node_t;
  62. typedef struct _internal_node {
  63. uint8_t hash[HASH_VALUE_SIZE];
  64. }hash_tree_internal_node_t;
  65. typedef struct _leaf_node {
  66. uint8_t is_used; // flag that indicates
  67. uint8_t nonce[13]; //
  68. uint32_t value; //
  69. uint16_t owner_policy; //
  70. uint8_t owner_attr_mask[16]; //
  71. uint8_t owner_id[32]; //
  72. sgx_isv_svn_t owner_svn; //creator's SVN
  73. }hash_tree_leaf_node_t, vmc_data_blob_t;
  74. #define UUID_ENTRY_INDEX_SIZE 3
  75. #define UUID_NONCE_SIZE 13
  76. typedef struct _mc_rpdb_uuid {
  77. uint8_t entry_index[UUID_ENTRY_INDEX_SIZE];
  78. uint8_t nonce[UUID_NONCE_SIZE];
  79. }mc_rpdb_uuid_t;
  80. #define INVALID_VMC_ID 0xFFFFFF
  81. #define SIM_ME_MC_READ 0
  82. #define SIM_ME_MC_INC_BY_ONE 1
  83. #define SIM_ME_MC_INC_BY_TWO 2
  84. #define MAX_VMC_ENTRY_NR_LIMIT 8192
  85. typedef struct _cal_root_hash_buf {
  86. uint8_t children_hash[HASH_VALUE_SIZE*2]; // left_child_hash followed by right_child_hash, for sha256-128 calculation
  87. uint8_t pairing_nonce[16];
  88. uint32_t rp_epoch;
  89. }cal_root_hash_buf_t;
  90. typedef enum _pse_vmc_db_state {
  91. PSE_VMC_DB_STATE_WORKABLE,
  92. PSE_VMC_DB_STATE_DOWN
  93. }pse_vmc_db_state_t;
  94. typedef enum _leafnode_flag_op_type {
  95. CLR_LEAFNODE_FLAG,
  96. SET_LEAFNODE_FLAG,
  97. GET_EMPTY_LEAFNODE,
  98. NON_OP
  99. }leafnode_flag_op_type;
  100. typedef struct _op_leafnode_flag_t {
  101. leafnode_flag_op_type op_type;
  102. sgx_measurement_t mr_signer; // The value of the enclave SIGNER's measurement
  103. }op_leafnode_flag_t;
  104. typedef struct _cse_rpdata_t
  105. {
  106. uint8_t rpdata_roothash[ROOT_HASH_SIZE];
  107. uint32_t rpdata_epoch;
  108. }cse_rpdata_t;
  109. typedef enum _rpdb_op_t {
  110. RPDB_OP_CREATE,
  111. RPDB_OP_READ,
  112. RPDB_OP_INCREMENT,
  113. RPDB_OP_DELETE
  114. }rpdb_op_t;
  115. typedef struct _leaf_node_cache_t {
  116. uint32_t node_id;
  117. hash_tree_leaf_node_t leaf;
  118. }leaf_node_cache_t;
  119. typedef struct _internal_node_cache_t {
  120. uint32_t node_id;
  121. hash_tree_internal_node_t internal;
  122. }internal_node_cache_t;
  123. typedef struct _pse_vmc_hash_tree_cache_t {
  124. leaf_node_cache_t self;
  125. leaf_node_cache_t brother;
  126. internal_node_cache_t ancestors[INIT_INTERNAL_NODE_NR];
  127. internal_node_cache_t brother_of_ancestors[INIT_INTERNAL_NODE_NR];
  128. hash_tree_root_node_t root;
  129. }pse_vmc_hash_tree_cache_t;
  130. typedef struct _pse_vmc_children_of_root_t {
  131. internal_node_cache_t left_child;
  132. internal_node_cache_t rigth_child;
  133. }pse_vmc_children_of_root_t;
  134. #pragma pack(pop)
  135. #endif