]>
git.saurik.com Git - apple/xnu.git/blob - libkern/crypto/corecrypto_sha2.c
2 * Copyright (c) 2012 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <libkern/crypto/crypto_internal.h>
30 #include <libkern/crypto/sha2.h>
31 #include <libkern/libkern.h>
32 #include <kern/debug.h>
33 #include <corecrypto/ccdigest.h>
35 #if defined(CRYPTO_SHA2)
37 void SHA256_Init(SHA256_CTX
*ctx
)
39 const struct ccdigest_info
*di
;
40 di
=g_crypto_funcs
->ccsha256_di
;
42 /* Make sure the context size for the digest info fits in the one we have */
43 if(ccdigest_di_size(di
)>sizeof(SHA256_CTX
))
44 panic("%s: inconsistent size for SHA256 context", __FUNCTION__
);
46 g_crypto_funcs
->ccdigest_init_fn(di
, ctx
->ctx
);
49 void SHA256_Update(SHA256_CTX
*ctx
, const void *data
, size_t len
)
51 const struct ccdigest_info
*di
;
52 di
=g_crypto_funcs
->ccsha256_di
;
54 g_crypto_funcs
->ccdigest_update_fn(di
, ctx
->ctx
, len
, data
);
57 void SHA256_Final(void *digest
, SHA256_CTX
*ctx
)
59 const struct ccdigest_info
*di
;
60 di
=g_crypto_funcs
->ccsha256_di
;
62 ccdigest_final(di
, ctx
->ctx
, digest
);
65 void SHA384_Init(SHA384_CTX
*ctx
)
67 const struct ccdigest_info
*di
;
68 di
=g_crypto_funcs
->ccsha384_di
;
70 /* Make sure the context size for the digest info fits in the one we have */
71 if(ccdigest_di_size(di
)>sizeof(SHA384_CTX
))
72 panic("%s: inconsistent size for SHA384 context", __FUNCTION__
);
74 g_crypto_funcs
->ccdigest_init_fn(di
, ctx
->ctx
);
77 void SHA384_Update(SHA384_CTX
*ctx
, const void *data
, size_t len
)
79 const struct ccdigest_info
*di
;
80 di
=g_crypto_funcs
->ccsha384_di
;
82 g_crypto_funcs
->ccdigest_update_fn(di
, ctx
->ctx
, len
, data
);
86 void SHA384_Final(void *digest
, SHA384_CTX
*ctx
)
88 const struct ccdigest_info
*di
;
89 di
=g_crypto_funcs
->ccsha384_di
;
91 ccdigest_final(di
, ctx
->ctx
, digest
);
94 void SHA512_Init(SHA512_CTX
*ctx
)
96 const struct ccdigest_info
*di
;
97 di
=g_crypto_funcs
->ccsha512_di
;
99 /* Make sure the context size for the digest info fits in the one we have */
100 if(ccdigest_di_size(di
)>sizeof(SHA512_CTX
))
101 panic("%s: inconsistent size for SHA512 context", __FUNCTION__
);
103 g_crypto_funcs
->ccdigest_init_fn(di
, ctx
->ctx
);
106 void SHA512_Update(SHA512_CTX
*ctx
, const void *data
, size_t len
)
108 const struct ccdigest_info
*di
;
109 di
=g_crypto_funcs
->ccsha512_di
;
111 g_crypto_funcs
->ccdigest_update_fn(di
, ctx
->ctx
, len
, data
);
114 void SHA512_Final(void *digest
, SHA512_CTX
*ctx
)
116 const struct ccdigest_info
*di
;
117 di
=g_crypto_funcs
->ccsha512_di
;
119 ccdigest_final(di
, ctx
->ctx
, digest
);
124 /* As these are part of the KPI, we need to stub them out for any kernel configuration that does not support SHA2. */
126 void UNSUPPORTED_API(SHA256_Init
, SHA256_CTX
*ctx
);
127 void UNSUPPORTED_API(SHA384_Init
, SHA384_CTX
*ctx
);
128 void UNSUPPORTED_API(SHA512_Init
, SHA512_CTX
*ctx
);
129 void UNSUPPORTED_API(SHA256_Update
, SHA256_CTX
*ctx
, const void *data
, size_t len
);
130 void UNSUPPORTED_API(SHA384_Update
, SHA384_CTX
*ctx
, const void *data
, size_t len
);
131 void UNSUPPORTED_API(SHA512_Update
, SHA512_CTX
*ctx
, const void *data
, size_t len
);
132 void UNSUPPORTED_API(SHA256_Final
, void *digest
, SHA256_CTX
*ctx
);
133 void UNSUPPORTED_API(SHA384_Final
, void *digest
, SHA384_CTX
*ctx
);
134 void UNSUPPORTED_API(SHA512_Final
, void *digest
, SHA512_CTX
*ctx
);