n32g45x_algo_common.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file n32g45x_algo_common.h
  29. * @author Nations
  30. * @version v1.0.0
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #ifndef __N32G45X_ALGO_COMMON_H__
  35. #define __N32G45X_ALGO_COMMON_H__
  36. #include <stdint.h>
  37. /** @addtogroup N32G45X_Algorithm_Library
  38. * @{
  39. */
  40. enum{
  41. Cpy_OK=0,//copy success
  42. SetZero_OK = 0,//set zero success
  43. XOR_OK = 0, //XOR success
  44. Reverse_OK = 0, //Reverse success
  45. Cmp_EQUAL = 0, //Two big number are equal
  46. Cmp_UNEQUAL = 1, //Two big number are not equal
  47. };
  48. /**
  49. * @brief disturb the sequence order
  50. * @param[in] order pointer to the sequence to be disturbed
  51. * @param[in] rand pointer to random number
  52. * @param[in] the length of order
  53. * @return RandomSort_OK: disturb order success; Others: disturb order fail;
  54. * @note
  55. */
  56. uint32_t RandomSort(uint8_t *order, const uint8_t *rand, uint32_t len);
  57. /**
  58. * @brief Copy data by byte
  59. * @param[in] dst pointer to destination data
  60. * @param[in] src pointer to source data
  61. * @param[in] byte length
  62. * @return Cpy_OK: success; others: fail.
  63. * @note 1. dst and src cannot be same
  64. */
  65. uint32_t Cpy_U8(uint8_t *dst, uint8_t *src, uint32_t byteLen);
  66. /**
  67. * @brief Copy data by word
  68. * @param[in] dst pointer to destination data
  69. * @param[in] src pointer to source data
  70. * @param[in] word length
  71. * @return Cpy_OK: success; others: fail.
  72. * @note 1. dst and src must be aligned by word
  73. */
  74. uint32_t Cpy_U32(uint32_t *dst, const uint32_t *src, uint32_t wordLen);
  75. /**
  76. * @brief XOR
  77. * @param[in] a pointer to one data to be XORed
  78. * @param[in] b pointer to another data to be XORed
  79. * @param[in] the length of order
  80. * @return XOR_OK: operation success; Others: operation fail;
  81. * @note
  82. */
  83. uint32_t XOR_U8(uint8_t *a, uint8_t *b, uint8_t *c, uint32_t byteLen);
  84. /**
  85. * @brief XORed two u32 arrays
  86. * @param[in] a pointer to one data to be XORed
  87. * @param[in] b pointer to another data to be XORed
  88. * @param[in] the length of order
  89. * @return XOR_OK: operation success; Others: operation fail;
  90. * @note
  91. */
  92. uint32_t XOR_U32(uint32_t *a,uint32_t *b,uint32_t *c,uint32_t wordLen);
  93. /**
  94. * @brief set zero by byte
  95. * @param[in] dst pointer to the address to be set zero
  96. * @param[in] byte length
  97. * @return SetZero_OK: success; others: fail.
  98. * @note
  99. */
  100. uint32_t SetZero_U8(uint8_t *dst, uint32_t byteLen);
  101. /**
  102. * @brief set zero by word
  103. * @param[in] dst pointer to the address to be set zero
  104. * @param[in] word length
  105. * @return SetZero_OK: success; others: fail.
  106. * @note
  107. */
  108. uint32_t SetZero_U32(uint32_t *dst, uint32_t wordLen);
  109. /**
  110. * @brief reverse byte order of every word, the words stay the same
  111. * @param[in] dst pointer to the destination address
  112. * @param[in] src pointer to the source address
  113. * @param[in] word length
  114. * @return Reverse_OK: success; others: fail.
  115. * @note 1.dst and src can be same
  116. */
  117. uint32_t ReverseBytesInWord_U32(uint32_t *dst, const uint32_t *src, uint32_t wordLen);
  118. /**
  119. * @brief compare two big number
  120. * @param[in] a pointer to one big number
  121. * @param[in] word length of a
  122. * @param[in] b pointer to another big number
  123. * @param[in] word length of b
  124. * @return Cmp_UNEQUAL:a!=b;Cmp_EQUAL: a==b.
  125. *
  126. */
  127. int32_t Cmp_U32(const uint32_t *a, uint32_t aWordLen, const uint32_t *b, uint32_t bWordLen);
  128. /**
  129. * @brief compare two big number
  130. * @param[in] a pointer to one big number
  131. * @param[in] word length of a
  132. * @param[in] b pointer to another big number
  133. * @param[in] word length of b
  134. * @return Cmp_UNEQUAL:a!=b;Cmp_EQUAL: a==b.
  135. *
  136. */
  137. int32_t Cmp_U8(const uint8_t *a, uint32_t aByteLen, const uint8_t *b, uint32_t bByteLen);
  138. #endif