1 /* 2 * Copyright (C) 2024 BayLibre. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/sys/crc.h> 8 9 #define CRC24_PGP_POLY 0x01864cfbU 10 crc24_pgp(const uint8_t * data,size_t len)11uint32_t crc24_pgp(const uint8_t *data, size_t len) 12 { 13 return crc24_pgp_update(CRC24_PGP_INITIAL_VALUE, data, len) & CRC24_FINAL_VALUE_MASK; 14 } 15 16 /* CRC-24 implementation from the section 6.1 of the RFC 4880 */ crc24_pgp_update(uint32_t crc,const uint8_t * data,size_t len)17uint32_t crc24_pgp_update(uint32_t crc, const uint8_t *data, size_t len) 18 { 19 int i; 20 21 while (len--) { 22 crc ^= (*data++) << 16; 23 for (i = 0; i < 8; i++) { 24 crc <<= 1; 25 if (crc & 0x01000000) { 26 crc ^= CRC24_PGP_POLY; 27 } 28 } 29 } 30 31 return crc; 32 } 33