wolfssl_adapter.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* This file is part of Graphene Library OS.
  2. Graphene Library OS is free software: you can redistribute it and/or
  3. modify it under the terms of the GNU General Public License
  4. as published by the Free Software Foundation, either version 3 of the
  5. License, or (at your option) any later version.
  6. Graphene Library OS is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  12. #include <stdint.h>
  13. #include <limits.h>
  14. #include "pal.h"
  15. #include "pal_crypto.h"
  16. #include "pal_error.h"
  17. #include "crypto/wolfssl/sha256.h"
  18. #include "crypto/wolfssl/cmac.h"
  19. #include "crypto/wolfssl/rsa.h"
  20. int lib_SHA256Init(LIB_SHA256_CONTEXT *context)
  21. {
  22. return SHA256Init(context);
  23. }
  24. int lib_SHA256Update(LIB_SHA256_CONTEXT *context, const uint8_t *data,
  25. uint64_t len)
  26. {
  27. /* uint64_t is a 64-bit value, but SHA256Update takes a 32-bit len. */
  28. if (len > UINT32_MAX) {
  29. return -PAL_ERROR_INVAL;
  30. }
  31. return SHA256Update(context, data, len);
  32. }
  33. int lib_SHA256Final(LIB_SHA256_CONTEXT *context, uint8_t *output)
  34. {
  35. return SHA256Final(context, output);
  36. }
  37. int lib_AESCMAC(const uint8_t *key, uint64_t key_len, const uint8_t *input,
  38. uint64_t input_len, uint8_t *mac, uint64_t mac_len)
  39. {
  40. /* The old code only supports 128-bit AES CMAC, and length is a 32-bit
  41. * value. */
  42. if (key_len != 16 || input_len > INT32_MAX || mac_len < 16) {
  43. return -PAL_ERROR_INVAL;
  44. }
  45. AES_CMAC((unsigned char *) key, (unsigned char *) input, input_len, mac);
  46. return 0;
  47. }