1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#ifndef OPENSSL_SHA_H
11# define OPENSSL_SHA_H
12# pragma once
13
14# include <openssl/macros.h>
15# ifndef OPENSSL_NO_DEPRECATED_3_0
16# define HEADER_SHA_H
17# endif
18
19# include <openssl/e_os2.h>
20# include <stddef.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/*-
27 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28 * ! SHA_LONG has to be at least 32 bits wide. !
29 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
30 */
31# define SHA_LONG unsigned int
32
33# define SHA_LBLOCK 16
34# define SHA_CBLOCK (SHA_LBLOCK*4)/* SHA treats input data as a
35 * contiguous array of 32 bit wide
36 * big-endian values. */
37# define SHA_LAST_BLOCK (SHA_CBLOCK-8)
38# define SHA_DIGEST_LENGTH 20
39
40typedef struct SHAstate_st {
41 SHA_LONG h0, h1, h2, h3, h4;
42 SHA_LONG Nl, Nh;
43 SHA_LONG data[SHA_LBLOCK];
44 unsigned int num;
45} SHA_CTX;
46
47int SHA1_Init(SHA_CTX *c);
48int SHA1_Update(SHA_CTX *c, const void *data, size_t len);
49int SHA1_Final(unsigned char *md, SHA_CTX *c);
50unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);
51void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
52
53# define SHA256_CBLOCK (SHA_LBLOCK*4)/* SHA-256 treats input data as a
54 * contiguous array of 32 bit wide
55 * big-endian values. */
56
57typedef struct SHA256state_st {
58 SHA_LONG h[8];
59 SHA_LONG Nl, Nh;
60 SHA_LONG data[SHA_LBLOCK];
61 unsigned int num, md_len;
62} SHA256_CTX;
63
64int SHA224_Init(SHA256_CTX *c);
65int SHA224_Update(SHA256_CTX *c, const void *data, size_t len);
66int SHA224_Final(unsigned char *md, SHA256_CTX *c);
67unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md);
68int SHA256_Init(SHA256_CTX *c);
69int SHA256_Update(SHA256_CTX *c, const void *data, size_t len);
70int SHA256_Final(unsigned char *md, SHA256_CTX *c);
71unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md);
72void SHA256_Transform(SHA256_CTX *c, const unsigned char *data);
73
74# define SHA224_DIGEST_LENGTH 28
75# define SHA256_DIGEST_LENGTH 32
76# define SHA384_DIGEST_LENGTH 48
77# define SHA512_DIGEST_LENGTH 64
78
79/*
80 * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64
81 * being exactly 64-bit wide. See Implementation Notes in sha512.c
82 * for further details.
83 */
84/*
85 * SHA-512 treats input data as a
86 * contiguous array of 64 bit
87 * wide big-endian values.
88 */
89# define SHA512_CBLOCK (SHA_LBLOCK*8)
90# if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
91# define SHA_LONG64 unsigned __int64
92# elif defined(__arch64__)
93# define SHA_LONG64 unsigned long
94# else
95# define SHA_LONG64 unsigned long long
96# endif
97
98typedef struct SHA512state_st {
99 SHA_LONG64 h[8];
100 SHA_LONG64 Nl, Nh;
101 union {
102 SHA_LONG64 d[SHA_LBLOCK];
103 unsigned char p[SHA512_CBLOCK];
104 } u;
105 unsigned int num, md_len;
106} SHA512_CTX;
107
108int SHA384_Init(SHA512_CTX *c);
109int SHA384_Update(SHA512_CTX *c, const void *data, size_t len);
110int SHA384_Final(unsigned char *md, SHA512_CTX *c);
111unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md);
112int SHA512_Init(SHA512_CTX *c);
113int SHA512_Update(SHA512_CTX *c, const void *data, size_t len);
114int SHA512_Final(unsigned char *md, SHA512_CTX *c);
115unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md);
116void SHA512_Transform(SHA512_CTX *c, const unsigned char *data);
117
118#ifdef __cplusplus
119}
120#endif
121
122#endif
123