crc32.c 861 B

12345678910111213141516171819202122232425262728293031
  1. /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. #include "crc32.h"
  13. #include <stdlib.h>
  14. uint32_t crc32_compute(uint8_t const * p_data, uint32_t size, uint32_t const * p_crc)
  15. {
  16. uint32_t crc;
  17. crc = (p_crc == NULL) ? 0xFFFFFFFF : ~(*p_crc);
  18. for (uint32_t i = 0; i < size; i++)
  19. {
  20. crc = crc ^ p_data[i];
  21. for (uint32_t j = 8; j > 0; j--)
  22. {
  23. crc = (crc >> 1) ^ (0xEDB88320 & -(crc & 1));
  24. }
  25. }
  26. return ~crc;
  27. }