Sha256: fe4d25b7a8bd777c2fee22b03db221c02b637ff68390874a0f0e52aea6985998

Contents?: true

Size: 826 Bytes

Versions: 36

Compression:

Stored size: 826 Bytes

Contents

/*
** crc.c - calculate CRC
**
** See Copyright Notice in mruby.h
*/

#include <limits.h>
#include <stdint.h>
#include <stddef.h>

/* Calculate CRC (CRC-16-CCITT)
**
**  0000_0000_0000_0000_0000_0000_0000_0000
**          ^|------- CRC -------|- work --|
**        carry
*/
#define  CRC_16_CCITT       0x11021ul        /* x^16+x^12+x^5+1 */
#define  CRC_XOR_PATTERN    (CRC_16_CCITT << 8)
#define  CRC_CARRY_BIT      (0x01000000)

uint16_t
calc_crc_16_ccitt(const uint8_t *src, size_t nbytes, uint16_t crc)
{
  size_t ibyte;
  uint32_t ibit;
  uint32_t crcwk = crc << 8;

  for (ibyte = 0; ibyte < nbytes; ibyte++) {
    crcwk |= *src++;
    for (ibit = 0; ibit < CHAR_BIT; ibit++) {
      crcwk <<= 1;
      if (crcwk & CRC_CARRY_BIT) {
        crcwk ^= CRC_XOR_PATTERN;
      }
    }
  }
  return (uint16_t)(crcwk >> 8);
}

Version data entries

36 entries across 36 versions & 3 rubygems

Version Path
script_core-0.2.7 ext/enterprise_script_service/mruby/src/crc.c
script_core-0.2.6 ext/enterprise_script_service/mruby/src/crc.c
script_core-0.2.5 ext/enterprise_script_service/mruby/src/crc.c
script_core-0.2.4 ext/enterprise_script_service/mruby/src/crc.c
script_core-0.2.3 ext/enterprise_script_service/mruby/src/crc.c
script_core-0.2.2 ext/enterprise_script_service/mruby/src/crc.c
script_core-0.2.1 ext/enterprise_script_service/mruby/src/crc.c
script_core-0.2.0 ext/enterprise_script_service/mruby/src/crc.c
script_core-0.1.1 ext/enterprise_script_service/mruby/src/crc.c
script_core-0.1.0 ext/enterprise_script_service/mruby/src/crc.c
script_core-0.0.6 ext/enterprise_script_service/mruby/src/crc.c
script_core-0.0.5 ext/enterprise_script_service/mruby/src/crc.c
esruby-0.2.0 resources/mruby/src/crc.c
esruby-0.1.5 resources/mruby/src/crc.c
esruby-0.1.4 resources/mruby/src/crc.c
esruby-0.1.3 resources/mruby/src/crc.c
esruby-0.1.2 resources/mruby/src/crc.c
esruby-0.1.1 resources/mruby/src/crc.c
esruby-0.1.0 resources/mruby/src/crc.c
esruby-0.0.11 resources/mruby/src/crc.c