xref: /xnu-12377.41.6/iokit/DriverKit/crypto/sha2.h (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1*bbb1b6f9SApple OSS Distributions /*
2*bbb1b6f9SApple OSS Distributions  * copyright (c) 2012 apple computer, inc. all rights reserved.
3*bbb1b6f9SApple OSS Distributions  *
4*bbb1b6f9SApple OSS Distributions  * @apple_osreference_license_header_start@
5*bbb1b6f9SApple OSS Distributions  *
6*bbb1b6f9SApple OSS Distributions  * this file contains original code and/or modifications of original code
7*bbb1b6f9SApple OSS Distributions  * as defined in and that are subject to the apple public source license
8*bbb1b6f9SApple OSS Distributions  * version 2.0 (the 'license'). you may not use this file except in
9*bbb1b6f9SApple OSS Distributions  * compliance with the license. the rights granted to you under the license
10*bbb1b6f9SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*bbb1b6f9SApple OSS Distributions  * unlawful or unlicensed copies of an apple operating system, or to
12*bbb1b6f9SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*bbb1b6f9SApple OSS Distributions  * terms of an apple operating system software license agreement.
14*bbb1b6f9SApple OSS Distributions  *
15*bbb1b6f9SApple OSS Distributions  * please obtain a copy of the license at
16*bbb1b6f9SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*bbb1b6f9SApple OSS Distributions  *
18*bbb1b6f9SApple OSS Distributions  * the original code and all software distributed under the license are
19*bbb1b6f9SApple OSS Distributions  * distributed on an 'as is' basis, without warranty of any kind, either
20*bbb1b6f9SApple OSS Distributions  * express or implied, and apple hereby disclaims all such warranties,
21*bbb1b6f9SApple OSS Distributions  * including without limitation, any warranties of merchantability,
22*bbb1b6f9SApple OSS Distributions  * fitness for a particular purpose, quiet enjoyment or non-infringement.
23*bbb1b6f9SApple OSS Distributions  * please see the license for the specific language governing rights and
24*bbb1b6f9SApple OSS Distributions  * limitations under the license.
25*bbb1b6f9SApple OSS Distributions  *
26*bbb1b6f9SApple OSS Distributions  * @apple_osreference_license_header_end@
27*bbb1b6f9SApple OSS Distributions  */
28*bbb1b6f9SApple OSS Distributions 
29*bbb1b6f9SApple OSS Distributions #ifndef _CRYPTO_SHA2_H__
30*bbb1b6f9SApple OSS Distributions #define _CRYPTO_SHA2_H__
31*bbb1b6f9SApple OSS Distributions 
32*bbb1b6f9SApple OSS Distributions #ifdef __cplusplus
33*bbb1b6f9SApple OSS Distributions extern "C" {
34*bbb1b6f9SApple OSS Distributions #endif
35*bbb1b6f9SApple OSS Distributions 
36*bbb1b6f9SApple OSS Distributions #include <corecrypto/ccsha2.h>
37*bbb1b6f9SApple OSS Distributions 
38*bbb1b6f9SApple OSS Distributions /*** SHA-256/384/512 Various Length Definitions ***********************/
39*bbb1b6f9SApple OSS Distributions #define SHA256_BLOCK_LENGTH             CCSHA256_BLOCK_SIZE
40*bbb1b6f9SApple OSS Distributions #define SHA256_DIGEST_LENGTH    CCSHA256_OUTPUT_SIZE
41*bbb1b6f9SApple OSS Distributions #define SHA256_DIGEST_STRING_LENGTH     (SHA256_DIGEST_LENGTH * 2 + 1)
42*bbb1b6f9SApple OSS Distributions #define SHA384_BLOCK_LENGTH             CCSHA512_BLOCK_SIZE
43*bbb1b6f9SApple OSS Distributions #define SHA384_DIGEST_LENGTH    CCSHA384_OUTPUT_SIZE
44*bbb1b6f9SApple OSS Distributions #define SHA384_DIGEST_STRING_LENGTH     (SHA384_DIGEST_LENGTH * 2 + 1)
45*bbb1b6f9SApple OSS Distributions #define SHA512_BLOCK_LENGTH             CCSHA512_BLOCK_SIZE
46*bbb1b6f9SApple OSS Distributions #define SHA512_DIGEST_LENGTH    CCSHA512_OUTPUT_SIZE
47*bbb1b6f9SApple OSS Distributions #define SHA512_DIGEST_STRING_LENGTH     (SHA512_DIGEST_LENGTH * 2 + 1)
48*bbb1b6f9SApple OSS Distributions 
49*bbb1b6f9SApple OSS Distributions typedef struct {
50*bbb1b6f9SApple OSS Distributions 	ccdigest_ctx_decl(CCSHA256_STATE_SIZE, CCSHA256_BLOCK_SIZE, ctx);
51*bbb1b6f9SApple OSS Distributions } SHA256_CTX;
52*bbb1b6f9SApple OSS Distributions 
53*bbb1b6f9SApple OSS Distributions typedef struct SHA512_CTX {
54*bbb1b6f9SApple OSS Distributions 	ccdigest_ctx_decl(CCSHA512_STATE_SIZE, CCSHA512_BLOCK_SIZE, ctx);
55*bbb1b6f9SApple OSS Distributions } SHA512_CTX;
56*bbb1b6f9SApple OSS Distributions 
57*bbb1b6f9SApple OSS Distributions typedef SHA512_CTX SHA384_CTX;
58*bbb1b6f9SApple OSS Distributions 
59*bbb1b6f9SApple OSS Distributions /*** SHA-256/384/512 Function Prototypes ******************************/
60*bbb1b6f9SApple OSS Distributions 
61*bbb1b6f9SApple OSS Distributions void SHA256_Init(SHA256_CTX *ctx);
62*bbb1b6f9SApple OSS Distributions void SHA256_Update(SHA256_CTX *ctx, const void *data, size_t len);
63*bbb1b6f9SApple OSS Distributions void SHA256_Final(void *digest, SHA256_CTX *ctx);
64*bbb1b6f9SApple OSS Distributions 
65*bbb1b6f9SApple OSS Distributions void SHA384_Init(SHA384_CTX *ctx);
66*bbb1b6f9SApple OSS Distributions void SHA384_Update(SHA384_CTX *ctx, const void *data, size_t len);
67*bbb1b6f9SApple OSS Distributions void SHA384_Final(void *digest, SHA384_CTX *ctx);
68*bbb1b6f9SApple OSS Distributions 
69*bbb1b6f9SApple OSS Distributions void SHA512_Init(SHA512_CTX *ctx);
70*bbb1b6f9SApple OSS Distributions void SHA512_Update(SHA512_CTX *ctx, const void *data, size_t len);
71*bbb1b6f9SApple OSS Distributions void SHA512_Final(void *digest, SHA512_CTX *ctx);
72*bbb1b6f9SApple OSS Distributions 
73*bbb1b6f9SApple OSS Distributions #ifdef  __cplusplus
74*bbb1b6f9SApple OSS Distributions }
75*bbb1b6f9SApple OSS Distributions #endif /* __cplusplus */
76*bbb1b6f9SApple OSS Distributions 
77*bbb1b6f9SApple OSS Distributions #endif /* _CRYPTO_SHA2_H__ */
78