helper.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. /**
  32. * File: helper.h
  33. * Description: Header file to some helper function to extract some enclave information
  34. *
  35. * Wrap functions to get PPID, PWK, PSID, PSVN, PSK and seal/unseal function
  36. */
  37. #ifndef _HELPER_CPP
  38. #define _HELPER_CPP
  39. #include "se_cdefs.h"
  40. #include "ae_ipp.h"
  41. #include "sgx_tseal.h"
  42. #include "provision_msg.h"
  43. #include "epid/common/errors.h"
  44. /*Function to get PvE PPID: AES-128-CMAC using Provisioning Key with both CPUSVN,ISVSVN to be 0*/
  45. /* return PVEC_SUCCESS on success*/
  46. pve_status_t get_ppid(
  47. ppid_t* ppid);
  48. /*Function to retrive PWK2
  49. return PVEC_SUCCESS on success*/
  50. pve_status_t get_pwk2(
  51. const psvn_t* psvn,
  52. const uint8_t n2[NONCE_2_SIZE],
  53. sgx_key_128bit_t* wrap_key);
  54. /*Function to get PSK for Provision Enclave.
  55. The key is used to seal the private parameter f before sending to backend server
  56. return PVEC_SUCCESS on success*/
  57. pve_status_t get_pve_psk(const psvn_t *psvn, /*input PSVN, must not be NULL*/
  58. sgx_key_128bit_t *seal_key); /*output PSK*/
  59. /*define the struct so that we could use the pointer of it to external memory only
  60. It is used to prevent mixing the internal and external memory pointer together*/
  61. typedef struct _external_memory_byte_t{
  62. uint8_t byte;
  63. }external_memory_byte_t;
  64. /*Function to copy out or copy in between external memory and EPC
  65. to increase the readability and also to take advantage of compile time checking*/
  66. void pve_memcpy_out(external_memory_byte_t *dst, const void *src, uint32_t size);
  67. void pve_memcpy_in(void *dst, const external_memory_byte_t *src, uint32_t size);
  68. /*a helper function to transform sgx_read_rand error code into pve error code*/
  69. pve_status_t se_read_rand_error_to_pve_error(sgx_status_t error);
  70. /*a helper function to transform ipp error code into pve error code*/
  71. pve_status_t ipp_error_to_pve_error(IppStatus status);
  72. pve_status_t sgx_error_to_pve_error(sgx_status_t status);
  73. pve_status_t epid_error_to_pve_error(EpidStatus epid_result);
  74. #endif