Files
s1d3sw1ped b38f7f643b Add bambu-nfc dump parse, Key-A HKDF, and spool merge.
Parse filanfc-dump/v1 zip/JSON, Bambu 1K images, and merge stickers by tray UID. dump and mifare packages stay importable for a later common library.
2026-08-23 15:23:11 -05:00

31 lines
656 B
Go

package bambunfc
import (
"crypto/hkdf"
"crypto/sha256"
"fmt"
)
var kdfSalt = []byte{
0x9a, 0x75, 0x9c, 0xf2, 0xc4, 0xf7, 0xca, 0xff,
0x22, 0x2c, 0xb9, 0x76, 0x9b, 0x41, 0xbc, 0x96,
}
const kdfInfo = "RFID-A\x00"
// KeysA derives the 16 MIFARE Key-A values for a Bambu tag from its chip UID.
func KeysA(uid []byte) ([16][6]byte, error) {
var keys [16][6]byte
if len(uid) == 0 {
return keys, fmt.Errorf("%w: empty", ErrUID)
}
okm, err := hkdf.Key(sha256.New, uid, kdfSalt, kdfInfo, 16*6)
if err != nil {
return keys, fmt.Errorf("%w: hkdf: %v", ErrUID, err)
}
for i := range 16 {
copy(keys[i][:], okm[i*6:i*6+6])
}
return keys, nil
}