]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cryptkit/lib/ckSHA1.c
1 /* Copyright (c) 1998,2011,2014 Apple Inc. All Rights Reserved.
3 * NOTICE: USE OF THE MATERIALS ACCOMPANYING THIS NOTICE IS SUBJECT
4 * TO THE TERMS OF THE SIGNED "FAST ELLIPTIC ENCRYPTION (FEE) REFERENCE
5 * SOURCE CODE EVALUATION AGREEMENT" BETWEEN APPLE, INC. AND THE
6 * ORIGINAL LICENSEE THAT OBTAINED THESE MATERIALS FROM APPLE,
7 * INC. ANY USE OF THESE MATERIALS NOT PERMITTED BY SUCH AGREEMENT WILL
8 * EXPOSE YOU TO LIABILITY.
9 ***************************************************************************
11 * ckSHA1.c - generic, portable SHA-1 hash object
16 * Changed to compile with C++.
17 * 07 Jan 1998 at Apple
26 * For linking with AppleCSP: use libSystem SHA1 implementation.
28 #include <CommonCrypto/CommonDigest.h>
33 * Trivial wrapper for SHA_CTX; a sha1Obj is a pointer to this.
37 unsigned char digest
[CC_SHA1_DIGEST_LENGTH
];
40 sha1Obj
sha1Alloc(void)
42 void *rtn
= fmalloc(sizeof(Sha1Obj
));
43 memset(rtn
, 0, sizeof(Sha1Obj
));
44 CC_SHA1_Init(&(((Sha1Obj
*)rtn
)->ctx
));
48 void sha1Reinit(sha1Obj sha1
)
50 Sha1Obj
*ctx
= (Sha1Obj
*)sha1
;
51 CC_SHA1_Init(&ctx
->ctx
);
54 void sha1Free(sha1Obj sha1
)
56 memset(sha1
, 0, sizeof(Sha1Obj
));
60 void sha1AddData(sha1Obj sha1
,
61 const unsigned char *data
,
64 Sha1Obj
*ctx
= (Sha1Obj
*)sha1
;
65 CC_SHA1_Update(&ctx
->ctx
, data
, dataLen
);
68 unsigned char *sha1Digest(sha1Obj sha1
)
70 Sha1Obj
*ctx
= (Sha1Obj
*)sha1
;
71 CC_SHA1_Final(ctx
->digest
, &ctx
->ctx
);
75 unsigned sha1DigestLen(void)
77 return CC_SHA1_DIGEST_LENGTH
;