pal_crypto.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/wolfssl/sha256.h"
  36. typedef SHA256 LIB_SHA256_CONTEXT;
  37. #elif PAL_CRYPTO_PROVIDER == PAL_CRYPTO_MBEDTLS
  38. #include "crypto/mbedtls/mbedtls/sha256.h"
  39. typedef mbedtls_sha256_context LIB_SHA256_CONTEXT;
  40. #else
  41. # error "Unknown crypto provider. Set PAL_CRYPTO_PROVIDER in pal_crypto.h"
  42. #endif
  43. typedef LIB_SHA256_CONTEXT PAL_SHA256_CONTEXT;
  44. int lib_SHA256Init(LIB_SHA256_CONTEXT *context);
  45. int lib_SHA256Update(LIB_SHA256_CONTEXT *context, const uint8_t *data,
  46. uint64_t len);
  47. int lib_SHA256Final(LIB_SHA256_CONTEXT *context, uint8_t *output);
  48. #endif