misc.h
1 /* misc.h
2  *
3  * Copyright (C) 2006-2020 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 
23 
24 #ifndef WOLF_CRYPT_MISC_H
25 #define WOLF_CRYPT_MISC_H
26 
27 
29 
30 
31 #ifdef __cplusplus
32  extern "C" {
33 #endif
34 
35 
36 #ifdef NO_INLINE
37 WOLFSSL_LOCAL
38 word32 rotlFixed(word32, word32);
39 WOLFSSL_LOCAL
40 word32 rotrFixed(word32, word32);
41 
42 WOLFSSL_LOCAL
43 word32 ByteReverseWord32(word32);
44 WOLFSSL_LOCAL
45 void ByteReverseWords(word32*, const word32*, word32);
46 
47 WOLFSSL_LOCAL
48 void XorWords(wolfssl_word*, const wolfssl_word*, word32);
49 WOLFSSL_LOCAL
50 void xorbuf(void*, const void*, word32);
51 
52 WOLFSSL_LOCAL
53 void ForceZero(const void*, word32);
54 
55 WOLFSSL_LOCAL
56 int ConstantCompare(const byte*, const byte*, int);
57 
58 #ifdef WORD64_AVAILABLE
59 WOLFSSL_LOCAL
60 word64 rotlFixed64(word64, word64);
61 WOLFSSL_LOCAL
62 word64 rotrFixed64(word64, word64);
63 
64 WOLFSSL_LOCAL
65 word64 ByteReverseWord64(word64);
66 WOLFSSL_LOCAL
67 void ByteReverseWords64(word64*, const word64*, word32);
68 #endif /* WORD64_AVAILABLE */
69 
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 
77 #ifndef WOLFSSL_HAVE_MAX
78  #if defined(HAVE_FIPS) && !defined(max) /* so ifdef check passes */
79  #define max max
80  #endif
81  WOLFSSL_LOCAL word32 max(word32 a, word32 b);
82 #endif /* WOLFSSL_HAVE_MAX */
83 
84 
85 void c32to24(word32 in, word24 out);
86 void c16toa(word16 u16, byte* c);
87 void c32toa(word32 u32, byte* c);
88 void c24to32(const word24 u24, word32* u32);
89 void ato16(const byte* c, word16* u16);
90 void ato24(const byte* c, word32* u24);
91 void ato32(const byte* c, word32* u32);
92 word32 btoi(byte b);
93 
94 
95 WOLFSSL_LOCAL byte ctMaskGT(int a, int b);
96 WOLFSSL_LOCAL byte ctMaskGTE(int a, int b);
97 WOLFSSL_LOCAL int ctMaskIntGTE(int a, int b);
98 WOLFSSL_LOCAL byte ctMaskLT(int a, int b);
99 WOLFSSL_LOCAL byte ctMaskLTE(int a, int b);
100 WOLFSSL_LOCAL byte ctMaskEq(int a, int b);
101 WOLFSSL_LOCAL word16 ctMask16GT(int a, int b);
102 WOLFSSL_LOCAL word16 ctMask16LT(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 
109 #endif /* NO_INLINE */
110 
111 
112 #ifdef __cplusplus
113  } /* extern "C" */
114 #endif
115 
116 
117 #endif /* WOLF_CRYPT_MISC_H */
118