crc8

package module
v0.0.0-...-2243fe6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2022 License: MIT Imports: 1 Imported by: 74

README

crc8

Build Status Coverage Status GoDoc

Go implementation of CRC-8 calculation for majority of widely-used polinomials.

Usage

package main

import (
	"fmt"
	"github.com/sigurn/crc8"
)

func main() {
	table := crc8.MakeTable(crc8.CRC8_MAXIM)
	crc := crc8.Checksum([]byte("Hello world!"), table)
	fmt.Printf("CRC-8 MAXIM: %X", crc)
}

Documentation

For more documentation see package documentation

License

The MIT License (MIT)

Copyright (c) 2015 sigurn

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package crc8 implements the 8-bit cyclic redundancy check, or CRC-8, checksum.

It provides parameters for the majority of well-known CRC-8 algorithms.

Index

Constants

This section is empty.

Variables

View Source
var (
	CRC8          = Params{0x07, 0x00, false, false, 0x00, 0xF4, "CRC-8"}
	CRC8_CDMA2000 = Params{0x9B, 0xFF, false, false, 0x00, 0xDA, "CRC-8/CDMA2000"}
	CRC8_DARC     = Params{0x39, 0x00, true, true, 0x00, 0x15, "CRC-8/DARC"}
	CRC8_DVB_S2   = Params{0xD5, 0x00, false, false, 0x00, 0xBC, "CRC-8/DVB-S2"}
	CRC8_EBU      = Params{0x1D, 0xFF, true, true, 0x00, 0x97, "CRC-8/EBU"}
	CRC8_I_CODE   = Params{0x1D, 0xFD, false, false, 0x00, 0x7E, "CRC-8/I-CODE"}
	CRC8_ITU      = Params{0x07, 0x00, false, false, 0x55, 0xA1, "CRC-8/ITU"}
	CRC8_MAXIM    = Params{0x31, 0x00, true, true, 0x00, 0xA1, "CRC-8/MAXIM"}
	CRC8_ROHC     = Params{0x07, 0xFF, true, true, 0x00, 0xD0, "CRC-8/ROHC"}
	CRC8_WCDMA    = Params{0x9B, 0x00, true, true, 0x00, 0x25, "CRC-8/WCDMA"}
)

Predefined CRC-8 algorithms. List of algorithms with their parameters borrowed from here - http://reveng.sourceforge.net/crc-catalogue/1-15.htm#crc.cat-bits.8

The variables can be used to create Table for the selected algorithm.

Functions

func Checksum

func Checksum(data []byte, table *Table) uint8

Checksum returns CRC checksum of data using specified algorithm represented by the Table.

func Complete

func Complete(crc uint8, table *Table) uint8

Complete returns the result of CRC calculation and post-calculation processing of the crc.

func Init

func Init(table *Table) uint8

Init returns the initial value for CRC register corresponding to the specified algorithm.

func Update

func Update(crc uint8, data []byte, table *Table) uint8

Update returns the result of adding the bytes in data to the crc.

Types

type Params

type Params struct {
	Poly   uint8
	Init   uint8
	RefIn  bool
	RefOut bool
	XorOut uint8
	Check  uint8
	Name   string
}

Params represents parameters of a CRC-8 algorithm including polynomial and initial value. More information about algorithms parametrization and parameter descriptions can be found here - http://www.zlib.net/crc_v3.txt

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is a 256-byte table representing polynomial and algorithm settings for efficient processing.

func MakeTable

func MakeTable(params Params) *Table

MakeTable returns the Table constructed from the specified algorithm.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL