packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cm_sha2.h
1 /*
2  * FILE:    sha2.h
3  * AUTHOR:  Aaron D. Gifford
4  *          http://www.aarongifford.com/computers/sha.html
5  *
6  * Copyright (c) 2000-2003, Aaron D. Gifford
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the name of the copyright holder nor the names of contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * $Id: sha2.h,v 1.4 2004/01/07 19:06:18 adg Exp $
34  */
35
36 #ifndef __SHA2_H__
37 #define __SHA2_H__
38
39 #include "cm_sha2_mangle.h"
40
41 /* CMake modification: use integer types from cmIML.  */
42 #include "cmIML/INT.h"
43 typedef cmIML_INT_uint8_t cm_sha2_uint8_t;
44 typedef cmIML_INT_uint32_t cm_sha2_uint32_t;
45 typedef cmIML_INT_uint64_t cm_sha2_uint64_t;
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51
52 /*
53  * Import u_intXX_t size_t type definitions from system headers.  You
54  * may need to change this, or define these things yourself in this
55  * file.
56  */
57 #include <sys/types.h>
58
59 /*** SHA-224/256/384/512 Various Length Definitions *******************/
60
61 /* Digest lengths for SHA-1/224/256/384/512 */
62 #define   SHA1_DIGEST_LENGTH          20
63 #define   SHA1_DIGEST_STRING_LENGTH  (SHA1_DIGEST_LENGTH   * 2 + 1)
64 #define SHA224_DIGEST_LENGTH          28
65 #define SHA224_DIGEST_STRING_LENGTH  (SHA224_DIGEST_LENGTH * 2 + 1)
66 #define SHA256_DIGEST_LENGTH          32
67 #define SHA256_DIGEST_STRING_LENGTH  (SHA256_DIGEST_LENGTH * 2 + 1)
68 #define SHA384_DIGEST_LENGTH          48
69 #define SHA384_DIGEST_STRING_LENGTH  (SHA384_DIGEST_LENGTH * 2 + 1)
70 #define SHA512_DIGEST_LENGTH          64
71 #define SHA512_DIGEST_STRING_LENGTH  (SHA512_DIGEST_LENGTH * 2 + 1)
72
73
74 /*** SHA-224/256/384/512 Context Structures ***************************/
75
76 typedef union _SHA_CTX {
77     /* SHA-1 uses this part of the union: */
78     struct {
79         cm_sha2_uint32_t state[5];
80         cm_sha2_uint64_t bitcount;
81         cm_sha2_uint8_t  buffer[64];
82     } s1;
83
84     /* SHA-224 and SHA-256 use this part of the union: */
85     struct {
86         cm_sha2_uint32_t state[8];
87         cm_sha2_uint64_t bitcount;
88         cm_sha2_uint8_t  buffer[64];
89     } s256;
90
91     /* SHA-384 and SHA-512 use this part of the union: */
92     struct {
93         cm_sha2_uint64_t state[8];
94         cm_sha2_uint64_t bitcount[2];
95         cm_sha2_uint8_t  buffer[128];
96     } s512;
97 } SHA_CTX;
98
99 /*** SHA-256/384/512 Function Prototypes ******************************/
100
101 void SHA1_Init(SHA_CTX*);
102 void SHA1_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
103 void SHA1_Final(cm_sha2_uint8_t[SHA1_DIGEST_LENGTH], SHA_CTX*);
104 char* SHA1_End(SHA_CTX*, char[SHA1_DIGEST_STRING_LENGTH]);
105 char* SHA1_Data(const cm_sha2_uint8_t*, size_t,
106                 char[SHA1_DIGEST_STRING_LENGTH]);
107
108 void SHA224_Init(SHA_CTX*);
109 void SHA224_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
110 void SHA224_Final(cm_sha2_uint8_t[SHA224_DIGEST_LENGTH], SHA_CTX*);
111 char* SHA224_End(SHA_CTX*, char[SHA224_DIGEST_STRING_LENGTH]);
112 char* SHA224_Data(const cm_sha2_uint8_t*, size_t,
113                   char[SHA224_DIGEST_STRING_LENGTH]);
114
115 void SHA256_Init(SHA_CTX*);
116 void SHA256_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
117 void SHA256_Final(cm_sha2_uint8_t[SHA256_DIGEST_LENGTH], SHA_CTX*);
118 char* SHA256_End(SHA_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
119 char* SHA256_Data(const cm_sha2_uint8_t*, size_t,
120                   char[SHA256_DIGEST_STRING_LENGTH]);
121
122 void SHA384_Init(SHA_CTX*);
123 void SHA384_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
124 void SHA384_Final(cm_sha2_uint8_t[SHA384_DIGEST_LENGTH], SHA_CTX*);
125 char* SHA384_End(SHA_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
126 char* SHA384_Data(const cm_sha2_uint8_t*, size_t,
127                   char[SHA384_DIGEST_STRING_LENGTH]);
128
129 void SHA512_Init(SHA_CTX*);
130 void SHA512_Update(SHA_CTX*, const cm_sha2_uint8_t*, size_t);
131 void SHA512_Final(cm_sha2_uint8_t[SHA512_DIGEST_LENGTH], SHA_CTX*);
132 char* SHA512_End(SHA_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
133 char* SHA512_Data(const cm_sha2_uint8_t*, size_t,
134                   char[SHA512_DIGEST_STRING_LENGTH]);
135
136 #ifdef    __cplusplus
137 }
138 #endif /* __cplusplus */
139
140 #endif /* __SHA2_H__ */