test_ecc_utils.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* test_ecc_utils.h - TinyCrypt interface to common functions for ECC tests */
  2. /* Copyright (c) 2014, Kenneth MacKay
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright notice,
  10. * this list of conditions and the following disclaimer in the documentation
  11. * and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  17. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23. * POSSIBILITY OF SUCH DAMAGE.*/
  24. /*
  25. * Copyright (C) 2017 by Intel Corporation, All Rights Reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or without
  28. * modification, are permitted provided that the following conditions are met:
  29. *
  30. * - Redistributions of source code must retain the above copyright notice,
  31. * this list of conditions and the following disclaimer.
  32. *
  33. * - Redistributions in binary form must reproduce the above copyright
  34. * notice, this list of conditions and the following disclaimer in the
  35. * documentation and/or other materials provided with the distribution.
  36. *
  37. * - Neither the name of Intel Corporation nor the names of its contributors
  38. * may be used to endorse or promote products derived from this software
  39. * without specific prior written permission.
  40. *
  41. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  42. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  43. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  45. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  46. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  47. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  48. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  49. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  50. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  51. * POSSIBILITY OF SUCH DAMAGE.
  52. *
  53. * test_ecc_utils.h -- Interface to common functions for ECC tests.
  54. */
  55. #ifndef __TEST_ECC_UTILS_H__
  56. #define __TEST_ECC_UTILS_H__
  57. #include <tinycrypt/ecc_dh.h>
  58. #include <tinycrypt/ecc.h>
  59. #include <test_utils.h>
  60. int hex2int (char hex);
  61. /*
  62. * Convert hex string to byte string
  63. * Return number of bytes written to buf, or 0 on error
  64. */
  65. int hex2bin(uint8_t *buf, const size_t buflen, const char *hex,
  66. const size_t hexlen);
  67. /*
  68. * Convert hex string to zero-padded nanoECC scalar
  69. */
  70. void string2scalar(unsigned int * scalar, unsigned int num_word32, char *str);
  71. void print_ecc_scalar(const char *label, const unsigned int * p_vli,
  72. unsigned int num_word32);
  73. int check_ecc_result(const int num, const char *name,
  74. const unsigned int *expected,
  75. const unsigned int *computed,
  76. const unsigned int num_word32, const bool verbose);
  77. /* Test ecc_make_keys, and also as keygen part of other tests */
  78. int keygen_vectors(char **d_vec, char **qx_vec, char **qy_vec, int tests, bool verbose);
  79. void vli_print_bytes(uint8_t *vli, unsigned int size);
  80. int check_code(const int num, const char *name, const int expected,
  81. const int computed, const int verbose);
  82. #endif /* __TEST_ECC_UTILS_H__ */