pcl_internal.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 SGX_PCL_INTERNAL_H
  32. #define SGX_PCL_INTERNAL_H
  33. #define ALIGN_X2Y_AUX(x,y) \
  34. (x % y ? x + y - (x % y) : x)
  35. #define ALIGN_X2Y(x,y) ALIGN_X2Y_AUX((x),(y))
  36. #define CASTU8P(x) ((uint8_t*)(x))
  37. #define CAST_VOLATILE_U8P(x) ((volatile uint8_t*)(x))
  38. #define CASTU64(x) ((uint64_t)(x))
  39. #define ROUND_TO(x,y) ALIGN_X2Y(x,y)
  40. #define MAX(x,y) ((x)>(y)?(x):(y))
  41. #define assert(x)
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif // #ifdef __cplusplus
  45. void pcl_memcpy(OUT void* dst, IN void* src, size_t size);
  46. void pcl_memset(OUT void* dst, uint8_t val, size_t size);
  47. void pcl_volatile_memset(OUT volatile void* dst, uint8_t val, size_t size);
  48. // code taken from consttime_memequal
  49. uint32_t pcl_consttime_memequal(IN const void *b1, IN const void *b2, size_t len);
  50. int pcl_decrypt(
  51. IN unsigned char *ciphertext,
  52. size_t ciphertext_len,
  53. IN unsigned char *aad,
  54. size_t aad_len,
  55. IN unsigned char *tag,
  56. IN unsigned char *key,
  57. IN unsigned char *iv,
  58. OUT unsigned char *plaintext);
  59. sgx_status_t pcl_sha256(IN uint8_t* buf, size_t buflen, OUT uint8_t* hash);
  60. sgx_status_t pcl_unseal_data(
  61. IN const sgx_sealed_data_t *p_sealed_data,
  62. IN uint8_t *p_additional_MACtext,
  63. INOUT uint32_t *p_additional_MACtext_length,
  64. OUT uint8_t *p_decrypted_text,
  65. INOUT uint32_t *p_decrypted_text_length);
  66. sgx_status_t pcl_gcm_decrypt(
  67. IN uint8_t* plaintext,
  68. OUT uint8_t* ciphertext,
  69. size_t textlen,
  70. IN uint8_t* aad,
  71. size_t aad_len,
  72. IN uint8_t* key,
  73. IN uint8_t* iv,
  74. IN uint8_t* tag);
  75. uint32_t pcl_bswap32(uint32_t val);
  76. uint64_t pcl_bswap64(uint64_t val);
  77. sgx_status_t pcl_increment_iv(INOUT uint8_t* iv);
  78. void abort(void) __attribute__((__noreturn__));
  79. int pcl_is_outside_enclave(const void *addr, size_t size);
  80. int pcl_is_within_enclave(const void *addr, size_t size);
  81. #ifdef __cplusplus
  82. }; // extern "C"
  83. #endif // #ifdef __cplusplus
  84. #endif // #ifndef SGX_PCL_INTERNAL_H