1/* sha256.h
2 * Code copied from openssl distribution and
3 * Modified just enough so that compiles and runs standalone
4 *
5 * Copyright (C) 2015, Broadcom Corporation. All Rights Reserved.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
14 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
16 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 *
19 * $Id: sha256.h 241182 2011-02-17 21:50:03Z $
20 */
21/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
22 * All rights reserved.
23 *
24 * This package is an SSL implementation written
25 * by Eric Young (eay@cryptsoft.com).
26 * The implementation was written so as to conform with Netscapes SSL.
27 *
28 * This library is free for commercial and non-commercial use as long as
29 * the following conditions are aheared to.  The following conditions
30 * apply to all code found in this distribution, be it the RC4, RSA,
31 * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
32 * included with this distribution is covered by the same copyright terms
33 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
34 *
35 * Copyright remains Eric Young's, and as such any Copyright notices in
36 * the code are not to be removed.
37 * If this package is used in a product, Eric Young should be given attribution
38 * as the author of the parts of the library used.
39 * This can be in the form of a textual message at program startup or
40 * in documentation (online or textual) provided with the package.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the copyright
46 *    notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 *    notice, this list of conditions and the following disclaimer in the
49 *    documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 *    must display the following acknowledgement:
52 *    "This product includes cryptographic software written by
53 *     Eric Young (eay@cryptsoft.com)"
54 *    The word 'cryptographic' can be left out if the rouines from the library
55 *    being used are not cryptographic related :-).
56 * 4. If you include any Windows specific code (or a derivative thereof) from
57 *    the apps directory (application code) you must include an acknowledgement:
58 *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
59 *
60 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
61 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 * SUCH DAMAGE.
71 *
72 * The licence and distribution terms for any publically available version or
73 * derivative of this code cannot be changed.  i.e. this code cannot simply be
74 * copied and put under another distribution licence
75 * [including the GNU Public Licence.]
76 */
77
78#ifndef HEADER_SHA_H
79#define HEADER_SHA_H
80
81#ifdef  __cplusplus
82extern "C" {
83#endif
84
85/*
86 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
87 * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then !
88 * ! SHA_LONG_LOG2 has to be defined along.                        !
89 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
90 */
91
92#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
93#define SHA_LONG unsigned long
94#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
95#define SHA_LONG unsigned long
96#define SHA_LONG_LOG2 3
97#else
98#define SHA_LONG unsigned int
99#endif
100
101#define SHA_LBLOCK	16
102#define SHA_CBLOCK	(SHA_LBLOCK*4)	/* SHA treats input data as a
103					 * contiguous array of 32 bit
104					 * wide big-endian values.
105					 */
106#define SHA_LAST_BLOCK  (SHA_CBLOCK-8)
107#define SHA_DIGEST_LENGTH 20
108
109#define SHA256_CBLOCK	(SHA_LBLOCK*4)	/* SHA-256 treats input data as a
110					 * contiguous array of 32 bit
111					 * wide big-endian values.
112					 */
113#define SHA224_DIGEST_LENGTH	28
114#define SHA256_DIGEST_LENGTH	32
115
116typedef struct SHA256state_st
117	{
118	SHA_LONG h[8];
119	SHA_LONG Nl, Nh;
120	SHA_LONG data[SHA_LBLOCK];
121	unsigned int num, md_len;
122	} SHA256_CTX;
123
124int SHA224_Init(SHA256_CTX *c);
125int SHA224_Update(SHA256_CTX *c, const void *data, size_t len);
126int SHA224_Final(unsigned char *md, SHA256_CTX *c);
127unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md);
128int SHA256_Init(SHA256_CTX *c);
129int SHA256_Update(SHA256_CTX *c, const void *data, size_t len);
130int SHA256_Final(unsigned char *md, SHA256_CTX *c);
131unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md);
132void SHA256_Transform(SHA256_CTX *c, const unsigned char *data);
133
134#ifdef  __cplusplus
135}
136#endif
137
138#endif /* HEADER_SHA_H */
139