2
0

ecc-verify.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* ecc-verify.c
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #include <wolfssl/wolfcrypt/settings.h>
  22. #include <wolfssl/wolfcrypt/sha256.h>
  23. #include <wolfssl/wolfcrypt/random.h>
  24. #include <wolfssl/wolfcrypt/ecc.h>
  25. #include <wolfssl/wolfcrypt/asn_public.h>
  26. #define USE_CERT_BUFFERS_256
  27. #include <wolfssl/certs_test.h>
  28. #define MAX_BLOCK_SIZE 1024
  29. #ifdef WOLFSSL_DSP
  30. static char *sp_URI_value = wolfSSL_URI "&_dom=cdsp";
  31. int hash_firmware_verify(const byte* hash, word32 hashLen, const byte* sigBuf, word32 sigLen)
  32. {
  33. int ret;
  34. ecc_key eccKey;
  35. word32 idx;
  36. int verify;
  37. remote_handle64 handle = -1;
  38. idx = 0;
  39. ret = wc_EccPrivateKeyDecode(ecc_clikey_der_256, &idx, &eccKey, sizeof_ecc_clikey_der_256);
  40. if (ret < 0)
  41. goto exit;
  42. int retVal = wolfSSL_open(sp_URI_value, &handle);
  43. if (retVal != 0) {
  44. printf("unable to open CDSP? retVal = %d\n", retVal);
  45. ret = -1;
  46. goto exit;
  47. }
  48. wc_ecc_set_handle(&eccKey, handle);
  49. ret = wc_ecc_verify_hash((byte*)sigBuf, sigLen, hash, hashLen, &verify, &eccKey);
  50. printf("verify = %d\n", verify);
  51. if (ret < 0)
  52. goto exit;
  53. wolfSSL_close(handle);
  54. exit:
  55. return ret;
  56. }
  57. int main(void)
  58. {
  59. int ret;
  60. const byte hash[] = {
  61. 0XFB, 0XBA, 0XB2, 0X89, 0XF7, 0XF9, 0X4B, 0X25, 0X73, 0X6C, 0X58, 0XBE, 0X46, 0XA9, 0X94, 0XC4, 0X41, 0XFD, 0X02, 0X55, 0X2C, 0XC6, 0X02, 0X23, 0X52, 0XE3, 0XD8, 0X6D, 0X2F, 0XAB, 0X7C, 0X83
  62. };
  63. const byte sigBuf[] = {
  64. 0X30, 0X44, 0X02, 0X20, 0X05, 0X38, 0XBC, 0X16, 0XC7, 0X67, 0X18, 0XEC, 0XE6, 0X1E, 0X43, 0X7B, 0X29, 0X8F, 0X85, 0X01, 0X33, 0XA8, 0X9B, 0XDD, 0X91, 0X32, 0X1F, 0XEC, 0XF7, 0X91, 0X18, 0X72, 0X9C, 0XE2, 0X6F, 0X31, 0X02, 0X20, 0X3E, 0X31, 0XD6, 0X40, 0XF7, 0X38, 0X3C, 0X1B, 0X6D, 0XAD, 0XE3, 0X93, 0X20, 0XE8, 0XB1, 0XBD, 0X3C, 0X59, 0XF2, 0XD2, 0X7C, 0X46, 0X1B, 0XE5, 0XE1, 0XE3, 0XAB, 0X5E, 0X76, 0X73, 0X6F, 0XFB
  65. };
  66. word32 sigLen = (word32)sizeof(sigBuf);
  67. wolfCrypt_Init();
  68. ret = hash_firmware_verify(hash, sizeof(hash), sigBuf, sigLen);
  69. printf("hash_firmware_verify: %d\n", ret);
  70. wolfCrypt_Cleanup();
  71. return 0;
  72. }
  73. #else
  74. int main()
  75. {
  76. printf("WOLFSSL_DSP expected to be defined when building\n");
  77. return 0;
  78. }
  79. #endif /* WOLFSSL_DSP */