Replaced hf mf bambukeys with hf mf keygen with multiple KDFs support, use table for key output

Added Snapmaker U1 filament RFID KDF in `hf mf keygen`
This commit is contained in:
Foxushka committed 2025-11-10 20:58:49 +03:00
1 parent 3d53e85743
commit b380132cbb
7 files changed
+173 -41

No files matched your search

+63
View File
@@ -280,6 +280,7 @@ uint32_t ul_c_otpgenA(const uint8_t *uid) {
// Each algo implementation should offer two key generation functions.
// 1. function that returns all keys
// 2. function that returns one key, target sector | block
// Then add function to KDFTable with allowed UID sizes
//------------------------------------
//------------------------------------
@@ -576,6 +577,68 @@ int mfc_algo_bambu_all(uint8_t *uid, uint8_t *keys) {
return PM3_SUCCESS;
}
const uint8_t snapmaker_salt_a[] = "Snapmaker_qwertyuiop[,.;]";
const uint8_t snapmaker_salt_b[] = "Snapmaker_qwertyuiop[,.;]_1q2w3e";
int mfc_algo_snapmaker_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *key) {
if (uid == NULL) return PM3_EINVARG;
if (key == NULL) return PM3_EINVARG;
if (sector >= 16) return PM3_EINVARG;
const uint8_t *salt = (keytype == 0) ? snapmaker_salt_a : snapmaker_salt_b;
size_t salt_len = (keytype == 0) ? sizeof(snapmaker_salt_a) - 1 : sizeof(snapmaker_salt_b) - 1;
char key_char = (keytype == 0) ? 'a' : 'b';
// "key_a_0", "key_b_15"
char info[16];
snprintf(info, sizeof(info), "key_%c_%d", key_char, sector);
uint8_t output[6];
const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256);
mbedtls_hkdf(md_info, salt, salt_len, uid, 4, (const uint8_t *)info, strlen(info), output, 6);
*key = bytes_to_num(output, 6);
return PM3_SUCCESS;
}
int mfc_algo_snapmaker_all(uint8_t *uid, uint8_t *keys) {
if (uid == NULL) return PM3_EINVARG;
if (keys == NULL) return PM3_EINVARG;
for (int i = 0; i < 16; i++) {
uint64_t key = 0;
mfc_algo_snapmaker_one(uid, i, 0, &key);
num_to_bytes(key, 6, keys + (i * 6));
}
for (int i = 0; i < 16; i++) {
uint64_t key = 0;
mfc_algo_snapmaker_one(uid, i, 1, &key);
num_to_bytes(key, 6, keys + ((16 + i) * 6));
}
return PM3_SUCCESS;
}
static kdf_t KDFTable[] = {
{"Saflok / Maid", 16, mfc_algo_saflok_all, 4},
{"MIZIP", 5, mfc_algo_mizip_all, 4},
{"Disney Infinity", 5, mfc_algo_di_all, 7},
{"Skylanders", 16, mfc_algo_sky_all, 4},
{"Bambu Lab Filament Spool", 16, mfc_algo_bambu_all, 4},
{"Snapmaker Filament Spool", 16, mfc_algo_snapmaker_all, 4},
// {"Vinglock", 16, mfc_algo_ving_all, 4}, // not implemented
// {"Yale Doorman", 16, mfc_algo_yale_all, 4}, // not implemented
};
const kdf_t *get_kdf_table(void) {
return KDFTable;
}
size_t get_kdf_table_size(void) {
return ARRAYLEN(KDFTable);
}
// LF T55x7 White gun cloner algo
uint32_t lf_t55xx_white_pwdgen(uint32_t id) {
uint32_t r1 = rotl(id & 0x000000ec, 8);
+15
View File
@@ -40,6 +40,17 @@ uint16_t ul_ev1_packgenG(const uint8_t *uid, const uint8_t *mfg);
uint32_t ul_c_otpgenA(const uint8_t *uid);
// Stucture for KDF function list
typedef struct {
const char *name;
int sector_count;
int (*kdf_function)(uint8_t *, uint8_t *);
int uid_length;
} kdf_t;
const kdf_t *get_kdf_table(void);
size_t get_kdf_table_size(void);
int mfc_algo_ving_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *key);
int mfc_algo_ving_all(uint8_t *uid, uint8_t *keys);
@@ -64,6 +75,10 @@ int mfc_algo_touch_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *
int mfc_algo_bambu_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *key);
int mfc_algo_bambu_all(uint8_t *uid, uint8_t *keys);
int mfc_algo_snapmaker_one(uint8_t *uid, uint8_t sector, uint8_t keytype, uint64_t *key);
int mfc_algo_snapmaker_all(uint8_t *uid, uint8_t *keys);
uint32_t lf_t55xx_white_pwdgen(uint32_t id);
int mfdes_kdf_input_gallagher(uint8_t *uid, uint8_t uidLen, uint8_t keyNo, uint32_t aid, uint8_t *kdfInputOut, uint8_t *kdfInputLen);