|
ForumsSega Master System / Mark III / Game GearSG-1000 / SC-3000 / SF-7000 / OMV |
Home - Forums - Games - Scans - Maps - Cheats - Credits Music - Videos - Development - Hacks - Translations - Homebrew |
Author | Message |
---|---|
|
Pearson hashing
Posted: Fri Apr 24, 2020 5:35 am
|
A user of the Plutiedev Discord server mentioned an interesting hash function called Pearson hashing. It could be useful as a relatively strong error detection checksum of a saved game in battery SRAM. From Wikipedia's article:
In the past, I have used the S-box from AES as such a permutation. I imagine it'd look like this on a Z80 (untested): ;;
; Calculates the Pearson hash of an array ; @param BC length of message ; @param HL pointer to start of message pearson_hash: ld a, c ; start hash at low byte of message length ld d, high(rijndaelS) ; align this to 256 bytes! dec bc ; Increment B if C is nonzero inc b inc c @loop: ; here: A = hash xor [hl] ; Combine data byte with current hash value inc hl ld e, a ; Scramble through S-box ld a, [de] dec c ; Count bytes jr nz, @loop djnz @loop ret |
|
|
Posted: Fri Apr 24, 2020 7:07 am |
Thanks PinoBatch! It looks quite interesting for some integrity checking as you suggested! :-D | |
|
Posted: Fri Apr 24, 2020 3:21 pm |
Here’s my implementation from a few months ago:
https://github.com/SavagePencil/SMSFramework/blob/master/Utils/hash_function.asm |
|