libSPEC
Pokemon Save Editing Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Pages
Functions
checksum.h File Reference

Containes functions for calculation of checksums. More...

#include <stdlib.h>
#include <stdint.h>

Functions

uint16_t nds_crc16 (const uint8_t *, size_t)
 Calculates the CRC-16-IBM of the given data. More...
 
uint16_t gba_block_checksum (const uint8_t *, size_t)
 Calculates a 16-bit block checksum of the given data. More...
 
uint8_t gb_rby_checksum (const uint8_t *, size_t)
 Calculates the 8-bit GB block checksum of the given data. More...
 
uint16_t gb_gsc_checksum (const uint8_t *, size_t)
 Calculates the 16-bit GB block checksum of the given data. More...
 
uint16_t pkm_checksum (const uint8_t *, size_t)
 Calculates a simple 16-bit checksum of the given data. More...
 
uint16_t pk3_checksum (const uint8_t *, size_t)
 Calculates a simple 16-bit checksum of the given data. More...
 

Detailed Description

Containes functions for calculation of checksums.

Function Documentation

uint16_t nds_crc16 ( const uint8_t *  ptr,
size_t  size 
)

Calculates the CRC-16-IBM of the given data.

This is used by NDS saves for calculating block checksums.

Parameters
ptrThe pointer to the start of the data.
sizeThe length of the data.
Returns
The CRC-16-IBM value.
uint16_t gba_block_checksum ( const uint8_t *  ptr,
size_t  size 
)

Calculates a 16-bit block checksum of the given data.

This is used by the GBA to calculate block checksums.

Parameters
ptrThe pointer to the start of the data.
sizeThe length of the data.
Returns
The 16-bit block checksum of the given data.
uint8_t gb_rby_checksum ( const uint8_t *  ptr,
size_t  size 
)

Calculates the 8-bit GB block checksum of the given data.

This is used by Pokemon Red, Blue, and Yellow to calculate block checksums.

Parameters
ptrThe pointer to the start of the data.
sizeThe length of the data.
Returns
The 8-bit block checksum of the given data.
uint16_t gb_gsc_checksum ( const uint8_t *  ptr,
size_t  size 
)

Calculates the 16-bit GB block checksum of the given data.

This is used by Pokemon Gold, Silver, and Crystal to calculate block checksums.

Parameters
ptrThe pointer to the start of the data.
sizeThe length of the data.
Returns
The 16-bit block checksum of the given data.
uint16_t pkm_checksum ( const uint8_t *  ptr,
size_t  size 
)

Calculates a simple 16-bit checksum of the given data.

This is used in the PKM data structures to calculate the checksum of the encrypted blocks.

Parameters
ptrThe pointer to the start of the data.
sizeThe length of the data.
Returns
The 16-bit checksum of the given data.
uint16_t pk3_checksum ( const uint8_t *  ptr,
size_t  size 
)

Calculates a simple 16-bit checksum of the given data.

This is simply a copy of pkm_checksum(), it is used in the PK3 data structures to calculate the checksum of the encrypted blocks.

Parameters
ptrThe pointer to the start of the data.
sizeThe length of the data.
Returns
The 16-bit checksum of the given data