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