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