Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

crc32.c 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Little-endian CRC32 implementation.
  3. *
  4. * Copyright (c) 2009 Joshua Oreman <oremanj@rwcr.net>.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of the
  9. * License, or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. FILE_LICENCE ( GPL2_OR_LATER );
  21. #include <gpxe/crc32.h>
  22. #define CRCPOLY 0xedb88320
  23. /**
  24. * Calculate 32-bit little-endian CRC checksum
  25. *
  26. * @v seed Initial value
  27. * @v data Data to checksum
  28. * @v len Length of data
  29. *
  30. * Usually @a seed is initially zero or all one bits, depending on the
  31. * protocol. To continue a CRC checksum over multiple calls, pass the
  32. * return value from one call as the @a seed parameter to the next.
  33. */
  34. u32 crc32_le ( u32 seed, const void *data, size_t len )
  35. {
  36. u32 crc = seed;
  37. const u8 *src = data;
  38. u32 mult;
  39. int i;
  40. while ( len-- ) {
  41. crc ^= *src++;
  42. for ( i = 0; i < 8; i++ ) {
  43. mult = ( crc & 1 ) ? CRCPOLY : 0;
  44. crc = ( crc >> 1 ) ^ mult;
  45. }
  46. }
  47. return crc;
  48. }