pcl_common.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 PCL_COMMON_H
  32. #define PCL_COMMON_H
  33. /*
  34. * This file includes definition used by PCL library and encryption tool
  35. */
  36. #define IN
  37. #define OUT
  38. #define INOUT
  39. // Define both ASSERT_CONCAT and ASSERT_CONCAT_ so that __COUNTER__ receives a value
  40. #define ASSERT_CONCAT_(a, b) a##b
  41. #ifndef ASSERT_CONCAT
  42. #define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b)
  43. #endif // #ifndef ASSERT_CONCAT
  44. #define PCL_COMPILE_TIME_ASSERT(exp) \
  45. enum { ASSERT_CONCAT(static_assert_, __COUNTER__) = 1/(!!(exp)) }
  46. // PCL uses AES with 16 Bytes block size
  47. #define PCL_AES_BLOCK_LEN (16)
  48. #define PCL_COUNTER_SIZE (16)
  49. #define PCL_AES_BLOCK_LEN_BITS (128)
  50. #define PCLTBL_SECTION_NAME ".pcltbl"
  51. typedef struct iv_t_
  52. {
  53. uint8_t val[SGX_AESGCM_IV_SIZE];
  54. uint8_t reserved[4];
  55. }iv_t;
  56. typedef struct rva_size_tag_iv_t_
  57. {
  58. size_t rva;
  59. size_t size;
  60. sgx_cmac_128bit_tag_t tag;
  61. iv_t iv;
  62. }rva_size_tag_iv_t;
  63. // Hardcoded maximal size of sealed bolb. ISV can modify if requried
  64. #define PCL_SEALED_BLOB_SIZE (0x250)
  65. #define SGX_PCL_GUID_SIZE (16)
  66. // Hardcoded maximal number of encrypted sections. ISV can modify if requried
  67. #define PCL_MAX_NUM_ENCRYPTED_SECTIONS (0x80)
  68. typedef enum pcl_status_e_
  69. {
  70. PCL_PLAIN = 0xABABABAB,
  71. PCL_CIPHER = 0xBCBCBCBC,
  72. PCL_RUNNING = 0xDEDEDEDE,
  73. PCL_DONE = 0xFAFAFAFA,
  74. }pcl_status_e;
  75. typedef struct pcl_table_t_
  76. {
  77. pcl_status_e pcl_state; // Current state of PCL
  78. uint32_t reserved1[3]; // Must be 0
  79. uint8_t pcl_guid[SGX_PCL_GUID_SIZE]; // GUID must match GUID in Sealed blob
  80. size_t sealed_blob_size; // Size of selaed blob
  81. uint32_t reserved2[2]; // Must be 0
  82. uint8_t sealed_blob[PCL_SEALED_BLOB_SIZE]; // For security, sealed blob is copied into enclave
  83. uint8_t decryption_key_hash[SGX_SHA256_HASH_SIZE]; // SHA256 digest of decryption key
  84. uint32_t num_rvas; // Number of RVAs
  85. uint32_t reserved3[3]; // Must be 0
  86. rva_size_tag_iv_t rvas_sizes_tags_ivs[PCL_MAX_NUM_ENCRYPTED_SECTIONS]; // Array of rva_size_tag_iv_t
  87. }pcl_table_t;
  88. #endif // #ifndef PCL_COMMON_H