ADD: 'hf 14a read' - detection if found Mifare Classic tag has a weak or hardend PRNG. Thanks to @doegox for implementing it in nfc-tools/mfoc Its a beauty :)

This commit is contained in:
iceman1001
2017-06-26 21:45:22 +02:00
parent 89b24a69c0
commit 4d18909596
5 changed files with 91 additions and 36 deletions

View File

@@ -19,7 +19,7 @@
*/
#include "crapto1.h"
#include <stdlib.h>
#include <stdio.h>
#if !defined LOWMEM && defined __GNUC__
static uint8_t filterlut[1 << 20];
static void __attribute__((constructor)) fill_lut()
@@ -399,6 +399,17 @@ int nonce_distance(uint32_t from, uint32_t to)
return (65535 + dist[to >> 16] - dist[from >> 16]) % 65535;
}
/** validate_prng_nonce
* Determine if nonce is deterministic. ie: Suspectable to Darkside attack.
* returns
* true = weak prng
* false = hardend prng
*/
bool validate_prng_nonce(uint32_t nonce) {
// init prng table:
nonce_distance(nonce, nonce);
return ((65535 - dist[nonce >> 16] + dist[nonce & 0xffff]) % 65535) == 16;
}
static uint32_t fastfwd[2][8] = {
{ 0, 0x4BC53, 0xECB1, 0x450E2, 0x25E29, 0x6E27A, 0x2B298, 0x60ECB},
@@ -501,7 +512,7 @@ struct Crypto1State* lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8]
odd = lfsr_prefix_ks(ks, 1);
even = lfsr_prefix_ks(ks, 0);
s = statelist = malloc((sizeof *statelist) << 20);
s = statelist = malloc((sizeof *statelist) << 24);
if(!s || !odd || !even) {
free(statelist);
statelist = 0;
@@ -531,7 +542,7 @@ struct Crypto1State* lfsr_common_prefix_ex(uint32_t pfx, uint8_t ks[8])
odd = lfsr_prefix_ks(ks, 1);
even = lfsr_prefix_ks(ks, 0);
s = statelist = malloc((sizeof *statelist) << 20);
s = statelist = malloc((sizeof *statelist) << 24);
if(!s || !odd || !even) {
free(statelist);
statelist = 0;

View File

@@ -21,6 +21,7 @@
#define CRAPTO1_H__
#include <stdint.h>
#include <stdbool.h>
#include "bucketsort.h"
#ifdef __cplusplus
@@ -49,6 +50,7 @@ uint8_t lfsr_rollback_bit(struct Crypto1State* s, uint32_t in, int fb);
uint8_t lfsr_rollback_byte(struct Crypto1State* s, uint32_t in, int fb);
uint32_t lfsr_rollback_word(struct Crypto1State* s, uint32_t in, int fb);
int nonce_distance(uint32_t from, uint32_t to);
extern bool validate_prng_nonce(uint32_t nonce);
#define SWAPENDIAN(x)\
(x = (x >> 8 & 0xff00ff) | (x & 0xff00ff) << 8, x = x >> 16 | x << 16)