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