blob: 2bba3d1bcde5158d5de18cc248bf2c6f27b392a2 [file] [log] [blame]
Etienne Carriere75141172020-05-16 11:58:23 +02001/* SPDX-License-Identifier: (BSD-2-Clause AND BSD-3-Clause) */
Pascal Brandc639ac82015-07-02 08:53:34 +02002/*
3 * Copyright (c) 2014, STMicroelectronics International N.V.
4 * All rights reserved.
Pascal Brandc639ac82015-07-02 08:53:34 +02005 */
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
50struct 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
57struct 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
64void sha224_init(struct sha224_ctx *ctx);
65void sha224_update(struct sha224_ctx *ctx, const unsigned char *message,
66 unsigned int len);
67void sha224_final(struct sha224_ctx *ctx, unsigned char *digest);
68void sha224(const unsigned char *message, unsigned int len,
69 unsigned char *digest);
70
71void sha256_init(struct sha256_ctx *ctx);
72void sha256_update(struct sha256_ctx *ctx, const unsigned char *message,
73 unsigned int len);
74void sha256_final(struct sha256_ctx *ctx, unsigned char *digest);
75void sha256(const unsigned char *message, unsigned int len,
76 unsigned char *digest);
77
78void sha256_transf(struct sha256_ctx *ctx, const unsigned char *message,
79 unsigned int block_nb);
80#endif