se_sig_rl.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (C) 2011-2017 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. #include "stdint.h"
  32. #include "se_sig_rl.h"
  33. #include "byte_order.h"
  34. #include "sgx_quote.h"
  35. #include "se_quote_internal.h"
  36. uint64_t se_get_sig_rl_size(const se_sig_rl_t *p_sig_rl)
  37. {
  38. uint64_t n2 = (p_sig_rl) ? lv_ntohl(p_sig_rl->sig_rl.n2) : 0;
  39. return(sizeof(se_sig_rl_t) - sizeof(p_sig_rl->sig_rl.bk[0])
  40. + n2 * sizeof(p_sig_rl->sig_rl.bk[0]) + 2 * SE_ECDSA_SIGN_SIZE);
  41. }
  42. sgx_status_t sgx_get_quote_size(const uint8_t *sig_rl, uint32_t* p_quote_size)
  43. {
  44. if(!p_quote_size)
  45. return SGX_ERROR_INVALID_PARAMETER;
  46. uint64_t quote_size = 0;
  47. uint64_t sign_size = 0;
  48. uint64_t n2 = 0;
  49. const se_sig_rl_t *p_sig_rl = reinterpret_cast<const se_sig_rl_t *>(sig_rl);
  50. if(sig_rl)
  51. {
  52. if(p_sig_rl->protocol_version != SE_EPID_SIG_RL_VERSION
  53. || p_sig_rl->epid_identifier != SE_EPID_SIG_RL_ID)
  54. {
  55. return SGX_ERROR_INVALID_PARAMETER;
  56. }
  57. }
  58. n2 = (sig_rl) ? lv_ntohl(p_sig_rl->sig_rl.n2) : 0;
  59. sign_size = sizeof(EpidSignature) - sizeof(NrProof) + n2*sizeof(NrProof);
  60. quote_size = SE_QUOTE_LENGTH_WITHOUT_SIG + sign_size;
  61. if (quote_size >= 1ull<<32)
  62. {
  63. return SGX_ERROR_INVALID_PARAMETER;
  64. }
  65. *p_quote_size = static_cast<uint32_t>(quote_size);
  66. return SGX_SUCCESS;
  67. }