pcl_cmac.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. * Copyright (c) 1998-2017 The OpenSSL Project. All rights reserved.
  33. *
  34. * Redistribution and use in source and binary forms, with or without
  35. * modification, are permitted provided that the following conditions
  36. * are met:
  37. *
  38. * 1. Redistributions of source code must retain the above copyright
  39. * notice, this list of conditions and the following disclaimer.
  40. *
  41. * 2. Redistributions in binary form must reproduce the above copyright
  42. * notice, this list of conditions and the following disclaimer in
  43. * the documentation and/or other materials provided with the
  44. * distribution.
  45. *
  46. * 3. All advertising materials mentioning features or use of this
  47. * software must display the following acknowledgment:
  48. * "This product includes software developed by the OpenSSL Project
  49. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  50. *
  51. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  52. * endorse or promote products derived from this software without
  53. * prior written permission. For written permission, please contact
  54. * openssl-core@openssl.org.
  55. *
  56. * 5. Products derived from this software may not be called "OpenSSL"
  57. * nor may "OpenSSL" appear in their names without prior written
  58. * permission of the OpenSSL Project.
  59. *
  60. * 6. Redistributions of any form whatsoever must retain the following
  61. * acknowledgment:
  62. * "This product includes software developed by the OpenSSL Project
  63. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  64. *
  65. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  66. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  68. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  69. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  70. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  71. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  72. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  73. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  74. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  75. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  76. * OF THE POSSIBILITY OF SUCH DAMAGE.
  77. * ====================================================================
  78. *
  79. * This product includes cryptographic software written by Eric Young
  80. * (eay@cryptsoft.com). This product includes software written by Tim
  81. * Hudson (tjh@cryptsoft.com).
  82. *
  83. */
  84. /* Content from openssl-1.1.0e/crypto/cmac/cmac.c */
  85. #include <openssl/aes.h>
  86. #include <openssl/sha.h>
  87. #include <openssl/modes.h>
  88. #include <sgx_tseal.h>
  89. #include <pcl_common.h>
  90. #include <pcl_internal.h>
  91. #include <pcl_crypto_internal.h>
  92. #ifdef SE_SIM
  93. void make_kn(
  94. unsigned char *k1,
  95. const unsigned char *l,
  96. int bl)
  97. {
  98. int i;
  99. unsigned char c = l[0], carry = c >> 7, cnext;
  100. /* Shift block to left, including carry */
  101. for (i = 0; i < bl - 1; i++, c = cnext)
  102. k1[i] = (c << 1) | ((cnext = l[i + 1]) >> 7);
  103. /* If MSB set fixup with R */
  104. k1[i] = (c << 1) ^ ((0 - carry) & (bl == 16 ? 0x87 : 0x1b));
  105. }
  106. #endif // #ifdef SE_SIM