pal_crypto.h 2.0 KB

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