pcl_crypto_internal.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_CRYPTO_INTERNAL_H
  32. #define SGX_PCL_CRYPTO_INTERNAL_H
  33. extern "C"
  34. {
  35. int pcl_SHA256_Update(SHA256_CTX *c, void *data_, size_t len);
  36. int pcl_SHA256_Final(unsigned char *md, SHA256_CTX *c);
  37. int pcl_SHA256_Init(SHA256_CTX *c);
  38. typedef uint64_t u64;
  39. typedef uint32_t u32;
  40. typedef uint8_t u8;
  41. typedef struct {
  42. u64 hi, lo;
  43. } u128;
  44. int pcl_vpaes_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key);
  45. struct gcm128_context {
  46. /* Following 6 names follow names in GCM specification */
  47. union {
  48. u64 u[2];
  49. u32 d[4];
  50. u8 c[16];
  51. size_t t[16 / sizeof(size_t)];
  52. } Yi, EKi, EK0, len, Xi, H;
  53. /*
  54. * Relative position of Xi, H and pre-computed Htable is used in some
  55. * assembler modules, i.e. don't change the order!
  56. */
  57. u128 Htable[16];
  58. void (*gmult) (u64 Xi[2], const u128 Htable[16]);
  59. void (*ghash) (u64 Xi[2], const u128 Htable[16], const u8 *inp,
  60. size_t len);
  61. unsigned int mres, ares;
  62. block128_f block;
  63. void *key;
  64. };
  65. void pcl_CRYPTO_gcm128_init(GCM128_CONTEXT *ctx, void *key, block128_f block);
  66. void pcl_CRYPTO_gcm128_setiv(
  67. GCM128_CONTEXT *ctx,
  68. const unsigned char *iv,
  69. size_t len);
  70. int pcl_CRYPTO_gcm128_decrypt(GCM128_CONTEXT *ctx,
  71. const unsigned char *in, unsigned char *out,
  72. size_t len);
  73. int pcl_CRYPTO_gcm128_aad(
  74. GCM128_CONTEXT *ctx,
  75. const unsigned char *aad,
  76. size_t len);
  77. int pcl_CRYPTO_gcm128_finish(
  78. GCM128_CONTEXT *ctx,
  79. const unsigned char *tag,
  80. size_t len);
  81. void pcl_vpaes_encrypt(const unsigned char *in, unsigned char *out, const AES_KEY *key);
  82. #ifdef SE_SIM
  83. void make_kn(
  84. unsigned char *k1,
  85. const unsigned char *l,
  86. int bl);
  87. void pcl_vpaes_cbc_encrypt(
  88. uint8_t* in,
  89. uint8_t* out,
  90. size_t len,
  91. AES_KEY* wide_key_p,
  92. uint8_t* iv,
  93. bool encrypt);
  94. #endif // #ifdef SE_SIM
  95. }; // extern "C"
  96. #endif // #ifndef SGX_PCL_CRYPTO_INTERNAL_H