Fix checksum validation and property ID corruption in card modification#1
Open
KikoTs wants to merge 2 commits intogizmonicus:mainfrom
Open
Fix checksum validation and property ID corruption in card modification#1KikoTs wants to merge 2 commits intogizmonicus:mainfrom
KikoTs wants to merge 2 commits intogizmonicus:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When modifying Saflok cards, two critical bugs caused:
Root Causes
1. Creation Year Decoding Bug
The order of operations in
decode_card()was incorrect compared to the C implementation:Before (incorrect):
After (fixed):
This bug caused
creation_year_bitsto be calculated incorrectly during re-encoding, corrupting byte 14 which contains both the creation year bits and the property ID high bits.2. Alice Initialization Bug in Encryption
The
encrypt_card()function had a critical flaw in calculating thealicebit used for the bit-shuffling algorithm. The alice value is derived fromdc[10] & 1after stage 1 decryption, creating a circular dependency where:Solution: Test both possible alice values (0 and 1) and select the one that produces a self-consistent result. When both work, prefer alice=1 based on empirical testing.
Impact
Testing
Verified with real Saflok card data that modifying only the key level preserves the property ID (3573) and generates valid checksums.