misc.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* misc.h
  2. *
  3. * Copyright (C) 2006-2022 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. /*
  22. DESCRIPTION
  23. This module implements the arithmetic-shift right, left, byte swapping, XOR,
  24. masking and clearing memory logic.
  25. */
  26. #ifndef WOLF_CRYPT_MISC_H
  27. #define WOLF_CRYPT_MISC_H
  28. #include <wolfssl/wolfcrypt/types.h>
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #ifdef NO_INLINE
  33. WOLFSSL_LOCAL
  34. word32 rotlFixed(word32, word32);
  35. WOLFSSL_LOCAL
  36. word32 rotrFixed(word32, word32);
  37. #ifdef WC_RC2
  38. WOLFSSL_LOCAL
  39. word16 rotlFixed16(word16, word16);
  40. WOLFSSL_LOCAL
  41. word16 rotrFixed16(word16, word16);
  42. #endif
  43. WOLFSSL_LOCAL
  44. word32 ByteReverseWord32(word32);
  45. WOLFSSL_LOCAL
  46. void ByteReverseWords(word32*, const word32*, word32);
  47. WOLFSSL_LOCAL
  48. void XorWordsOut(wolfssl_word* r, const wolfssl_word* a, const wolfssl_word* b,
  49. word32 n);
  50. WOLFSSL_LOCAL
  51. void xorbufout(void*, const void*, const void*, word32);
  52. WOLFSSL_LOCAL
  53. void XorWords(wolfssl_word*, const wolfssl_word*, word32);
  54. WOLFSSL_LOCAL
  55. void xorbuf(void*, const void*, word32);
  56. WOLFSSL_LOCAL
  57. void ForceZero(void*, word32);
  58. WOLFSSL_LOCAL
  59. int ConstantCompare(const byte*, const byte*, int);
  60. #ifdef WORD64_AVAILABLE
  61. WOLFSSL_LOCAL
  62. word64 rotlFixed64(word64, word64);
  63. WOLFSSL_LOCAL
  64. word64 rotrFixed64(word64, word64);
  65. WOLFSSL_LOCAL
  66. word64 ByteReverseWord64(word64);
  67. WOLFSSL_LOCAL
  68. void ByteReverseWords64(word64*, const word64*, word32);
  69. #endif /* WORD64_AVAILABLE */
  70. #ifndef WOLFSSL_HAVE_MIN
  71. #if defined(HAVE_FIPS) && !defined(min) /* so ifdef check passes */
  72. #define min min
  73. #endif
  74. WOLFSSL_LOCAL word32 min(word32 a, word32 b);
  75. #endif
  76. #ifndef WOLFSSL_HAVE_MAX
  77. #if defined(HAVE_FIPS) && !defined(max) /* so ifdef check passes */
  78. #define max max
  79. #endif
  80. WOLFSSL_LOCAL word32 max(word32 a, word32 b);
  81. #endif /* WOLFSSL_HAVE_MAX */
  82. void c32to24(word32 in, word24 out);
  83. void c16toa(word16 u16, byte* c);
  84. void c32toa(word32 u32, byte* c);
  85. void c24to32(const word24 u24, word32* u32);
  86. void ato16(const byte* c, word16* u16);
  87. void ato24(const byte* c, word32* u24);
  88. void ato32(const byte* c, word32* u32);
  89. word32 btoi(byte b);
  90. WOLFSSL_LOCAL signed char HexCharToByte(char ch);
  91. WOLFSSL_LOCAL char ByteToHex(byte in);
  92. WOLFSSL_LOCAL int ByteToHexStr(byte in, char* out);
  93. WOLFSSL_LOCAL byte ctMaskGT(int a, int b);
  94. WOLFSSL_LOCAL byte ctMaskGTE(int a, int b);
  95. WOLFSSL_LOCAL int ctMaskIntGTE(int a, int b);
  96. WOLFSSL_LOCAL byte ctMaskLT(int a, int b);
  97. WOLFSSL_LOCAL byte ctMaskLTE(int a, int b);
  98. WOLFSSL_LOCAL byte ctMaskEq(int a, int b);
  99. WOLFSSL_LOCAL word16 ctMask16GT(int a, int b);
  100. WOLFSSL_LOCAL word16 ctMask16GTE(int a, int b);
  101. WOLFSSL_LOCAL word16 ctMask16LT(int a, int b);
  102. WOLFSSL_LOCAL word16 ctMask16LTE(int a, int b);
  103. WOLFSSL_LOCAL word16 ctMask16Eq(int a, int b);
  104. WOLFSSL_LOCAL byte ctMaskNotEq(int a, int b);
  105. WOLFSSL_LOCAL byte ctMaskSel(byte m, byte a, byte b);
  106. WOLFSSL_LOCAL int ctMaskSelInt(byte m, int a, int b);
  107. WOLFSSL_LOCAL byte ctSetLTE(int a, int b);
  108. WOLFSSL_LOCAL void ctMaskCopy(byte mask, byte* dst, byte* src, word16 size);
  109. WOLFSSL_LOCAL word32 MakeWordFromHash(const byte* hashID);
  110. WOLFSSL_LOCAL word32 HashObject(const byte* o, word32 len, int* error);
  111. #endif /* NO_INLINE */
  112. #ifdef __cplusplus
  113. } /* extern "C" */
  114. #endif
  115. #endif /* WOLF_CRYPT_MISC_H */