pal_crypto.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Copyright (C) 2014 OSCAR lab, Stony Brook University
  2. Copyright (C) 2017 Fortanix, Inc.
  3. This file is part of Graphene Library OS.
  4. Graphene Library OS is free software: you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation, either version 3 of the
  7. License, or (at your option) any later version.
  8. Graphene Library OS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. /*
  15. * Cryptographic primitive abstractions. This layer provides a way to
  16. * change the crypto library without changing the rest of Graphene code
  17. * by providing a small crypto library adaptor implementing these methods.
  18. */
  19. #ifndef PAL_CRYPTO_H
  20. #define PAL_CRYPTO_H
  21. /*
  22. * You can change which crypto library will be used by changing this
  23. * define. Currently supported options:
  24. * - wolfSSL
  25. */
  26. #define PAL_CRYPTO_PROVIDER PAL_CRYPTO_MBEDTLS
  27. /* These cryptosystems are still unconditionally provided by WolfSSL. */
  28. #include "crypto/cmac.h"
  29. #include "crypto/dh.h"
  30. #include "crypto/rsa.h"
  31. #define PAL_CRYPTO_WOLFSSL 1
  32. #define PAL_CRYPTO_MBEDTLS 2
  33. #define SHA256_DIGEST_LEN 32
  34. #if PAL_CRYPTO_PROVIDER == PAL_CRYPTO_WOLFSSL
  35. #include "crypto/sha256.h"
  36. typedef SHA256 PAL_SHA256_CONTEXT;
  37. #elif PAL_CRYPTO_PROVIDER == PAL_CRYPTO_MBEDTLS
  38. #include "crypto/mbedtls/mbedtls/sha256.h"
  39. typedef mbedtls_sha256_context PAL_SHA256_CONTEXT;
  40. #else
  41. # error "Unknown crypto provider. Set PAL_CRYPTO_PROVIDER in pal_crypto.h"
  42. #endif
  43. int DkSHA256Init(PAL_SHA256_CONTEXT *context);
  44. int DkSHA256Update(PAL_SHA256_CONTEXT *context, const uint8_t *data,
  45. PAL_NUM len);
  46. int DkSHA256Final(PAL_SHA256_CONTEXT *context, uint8_t *output);
  47. #endif