sigma_crypto_layer.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #ifndef _SIGMA_CRYPTO_LAYER_H_
  32. #define _SIGMA_CRYPTO_LAYER_H_
  33. #include <string>
  34. #include "pse_pr_inc.h"
  35. #include "pse_pr_types.h"
  36. #include "pse_pr_sigma_1_1_defs.h"
  37. #include "sgx_tcrypto.h"
  38. #include "pairing_blob.h"
  39. class SigmaCryptoLayer
  40. {
  41. public:
  42. SigmaCryptoLayer();
  43. ~SigmaCryptoLayer();
  44. ae_error_t DeriveSkMk(sgx_ecc_state_handle_t ecc_handle);
  45. ae_error_t calc_s2_hmac(SIGMA_HMAC* hmac,
  46. const SIGMA_S2_MESSAGE* s2,
  47. size_t nS2VLDataLen);
  48. ae_error_t calc_s3_hmac(SIGMA_HMAC* hmac,
  49. const SIGMA_S3_MESSAGE* s3,
  50. size_t nS3VLDataLen);
  51. ae_error_t ComputePR(SIGMA_SECRET_KEY* oldSK, Ipp8u byteToAdd, SIGMA_HMAC* hmac);
  52. ae_error_t ComputeId(Ipp8u byteToAdd, SHA256_HASH* hmac);
  53. ae_error_t MsgVerifyPch(Ipp8u* PubKeyPch, int PubKeyPchLen,
  54. Ipp8u* EpidParamsCert, Ipp8u* Msg, int MsgLen, Ipp8u* Bsn, int BsnLen,
  55. Ipp8u* Signature, int SignatureLen,
  56. Ipp8u* PrivRevList, int PrivRL_Len, Ipp8u* SigRevList, int SigRL_Len, Ipp8u* GrpRevList, int GrpRL_Len);
  57. const uint8_t* get_pub_key_gb_be() { return m_local_public_key_gb_big_endian; }
  58. const uint8_t* get_remote_pub_key_ga_be() { return m_remote_public_key_ga_big_endian; }
  59. void set_prv_key_b_le(Ipp8u* pb) { memcpy(m_local_private_key_b_little_endian, pb, sizeof(m_local_private_key_b_little_endian)); }
  60. void set_pub_key_gb_be(Ipp8u* pGb) { memcpy(m_local_public_key_gb_big_endian, pGb, sizeof(m_local_public_key_gb_big_endian)); }
  61. void set_remote_pub_key_ga_be(Ipp8u* pGa) { memcpy(m_remote_public_key_ga_big_endian, pGa, sizeof(m_remote_public_key_ga_big_endian)); }
  62. const uint8_t* get_SMK() { return m_SMK; }
  63. const uint8_t* get_SK() { return m_SK; }
  64. const uint8_t* get_MK() { return m_MK; }
  65. private:
  66. uint8_t m_local_private_key_b_little_endian[SIGMA_SESSION_PRIVKEY_LENGTH];
  67. uint8_t m_local_public_key_gb_big_endian[SIGMA_SESSION_PUBKEY_LENGTH];
  68. uint8_t m_remote_public_key_ga_big_endian[SIGMA_SESSION_PUBKEY_LENGTH];
  69. uint8_t m_SMK[SIGMA_SMK_LENGTH];
  70. SIGMA_SECRET_KEY m_SK;
  71. SIGMA_MAC_KEY m_MK;
  72. // Disable class operations (default constructor, copy constructor, assignment operator, and address-of operator)
  73. //SigmaCryptoLayer(void); // default constructor
  74. SigmaCryptoLayer(const SigmaCryptoLayer& rhs); // copy constructor
  75. SigmaCryptoLayer& operator=(const SigmaCryptoLayer& rhs); // assignment operator
  76. SigmaCryptoLayer* operator&(); // address-of operator
  77. const SigmaCryptoLayer* operator&() const; // address-of operator
  78. };
  79. #endif