wolfssl_adapter.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 "pal.h"
  14. #include "pal_crypto.h"
  15. #include "pal_error.h"
  16. #include "crypto/wolfssl/sha256.h"
  17. #include "crypto/wolfssl/cmac.h"
  18. int lib_SHA256Init(LIB_SHA256_CONTEXT *context)
  19. {
  20. return SHA256Init(context);
  21. }
  22. int lib_SHA256Update(LIB_SHA256_CONTEXT *context, const uint8_t *data,
  23. uint64_t len)
  24. {
  25. /* uint64_t is a 64-bit value, but SHA256Update takes a 32-bit len. */
  26. if (len > UINT32_MAX) {
  27. return -PAL_ERROR_INVAL;
  28. }
  29. return SHA256Update(context, data, len);
  30. }
  31. int lib_SHA256Final(LIB_SHA256_CONTEXT *context, uint8_t *output)
  32. {
  33. return SHA256Final(context, output);
  34. }
  35. int lib_AESCMAC(const uint8_t *key, uint64_t key_len, const uint8_t *input,
  36. uint64_t input_len, uint8_t *mac, uint64_t mac_len)
  37. {
  38. /* The old code only supports 128-bit AES CMAC, and length is a 32-bit
  39. * value. */
  40. if (key_len != 16 || input_len > INT32_MAX || mac_len < 16) {
  41. return -PAL_ERROR_INVAL;
  42. }
  43. AES_CMAC((unsigned char *) key, (unsigned char *) input, input_len, mac);
  44. return 0;
  45. }