]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/cspxutils/ccOpensslCompat/digestCommon.h
2 * digestCommon.h - openssl-style digest ops that can be redirected to CommonDigest.h
6 * Currently, SHA2 functions are not implemented by OpenSSL, even though they are
7 * present in the header <openssl/fips_sha.h>.
9 * <rdar://problem/4753005> SHA2 functions are declared, but not implemented
11 * For now we'll have to redirect openssl SHA2 calls manually just to get this
12 * program to build and run correctly. (We could just disable all of the SHA2
13 * code but we still get a benefit from compiling openssl-style code).
15 #define OPENSSL_SHA2_IMPLEMENTED 0
17 #include "digestCommonExtern.h"
19 #ifdef COMMON_DIGEST_FOR_OPENSSL
21 /* redirecting to CommonDigest */
27 #define doSHA224 sha224cc
28 #define doSHA256 sha256cc
29 #define doSHA384 sha384cc
30 #define doSHA512 sha512cc
32 #else /* !COMMON_DIGEST_FOR_OPENSSL */
40 #define doSHA224 sha224os
41 #define doSHA256 sha256os
42 #define doSHA384 sha384os
43 #define doSHA512 sha512os
45 #if !OPENSSL_SHA2_IMPLEMENTED
47 /* Hack: redirect SHA2 calls after all */
49 #include <CommonCrypto/CommonDigest.h>
51 #define SHA256_CTX CC_SHA256_CTX
52 #define SHA224_Init(c) CC_SHA224_Init(c)
53 #define SHA224_Update(c,d,l) CC_SHA224_Update(c,d,l)
54 #define SHA224_Final(m, c) CC_SHA224_Final(m,c)
56 #define SHA256_Init(c) CC_SHA256_Init(c)
57 #define SHA256_Update(c,d,l) CC_SHA256_Update(c,d,l)
58 #define SHA256_Final(m, c) CC_SHA256_Final(m,c)
60 #define SHA512_CTX CC_SHA512_CTX
61 #define SHA384_Init(c) CC_SHA384_Init(c)
62 #define SHA384_Update(c,d,l) CC_SHA384_Update(c,d,l)
63 #define SHA384_Final(m, c) CC_SHA384_Final(m,c)
65 #define SHA512_Init(c) CC_SHA512_Init(c)
66 #define SHA512_Update(c,d,l) CC_SHA512_Update(c,d,l)
67 #define SHA512_Final(m, c) CC_SHA512_Final(m,c)
69 #endif /* OPENSSL_SHA2_IMPLEMENTED */
72 #endif /* COMMON_DIGEST_FOR_OPENSSL */
74 /* all functions return nonzero on error */
76 int doMD2(const void *p
, unsigned long len
, unsigned char *md
)
78 /* OPenSSL MD2 is not orthogonal: the pointer is a const unsigned char * */
80 const unsigned char *cp
= (const unsigned char *)p
;
85 if(!MD2_Update(&ctx
, cp
, len
)) {
88 if(!MD2_Final(md
, &ctx
)) {
94 int doMD4(const void *p
, unsigned long len
, unsigned char *md
)
100 if(!MD4_Update(&ctx
, p
, len
)) {
103 if(!MD4_Final(md
, &ctx
)) {
109 int doMD5(const void *p
, unsigned long len
, unsigned char *md
)
112 if(!MD5_Init(&ctx
)) {
115 if(!MD5_Update(&ctx
, p
, len
)) {
118 if(!MD5_Final(md
, &ctx
)) {
124 int doSHA1(const void *p
, unsigned long len
, unsigned char *md
)
127 if(!SHA1_Init(&ctx
)) {
130 if(!SHA1_Update(&ctx
, p
, len
)) {
133 if(!SHA1_Final(md
, &ctx
)) {
139 int doSHA224(const void *p
, unsigned long len
, unsigned char *md
)
142 if(!SHA224_Init(&ctx
)) {
145 if(!SHA224_Update(&ctx
, p
, len
)) {
148 if(!SHA224_Final(md
, &ctx
)) {
154 int doSHA256(const void *p
, unsigned long len
, unsigned char *md
)
157 if(!SHA256_Init(&ctx
)) {
160 if(!SHA256_Update(&ctx
, p
, len
)) {
163 if(!SHA256_Final(md
, &ctx
)) {
169 int doSHA384(const void *p
, unsigned long len
, unsigned char *md
)
172 if(!SHA384_Init(&ctx
)) {
175 if(!SHA384_Update(&ctx
, p
, len
)) {
178 if(!SHA384_Final(md
, &ctx
)) {
184 int doSHA512(const void *p
, unsigned long len
, unsigned char *md
)
187 if(!SHA512_Init(&ctx
)) {
190 if(!SHA512_Update(&ctx
, p
, len
)) {
193 if(!SHA512_Final(md
, &ctx
)) {