crc

package
v0.0.0-...-341aec2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHardwareCRC16Handler

func NewHardwareCRC16Handler(calculator interfaces.CRCCalculator) interfaces.SectionCRCHandler

NewHardwareCRC16Handler creates a new hardware CRC16 handler

func NewHardwareCRCCalculator

func NewHardwareCRCCalculator() interfaces.CRCCalculator

NewHardwareCRCCalculator creates a new hardware CRC calculator

func NewInSectionCRC16Handler

func NewInSectionCRC16Handler(calculator interfaces.CRCCalculator) interfaces.SectionCRCHandler

NewInSectionCRC16Handler creates a new in-section CRC16 handler

func NewSoftwareCRC16Handler

func NewSoftwareCRC16Handler(calculator interfaces.CRCCalculator) interfaces.SectionCRCHandler

NewSoftwareCRC16Handler creates a new software CRC16 handler

func NewSoftwareCRCCalculator

func NewSoftwareCRCCalculator() interfaces.CRCCalculator

NewSoftwareCRCCalculator creates a new software CRC calculator

Types

type BaseCRCHandler

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

BaseCRCHandler provides common CRC handling functionality that can be embedded in specific CRC handlers

func NewBaseCRCHandler

func NewBaseCRCHandler(calculator interfaces.CRCCalculator, crcOffset int, hasEmbeddedCRC bool) *BaseCRCHandler

NewBaseCRCHandler creates a new base CRC handler

func (*BaseCRCHandler) GetCRCOffset

func (h *BaseCRCHandler) GetCRCOffset() int

GetCRCOffset returns the offset where CRC is stored

func (*BaseCRCHandler) GetCalculator

func (h *BaseCRCHandler) GetCalculator() interfaces.CRCCalculator

GetCalculator returns the CRC calculator

func (*BaseCRCHandler) HasEmbeddedCRC

func (h *BaseCRCHandler) HasEmbeddedCRC() bool

HasEmbeddedCRC returns whether CRC is embedded in the section

func (*BaseCRCHandler) ValidateCRCType

func (h *BaseCRCHandler) ValidateCRCType(crcType types.CRCType, supportedTypes ...types.CRCType) error

ValidateCRCType checks if the CRC type is supported

func (*BaseCRCHandler) VerifyCRC

func (h *BaseCRCHandler) VerifyCRC(data []byte, expectedCRC uint32, crcType types.CRCType, calculateFunc func([]byte, types.CRCType) (uint32, error)) error

VerifyCRC provides common CRC verification logic

func (*BaseCRCHandler) VerifyCRC16

func (h *BaseCRCHandler) VerifyCRC16(data []byte, expectedCRC uint32, crcType types.CRCType, calculateFunc func([]byte, types.CRCType) (uint32, error)) error

VerifyCRC16 provides common CRC16 verification logic where only the lower 16 bits are significant

type Boot2CRCHandler

type Boot2CRCHandler struct {
	*BaseCRCHandler
	// contains filtered or unexported fields
}

Boot2CRCHandler implements CRC handling specifically for BOOT2 sections Based on mstflint's CheckBoot2 implementation

func NewBoot2CRCHandler

func NewBoot2CRCHandler() *Boot2CRCHandler

NewBoot2CRCHandler creates a new BOOT2 CRC handler

func (*Boot2CRCHandler) CalculateCRC

func (h *Boot2CRCHandler) CalculateCRC(data []byte, crcType types.CRCType) (uint32, error)

CalculateCRC calculates CRC16 for BOOT2 section BOOT2 format: - Header (16 bytes): magic(4) + size_dwords(4) + reserved(8) - Data (size_dwords * 4 bytes) - CRC is at offset (size_dwords + 3) * 4 CRC is calculated over (size_dwords + 3) dwords, excluding the CRC dword

func (*Boot2CRCHandler) VerifyCRC

func (h *Boot2CRCHandler) VerifyCRC(data []byte, expectedCRC uint32, crcType types.CRCType) error

VerifyCRC verifies the CRC for BOOT2 section

type CRCStrategy

type CRCStrategy interface {
	Calculate(calc *parser.CRCCalculator, data []byte) uint32
	GetType() types.CRCType
}

CRCStrategy defines the strategy for CRC calculation

type DefaultCRCHandler

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

DefaultCRCHandler provides default CRC handling for sections

func NewDefaultCRCHandler

func NewDefaultCRCHandler() *DefaultCRCHandler

NewDefaultCRCHandler creates a new default CRC handler

func (*DefaultCRCHandler) CalculateCRC

func (h *DefaultCRCHandler) CalculateCRC(data []byte, crcType types.CRCType) (uint32, error)

CalculateCRC calculates the CRC for the section data

func (*DefaultCRCHandler) GetCRCOffset

func (h *DefaultCRCHandler) GetCRCOffset() int

GetCRCOffset returns the offset of CRC within the section data (if CRC is embedded)

func (*DefaultCRCHandler) HasEmbeddedCRC

func (h *DefaultCRCHandler) HasEmbeddedCRC() bool

HasEmbeddedCRC returns true if CRC is stored within the section data

func (*DefaultCRCHandler) VerifyCRC

func (h *DefaultCRCHandler) VerifyCRC(data []byte, expectedCRC uint32, crcType types.CRCType) error

VerifyCRC verifies the CRC for the section

type GenericCRCCalculator

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

GenericCRCCalculator implements CRC calculation using a strategy

func NewGenericCRCCalculator

func NewGenericCRCCalculator(strategy CRCStrategy) *GenericCRCCalculator

NewGenericCRCCalculator creates a new generic CRC calculator with a strategy

func (*GenericCRCCalculator) Calculate

func (c *GenericCRCCalculator) Calculate(data []byte) uint32

Calculate calculates CRC for the given data using the strategy

func (*GenericCRCCalculator) CalculateImageCRC

func (c *GenericCRCCalculator) CalculateImageCRC(data []byte, sizeInDwords int) uint16

CalculateImageCRC calculates CRC for firmware image data (handles endianness)

func (*GenericCRCCalculator) CalculateWithParams

func (c *GenericCRCCalculator) CalculateWithParams(data []byte, polynomial, initial, xorOut uint32) uint32

CalculateWithParams calculates CRC with specific parameters (uses default calculation)

func (*GenericCRCCalculator) GetType

func (c *GenericCRCCalculator) GetType() types.CRCType

GetType returns the CRC type from the strategy

type HandlerStrategy

type HandlerStrategy interface {
	CalculateCRC(calculator interfaces.CRCCalculator, data []byte, crcType types.CRCType) (uint32, error)
	ValidCRCTypes() []types.CRCType
}

HandlerStrategy defines the strategy for CRC calculation in handlers

type HardwareCRC16Strategy

type HardwareCRC16Strategy struct{}

HardwareCRC16Strategy implements hardware CRC16 calculation

func (*HardwareCRC16Strategy) CalculateCRC

func (h *HardwareCRC16Strategy) CalculateCRC(calculator interfaces.CRCCalculator, data []byte, crcType types.CRCType) (uint32, error)

func (*HardwareCRC16Strategy) ValidCRCTypes

func (h *HardwareCRC16Strategy) ValidCRCTypes() []types.CRCType

type HardwareCRCStrategy

type HardwareCRCStrategy struct{}

HardwareCRCStrategy implements hardware CRC calculation strategy

func (*HardwareCRCStrategy) Calculate

func (h *HardwareCRCStrategy) Calculate(calc *parser.CRCCalculator, data []byte) uint32

func (*HardwareCRCStrategy) GetType

func (h *HardwareCRCStrategy) GetType() types.CRCType

type InSectionCRC16Strategy

type InSectionCRC16Strategy struct{}

InSectionCRC16Strategy implements in-section CRC16 calculation

func (*InSectionCRC16Strategy) CalculateCRC

func (i *InSectionCRC16Strategy) CalculateCRC(calculator interfaces.CRCCalculator, data []byte, crcType types.CRCType) (uint32, error)

func (*InSectionCRC16Strategy) ValidCRCTypes

func (i *InSectionCRC16Strategy) ValidCRCTypes() []types.CRCType

type NoCRCHandler

type NoCRCHandler struct{}

NoCRCHandler implements a handler for sections without CRC

func NewNoCRCHandler

func NewNoCRCHandler() *NoCRCHandler

NewNoCRCHandler creates a new no-CRC handler

func (*NoCRCHandler) CalculateCRC

func (h *NoCRCHandler) CalculateCRC(data []byte, crcType types.CRCType) (uint32, error)

CalculateCRC returns 0 as there's no CRC

func (*NoCRCHandler) GetCRCOffset

func (h *NoCRCHandler) GetCRCOffset() int

GetCRCOffset returns -1 as there's no CRC

func (*NoCRCHandler) HasEmbeddedCRC

func (h *NoCRCHandler) HasEmbeddedCRC() bool

HasEmbeddedCRC returns false as there's no CRC

func (*NoCRCHandler) VerifyCRC

func (h *NoCRCHandler) VerifyCRC(data []byte, expectedCRC uint32, crcType types.CRCType) error

VerifyCRC always returns nil as there's no CRC to verify

type SoftwareCRC16Strategy

type SoftwareCRC16Strategy struct{}

SoftwareCRC16Strategy implements software CRC16 calculation

func (*SoftwareCRC16Strategy) CalculateCRC

func (s *SoftwareCRC16Strategy) CalculateCRC(calculator interfaces.CRCCalculator, data []byte, crcType types.CRCType) (uint32, error)

func (*SoftwareCRC16Strategy) ValidCRCTypes

func (s *SoftwareCRC16Strategy) ValidCRCTypes() []types.CRCType

type SoftwareCRCStrategy

type SoftwareCRCStrategy struct{}

SoftwareCRCStrategy implements software CRC calculation strategy

func (*SoftwareCRCStrategy) Calculate

func (s *SoftwareCRCStrategy) Calculate(calc *parser.CRCCalculator, data []byte) uint32

func (*SoftwareCRCStrategy) GetType

func (s *SoftwareCRCStrategy) GetType() types.CRCType

type ToolsAreaCRCHandler

type ToolsAreaCRCHandler struct {
	*BaseCRCHandler
	// contains filtered or unexported fields
}

ToolsAreaCRCHandler implements CRC handling specifically for TOOLS_AREA sections

func NewToolsAreaCRCHandler

func NewToolsAreaCRCHandler() *ToolsAreaCRCHandler

NewToolsAreaCRCHandler creates a new TOOLS_AREA CRC handler

func (*ToolsAreaCRCHandler) CalculateCRC

func (h *ToolsAreaCRCHandler) CalculateCRC(data []byte, crcType types.CRCType) (uint32, error)

CalculateCRC calculates CRC16 for TOOLS_AREA (first 60 bytes)

func (*ToolsAreaCRCHandler) VerifyCRC

func (h *ToolsAreaCRCHandler) VerifyCRC(data []byte, expectedCRC uint32, crcType types.CRCType) error

VerifyCRC verifies the CRC for TOOLS_AREA section

type UnifiedCRCHandler

type UnifiedCRCHandler struct {
	*BaseCRCHandler
	// contains filtered or unexported fields
}

UnifiedCRCHandler implements a unified CRC handler using strategies

func NewUnifiedCRCHandler

func NewUnifiedCRCHandler(calculator interfaces.CRCCalculator, strategy HandlerStrategy, crcOffset int, hasEmbeddedCRC bool) *UnifiedCRCHandler

NewUnifiedCRCHandler creates a new unified CRC handler

func (*UnifiedCRCHandler) CalculateCRC

func (h *UnifiedCRCHandler) CalculateCRC(data []byte, crcType types.CRCType) (uint32, error)

CalculateCRC calculates CRC using the strategy

func (*UnifiedCRCHandler) VerifyCRC

func (h *UnifiedCRCHandler) VerifyCRC(data []byte, expectedCRC uint32, crcType types.CRCType) error

VerifyCRC verifies the CRC for the section

Jump to

Keyboard shortcuts

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