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