xil-versal-glue.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* xil-versal-glue.h
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifndef WOLF_XIL_CRYPT_VERSAL_GLUE_H
  22. #define WOLF_XIL_CRYPT_VERSAL_GLUE_H
  23. #include <wolfssl/wolfcrypt/settings.h>
  24. #ifdef WOLFSSL_XILINX_CRYPT_VERSAL
  25. #include <xil_types.h>
  26. #include <xsecure_mailbox.h>
  27. #include <xsecure_defs.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #define XIL_CAST_U64(v) ((u64)(UINTPTR)(v))
  32. #ifdef XSECURE_CACHE_DISABLE
  33. #define WOLFSSL_XIL_DCACHE_INVALIDATE_RANGE(p, l) WC_DO_NOTHING
  34. #define WOLFSSL_XIL_DCACHE_FLUSH_RANGE(p, l) WC_DO_NOTHING
  35. #else
  36. #define WOLFSSL_XIL_DCACHE_INVALIDATE_RANGE(p, l) \
  37. do{ Xil_DCacheInvalidateRange((p), (l)); }while(0)
  38. #define WOLFSSL_XIL_DCACHE_FLUSH_RANGE(p, l) \
  39. do{ Xil_DCacheFlushRange((p), (l)); }while(0)
  40. #endif
  41. #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_DEBUG_ERRORS_ONLY) \
  42. && !defined(WOLFSSL_XIL_MSG_NO_SLEEP)
  43. #include <unistd.h>
  44. #define WOLFSSL_XIL_SLEEP(n) do{ sleep(n); }while(0)
  45. #else
  46. #define WOLFSSL_XIL_SLEEP(n) WC_DO_NOTHING
  47. #endif
  48. /* Provide our own message macro since the Versal PLM maybe
  49. * prints an error message to the same console.
  50. * In order to not mix those outputs up, sleep a little while
  51. * before printing our message.
  52. * This behavior can be disabled by defining `WOLFSSL_XIL_MSG_NO_SLEEP`
  53. */
  54. #define WOLFSSL_XIL_MSG(msg) do { \
  55. WOLFSSL_XIL_SLEEP(1); \
  56. WOLFSSL_MSG(msg); \
  57. } while(0)
  58. #define WOLFSSL_XIL_ERROR(msg, err) do { \
  59. WOLFSSL_XIL_MSG(msg); \
  60. WOLFSSL_MSG_EX("Xilinx API returned 0x%08x: %s", (err), \
  61. wc_XsecureErrorToString(err)); \
  62. } while(0)
  63. #define WOLFSSL_XSECURE_QWORD_SIZE 16u
  64. #define WOLFSSL_XSECURE_AES_KEY_SIZE 32u
  65. #define WOLFSSL_XSECURE_AES_IV_SIZE 12u
  66. #define WOLFSSL_XSECURE_RSA_KEY_SIZE 512u
  67. enum {
  68. WOLFSSL_XSECURE_ECC_NIST_P384 = 4,
  69. WOLFSSL_XSECURE_ECC_NIST_P521 = 5,
  70. WOLFSSL_XSECURE_ECC_NUM
  71. };
  72. typedef struct Xsecure {
  73. ALIGN64 u8 mem[XSECURE_SHARED_MEM_SIZE];
  74. XMailbox mb;
  75. XSecure_ClientInstance cinst;
  76. } wc_Xsecure;
  77. WOLFSSL_LOCAL int wc_InitXsecure(wc_Xsecure* xsec);
  78. WOLFSSL_LOCAL const char *wc_XsecureErrorToString(int err);
  79. #ifdef __cplusplus
  80. } /* extern "C" */
  81. #endif
  82. #endif /* WOLFSSL_XILINX_CRYPT_VERSAL */
  83. #endif /* WOLF_XIL_CRYPT_VERSAL_GLUE_H */