Soby Mathew | 1ae83bc | 2017-05-10 11:48:40 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef UTIL_H |
| 8 | #define UTIL_H |
| 9 | |
| 10 | /* |
| 11 | * All the includes that are needed for code using this module to |
| 12 | * compile correctly should be #included here. |
| 13 | */ |
| 14 | |
| 15 | #ifdef __cplusplus |
| 16 | extern "C" |
| 17 | { |
| 18 | #endif |
| 19 | |
| 20 | /************************ Defines ******************************/ |
| 21 | |
| 22 | /* invers the bytes on a word- used for output from HASH */ |
| 23 | #ifdef BIG__ENDIAN |
| 24 | #define UTIL_INVERSE_UINT32_BYTES(val) (val) |
| 25 | #else |
| 26 | #define UTIL_INVERSE_UINT32_BYTES(val) \ |
| 27 | (((val) >> 24) | (((val) & 0x00FF0000) >> 8) | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) |
| 28 | #endif |
| 29 | |
| 30 | /* invers the bytes on a word - used for input data for HASH */ |
| 31 | #ifdef BIG__ENDIAN |
| 32 | #define UTIL_REVERT_UINT32_BYTES(val) \ |
| 33 | (((val) >> 24) | (((val) & 0x00FF0000) >> 8) | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) |
| 34 | #else |
| 35 | #define UTIL_REVERT_UINT32_BYTES(val) (val) |
| 36 | #endif |
| 37 | |
| 38 | /* ------------------------------------------------------------ |
| 39 | ** |
| 40 | * @brief This function executes a reverse bytes copying from one buffer to another buffer. |
| 41 | * |
| 42 | * @param[in] dst_ptr - The pointer to destination buffer. |
| 43 | * @param[in] src_ptr - The pointer to source buffer. |
| 44 | * @param[in] size - The size in bytes. |
| 45 | * |
| 46 | */ |
| 47 | |
| 48 | void UTIL_ReverseMemCopy(uint8_t *dst_ptr, uint8_t *src_ptr, uint32_t size); |
| 49 | |
| 50 | |
| 51 | /* ------------------------------------------------------------ |
| 52 | ** |
| 53 | * @brief This function executes a reversed byte copy on a specified buffer. |
| 54 | * |
| 55 | * on a 6 byte byffer: |
| 56 | * |
| 57 | * buff[5] <---> buff[0] |
| 58 | * buff[4] <---> buff[1] |
| 59 | * buff[3] <---> buff[2] |
| 60 | * |
| 61 | * @param[in] dst_ptr - The counter buffer. |
| 62 | * @param[in] src_ptr - The counter size in bytes. |
| 63 | * |
| 64 | */ |
| 65 | void UTIL_ReverseBuff(uint8_t *buff_ptr, uint32_t size); |
| 66 | |
| 67 | |
| 68 | #ifdef __cplusplus |
| 69 | } |
| 70 | #endif |
| 71 | |
| 72 | #endif |