X509_LOOKUP_store: new X509_LOOKUP_METHOD that works by OSSL_STORE URI
[openssl.git] / include / openssl / sha.h
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 # if !OPENSSL_API_3
16 #  define HEADER_SHA_H
17 # endif
18
19 # include <openssl/e_os2.h>
20 # include <stddef.h>
21
22 #ifdef  __cplusplus
23 extern "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
40 typedef 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
47 int SHA1_Init(SHA_CTX *c);
48 int SHA1_Update(SHA_CTX *c, const void *data, size_t len);
49 int SHA1_Final(unsigned char *md, SHA_CTX *c);
50 unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);
51 void 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
57 typedef 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
64 int SHA224_Init(SHA256_CTX *c);
65 int SHA224_Update(SHA256_CTX *c, const void *data, size_t len);
66 int SHA224_Final(unsigned char *md, SHA256_CTX *c);
67 unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md);
68 int SHA256_Init(SHA256_CTX *c);
69 int SHA256_Update(SHA256_CTX *c, const void *data, size_t len);
70 int SHA256_Final(unsigned char *md, SHA256_CTX *c);
71 unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md);
72 void 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 #  define U64(C)     C##UI64
93 # elif defined(__arch64__)
94 #  define SHA_LONG64 unsigned long
95 #  define U64(C)     C##UL
96 # else
97 #  define SHA_LONG64 unsigned long long
98 #  define U64(C)     C##ULL
99 # endif
100
101 typedef struct SHA512state_st {
102     SHA_LONG64 h[8];
103     SHA_LONG64 Nl, Nh;
104     union {
105         SHA_LONG64 d[SHA_LBLOCK];
106         unsigned char p[SHA512_CBLOCK];
107     } u;
108     unsigned int num, md_len;
109 } SHA512_CTX;
110
111 int SHA384_Init(SHA512_CTX *c);
112 int SHA384_Update(SHA512_CTX *c, const void *data, size_t len);
113 int SHA384_Final(unsigned char *md, SHA512_CTX *c);
114 unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md);
115 int SHA512_Init(SHA512_CTX *c);
116 int SHA512_Update(SHA512_CTX *c, const void *data, size_t len);
117 int SHA512_Final(unsigned char *md, SHA512_CTX *c);
118 unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md);
119 void SHA512_Transform(SHA512_CTX *c, const unsigned char *data);
120
121 #ifdef  __cplusplus
122 }
123 #endif
124
125 #endif