1 /** @file sha_256.h 2 * 3 * @brief This file contains the SHA256 hash implementation and interface functions 4 * 5 * Copyright (C) 2014-2017, Marvell International Ltd. 6 * 7 * This software file (the "File") is distributed by Marvell International 8 * Ltd. under the terms of the GNU General Public License Version 2, June 1991 9 * (the "License"). You may use, redistribute and/or modify this File in 10 * accordance with the terms and conditions of the License, a copy of which 11 * is available by writing to the Free Software Foundation, Inc., 12 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the 13 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 14 * 15 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE 17 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about 18 * this warranty disclaimer. 19 */ 20 21 /****************************************************** 22 Change log: 23 03/07/2014: Initial version 24 ******************************************************/ 25 #ifndef SHA256_H 26 #define SHA256_H 27 28 #include "wltypes.h" 29 30 #define SHA256_MAC_LEN 32 31 #define HMAC_SHA256_MIN_SCRATCH_BUF (500) 32 #define SHA256_MIN_SCRATCH_BUF (400) 33 34 struct sha256_state { 35 UINT64 length; 36 UINT32 state[8], curlen; 37 UINT8 buf[64]; 38 }; 39 40 void sha256_init(struct sha256_state *md); 41 42 /** 43 * @brief sha256_compress - Compress 512-bits. 44 * @param priv pointer to previous element 45 * @param md: Pointer to the element holding hash state. 46 * @param msgBuf: Pointer to the buffer containing the data to be hashed. 47 * @param pScratchMem: Scratch memory; At least 288 bytes of free memory * 48 * 49 */ 50 int sha256_compress(void *priv, struct sha256_state *md, 51 UINT8 *msgBuf, UINT8 *pScratchMem); 52 53 /** 54 * sha256_vector - SHA256 hash for data vector 55 * @param num_elem: Number of elements in the data vector 56 * @param addr: Pointers to the data areas 57 * @param len: Lengths of the data blocks 58 * @param mac: Buffer for the hash 59 * @param pScratchMem: Scratch memory; Buffer of SHA256_MIN_SCRATCH_BUF size 60 */ 61 void sha256_vector(void *priv, size_t num_elem, 62 UINT8 *addr[], size_t * len, UINT8 *mac, UINT8 *pScratchMem); 63 64 /** 65 * hmac_sha256_vector - HMAC-SHA256 over data vector (RFC 2104) 66 * @param key: Key for HMAC operations 67 * @param key_len: Length of the key in bytes 68 * @param num_elem: Number of elements in the data vector; including [0] 69 * @param addr: Pointers to the data areas, [0] element must be left as spare 70 * @param len: Lengths of the data blocks, [0] element must be left as spare 71 * @param mac: Buffer for the hash (32 bytes) 72 * @param pScratchMem: Scratch Memory; Buffer of HMAC_SHA256_MIN_SCRATCH_BUF size 73 */ 74 void hmac_sha256_vector(void *priv, UINT8 *key, 75 size_t key_len, 76 size_t num_elem, 77 UINT8 *addr[], 78 size_t * len, UINT8 *mac, UINT8 *pScratchMem); 79 80 #endif /* SHA256_H */ 81