1 /* 2 * FIPS 180-2 SHA-224/256/384/512 implementation 3 * Last update: 02/02/2007 4 * Issue date: 04/30/2005 5 * 6 * Copyright (C) 2005, 2007 Olivier Gay <olivier.gay@a3.epfl.ch> 7 * All rights reserved. 8 * 9 * Copyright (c) 2016, Linaro Limited 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. Neither the name of the project nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37 #ifndef SHA2_H 38 #define SHA2_H 39 40 #define SHA256_DIGEST_SIZE ( 256 / 8) 41 #define SHA256_BLOCK_SIZE ( 512 / 8) 42 43 #ifndef SHA2_TYPES 44 #define SHA2_TYPES 45 typedef unsigned char uint8; 46 typedef unsigned int uint32; 47 typedef unsigned long long uint64; 48 #endif 49 50 #ifdef __cplusplus 51 extern "C" { 52 #endif 53 54 typedef struct { 55 unsigned int tot_len; 56 unsigned int len; 57 unsigned char block[2 * SHA256_BLOCK_SIZE]; 58 uint32 h[8]; 59 } sha256_ctx; 60 61 typedef sha256_ctx sha224_ctx; 62 63 void sha256_init(sha256_ctx * ctx); 64 void sha256_update(sha256_ctx *ctx, const unsigned char *message, 65 unsigned int len); 66 void sha256_final(sha256_ctx *ctx, unsigned char *digest); 67 void sha256(const unsigned char *message, unsigned int len, 68 unsigned char *digest); 69 70 #ifdef __cplusplus 71 } 72 #endif 73 74 #endif /* !SHA2_H */ 75 76