#include <utilities/SecCFCCWrappers.h>
CFDataRef CFDataCreateDigestWithBytes(CFAllocatorRef allocator, const struct ccdigest_info *di, size_t len,
const void *data, CFErrorRef *error) {
CFMutableDataRef digest = CFDataCreateMutable(allocator, di->output_size);
CFDataSetLength(digest, di->output_size);
ccdigest(di, len, data, CFDataGetMutableBytePtr(digest));
return digest;
}
CFDataRef CFDataCreateSHA1DigestWithBytes(CFAllocatorRef allocator, size_t len, const void *data, CFErrorRef *error) {
return CFDataCreateDigestWithBytes(allocator, ccsha1_di(), len, data, error);
}
CFDataRef CFDataCreateSHA256DigestWithBytes(CFAllocatorRef allocator, size_t len, const void *data, CFErrorRef *error) {
return CFDataCreateDigestWithBytes(allocator, ccsha256_di(), len, data, error);
}
CFDataRef CFDataCopySHA1Digest(CFDataRef dataToDigest, CFErrorRef *error) {
CFIndex length = CFDataGetLength(dataToDigest);
assert((unsigned long)length < UINT32_MAX);
return CFDataCreateSHA1DigestWithBytes(CFGetAllocator(dataToDigest), length, CFDataGetBytePtr(dataToDigest), error);
}
CFDataRef CFDataCopySHA256Digest(CFDataRef dataToDigest, CFErrorRef *error) {
CFIndex length = CFDataGetLength(dataToDigest);
assert((unsigned long)length < UINT32_MAX);
return CFDataCreateSHA256DigestWithBytes(CFGetAllocator(dataToDigest), length, CFDataGetBytePtr(dataToDigest), error);
}