1/* Copyright (c) 2012 Apple Inc. All rights reserved. */ 2 3#ifndef _SECURITY_AUTH_CRC_H_ 4#define _SECURITY_AUTH_CRC_H_ 5 6#if defined(__cplusplus) 7extern "C" { 8#endif 9 10extern const uint64_t _crc_table64[256]; 11extern const uint64_t xorout; 12 13AUTH_INLINE uint64_t 14crc64_init() 15{ 16 return xorout; 17} 18 19AUTH_INLINE uint64_t 20crc64_final(uint64_t crc) 21{ 22 return crc ^= xorout; 23} 24 25AUTH_INLINE AUTH_NONNULL_ALL uint64_t 26crc64_update(uint64_t crc, const void *buf, uint64_t len) 27{ 28 const unsigned char * ptr = (const unsigned char *) buf; 29 30 while (len-- > 0) { 31 crc = _crc_table64[((crc >> 56) ^ *(ptr++)) & 0xff] ^ (crc << 8); 32 } 33 34 return crc; 35} 36 37AUTH_INLINE uint64_t 38crc64(const void *buf, uint64_t len) 39{ 40 uint64_t crc = crc64_init(); 41 42 crc = crc64_update(crc, buf, len); 43 44 crc = crc64_final(crc); 45 46 return crc; 47} 48 49#if defined(__cplusplus) 50} 51#endif 52 53#endif /* !_SECURITY_AUTH_CRC_H_ */ 54