mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 18:48:13 -07:00
changing {} style to match majority of previous style
This commit is contained in:
parent
da6cdf014b
commit
961d929f4d
320 changed files with 5502 additions and 10485 deletions
|
@ -22,8 +22,7 @@
|
|||
|
||||
#if !defined LOWMEM && defined __GNUC__
|
||||
static uint8_t filterlut[1 << 20];
|
||||
static void __attribute__((constructor)) fill_lut()
|
||||
{
|
||||
static void __attribute__((constructor)) fill_lut() {
|
||||
uint32_t i;
|
||||
for (i = 0; i < 1 << 20; ++i)
|
||||
filterlut[i] = filter(i);
|
||||
|
@ -50,8 +49,7 @@ typedef struct bucket_info {
|
|||
|
||||
static void bucket_sort_intersect(uint32_t *const estart, uint32_t *const estop,
|
||||
uint32_t *const ostart, uint32_t *const ostop,
|
||||
bucket_info_t *bucket_info, bucket_array_t bucket)
|
||||
{
|
||||
bucket_info_t *bucket_info, bucket_array_t bucket) {
|
||||
uint32_t *p1, *p2;
|
||||
uint32_t *start[2];
|
||||
uint32_t *stop[2];
|
||||
|
@ -98,8 +96,7 @@ static void bucket_sort_intersect(uint32_t *const estart, uint32_t *const estop,
|
|||
/** update_contribution
|
||||
* helper, calculates the partial linear feedback contributions and puts in MSB
|
||||
*/
|
||||
static inline void update_contribution(uint32_t *item, const uint32_t mask1, const uint32_t mask2)
|
||||
{
|
||||
static inline void update_contribution(uint32_t *item, const uint32_t mask1, const uint32_t mask2) {
|
||||
uint32_t p = *item >> 25;
|
||||
|
||||
p = p << 1 | parity(*item & mask1);
|
||||
|
@ -110,8 +107,7 @@ static inline void update_contribution(uint32_t *item, const uint32_t mask1, con
|
|||
/** extend_table
|
||||
* using a bit of the keystream extend the table of possible lfsr states
|
||||
*/
|
||||
static inline void extend_table(uint32_t *tbl, uint32_t **end, int bit, int m1, int m2, uint32_t in)
|
||||
{
|
||||
static inline void extend_table(uint32_t *tbl, uint32_t **end, int bit, int m1, int m2, uint32_t in) {
|
||||
in <<= 24;
|
||||
for (*tbl <<= 1; tbl <= *end; *++tbl <<= 1)
|
||||
if (filter(*tbl) ^ filter(*tbl | 1)) {
|
||||
|
@ -131,8 +127,7 @@ static inline void extend_table(uint32_t *tbl, uint32_t **end, int bit, int m1,
|
|||
/** extend_table_simple
|
||||
* using a bit of the keystream extend the table of possible lfsr states
|
||||
*/
|
||||
static inline void extend_table_simple(uint32_t *tbl, uint32_t **end, int bit)
|
||||
{
|
||||
static inline void extend_table_simple(uint32_t *tbl, uint32_t **end, int bit) {
|
||||
for (*tbl <<= 1; tbl <= *end; *++tbl <<= 1) {
|
||||
if (filter(*tbl) ^ filter(*tbl | 1)) { // replace
|
||||
*tbl |= filter(*tbl) ^ bit;
|
||||
|
@ -150,8 +145,7 @@ static inline void extend_table_simple(uint32_t *tbl, uint32_t **end, int bit)
|
|||
static struct Crypto1State *
|
||||
recover(uint32_t *o_head, uint32_t *o_tail, uint32_t oks,
|
||||
uint32_t *e_head, uint32_t *e_tail, uint32_t eks, int rem,
|
||||
struct Crypto1State *sl, uint32_t in, bucket_array_t bucket)
|
||||
{
|
||||
struct Crypto1State *sl, uint32_t in, bucket_array_t bucket) {
|
||||
uint32_t *o, *e;
|
||||
bucket_info_t bucket_info;
|
||||
|
||||
|
@ -195,8 +189,7 @@ recover(uint32_t *o_head, uint32_t *o_tail, uint32_t oks,
|
|||
* additionally you can use the in parameter to specify the value
|
||||
* that was fed into the lfsr at the time the keystream was generated
|
||||
*/
|
||||
struct Crypto1State *lfsr_recovery32(uint32_t ks2, uint32_t in)
|
||||
{
|
||||
struct Crypto1State *lfsr_recovery32(uint32_t ks2, uint32_t in) {
|
||||
struct Crypto1State *statelist;
|
||||
uint32_t *odd_head = 0, *odd_tail = 0, oks = 0;
|
||||
uint32_t *even_head = 0, *even_tail = 0, eks = 0;
|
||||
|
@ -287,8 +280,7 @@ static const uint32_t C2[] = { 0x1A822E0, 0x21A822E0, 0x21A822E0};
|
|||
/** Reverse 64 bits of keystream into possible cipher states
|
||||
* Variation mentioned in the paper. Somewhat optimized version
|
||||
*/
|
||||
struct Crypto1State *lfsr_recovery64(uint32_t ks2, uint32_t ks3)
|
||||
{
|
||||
struct Crypto1State *lfsr_recovery64(uint32_t ks2, uint32_t ks3) {
|
||||
struct Crypto1State *statelist, *sl;
|
||||
uint8_t oks[32], eks[32], hi[32];
|
||||
uint32_t low = 0, win = 0;
|
||||
|
@ -358,8 +350,7 @@ continue2:
|
|||
/** lfsr_rollback_bit
|
||||
* Rollback the shift register in order to get previous states
|
||||
*/
|
||||
uint8_t lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb)
|
||||
{
|
||||
uint8_t lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb) {
|
||||
int out;
|
||||
uint8_t ret;
|
||||
uint32_t t;
|
||||
|
@ -379,8 +370,7 @@ uint8_t lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb)
|
|||
/** lfsr_rollback_byte
|
||||
* Rollback the shift register in order to get previous states
|
||||
*/
|
||||
uint8_t lfsr_rollback_byte(struct Crypto1State *s, uint32_t in, int fb)
|
||||
{
|
||||
uint8_t lfsr_rollback_byte(struct Crypto1State *s, uint32_t in, int fb) {
|
||||
/*
|
||||
int i, ret = 0;
|
||||
for (i = 7; i >= 0; --i)
|
||||
|
@ -401,8 +391,7 @@ uint8_t lfsr_rollback_byte(struct Crypto1State *s, uint32_t in, int fb)
|
|||
/** lfsr_rollback_word
|
||||
* Rollback the shift register in order to get previous states
|
||||
*/
|
||||
uint32_t lfsr_rollback_word(struct Crypto1State *s, uint32_t in, int fb)
|
||||
{
|
||||
uint32_t lfsr_rollback_word(struct Crypto1State *s, uint32_t in, int fb) {
|
||||
/*
|
||||
int i;
|
||||
uint32_t ret = 0;
|
||||
|
@ -453,8 +442,7 @@ uint32_t lfsr_rollback_word(struct Crypto1State *s, uint32_t in, int fb)
|
|||
* x,y valid tag nonces, then prng_successor(x, nonce_distance(x, y)) = y
|
||||
*/
|
||||
static uint16_t *dist = 0;
|
||||
int nonce_distance(uint32_t from, uint32_t to)
|
||||
{
|
||||
int nonce_distance(uint32_t from, uint32_t to) {
|
||||
uint16_t x, i;
|
||||
if (!dist) {
|
||||
dist = malloc(2 << 16);
|
||||
|
@ -484,8 +472,7 @@ static uint32_t fastfwd[2][8] = {
|
|||
* encrypt the NACK which is observed when varying only the 3 last bits of Nr
|
||||
* only correct iff [NR_3] ^ NR_3 does not depend on Nr_3
|
||||
*/
|
||||
uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd)
|
||||
{
|
||||
uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd) {
|
||||
uint32_t *candidates = malloc(4 << 10);
|
||||
if (!candidates) return 0;
|
||||
|
||||
|
@ -510,8 +497,7 @@ uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd)
|
|||
/** check_pfx_parity
|
||||
* helper function which eliminates possible secret states using parity bits
|
||||
*/
|
||||
static struct Crypto1State *check_pfx_parity(uint32_t prefix, uint32_t rresp, uint8_t parities[8][8], uint32_t odd, uint32_t even, struct Crypto1State *sl)
|
||||
{
|
||||
static struct Crypto1State *check_pfx_parity(uint32_t prefix, uint32_t rresp, uint8_t parities[8][8], uint32_t odd, uint32_t even, struct Crypto1State *sl) {
|
||||
uint32_t ks1, nr, ks2, rr, ks3, c, good = 1;
|
||||
|
||||
for (c = 0; good && c < 8; ++c) {
|
||||
|
@ -548,8 +534,7 @@ static struct Crypto1State *check_pfx_parity(uint32_t prefix, uint32_t rresp, ui
|
|||
* tag nonce was fed in
|
||||
*/
|
||||
|
||||
struct Crypto1State *lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8])
|
||||
{
|
||||
struct Crypto1State *lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]) {
|
||||
struct Crypto1State *statelist, *s;
|
||||
uint32_t *odd, *even, *o, *e, top;
|
||||
|
||||
|
|
|
@ -60,8 +60,7 @@ int nonce_distance(uint32_t from, uint32_t to);
|
|||
#define LF_POLY_EVEN (0x870804)
|
||||
#define BIT(x, n) ((x) >> (n) & 1)
|
||||
#define BEBIT(x, n) BIT(x, (n) ^ 24)
|
||||
static inline int parity(uint32_t x)
|
||||
{
|
||||
static inline int parity(uint32_t x) {
|
||||
#if !defined __i386__ || !defined __GNUC__
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
|
@ -78,8 +77,7 @@ static inline int parity(uint32_t x)
|
|||
return x;
|
||||
#endif
|
||||
}
|
||||
static inline int filter(uint32_t const x)
|
||||
{
|
||||
static inline int filter(uint32_t const x) {
|
||||
uint32_t f;
|
||||
|
||||
f = 0xf22c0 >> (x & 0xf) & 16;
|
||||
|
|
|
@ -20,8 +20,7 @@
|
|||
#include "crapto1.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
struct Crypto1State *crypto1_create(uint64_t key)
|
||||
{
|
||||
struct Crypto1State *crypto1_create(uint64_t key) {
|
||||
struct Crypto1State *s = malloc(sizeof(*s));
|
||||
if (!s) return NULL;
|
||||
|
||||
|
@ -35,20 +34,17 @@ struct Crypto1State *crypto1_create(uint64_t key)
|
|||
}
|
||||
return s;
|
||||
}
|
||||
void crypto1_destroy(struct Crypto1State *state)
|
||||
{
|
||||
void crypto1_destroy(struct Crypto1State *state) {
|
||||
free(state);
|
||||
}
|
||||
void crypto1_get_lfsr(struct Crypto1State *state, uint64_t *lfsr)
|
||||
{
|
||||
void crypto1_get_lfsr(struct Crypto1State *state, uint64_t *lfsr) {
|
||||
int i;
|
||||
for (*lfsr = 0, i = 23; i >= 0; --i) {
|
||||
*lfsr = *lfsr << 1 | BIT(state->odd, i ^ 3);
|
||||
*lfsr = *lfsr << 1 | BIT(state->even, i ^ 3);
|
||||
}
|
||||
}
|
||||
uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted)
|
||||
{
|
||||
uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted) {
|
||||
uint32_t feedin;
|
||||
uint32_t tmp;
|
||||
uint8_t ret = filter(s->odd);
|
||||
|
@ -65,8 +61,7 @@ uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted)
|
|||
|
||||
return ret;
|
||||
}
|
||||
uint8_t crypto1_byte(struct Crypto1State *s, uint8_t in, int is_encrypted)
|
||||
{
|
||||
uint8_t crypto1_byte(struct Crypto1State *s, uint8_t in, int is_encrypted) {
|
||||
/*
|
||||
uint8_t i, ret = 0;
|
||||
|
||||
|
@ -85,8 +80,7 @@ uint8_t crypto1_byte(struct Crypto1State *s, uint8_t in, int is_encrypted)
|
|||
ret |= crypto1_bit(s, BIT(in, 7), is_encrypted) << 7;
|
||||
return ret;
|
||||
}
|
||||
uint32_t crypto1_word(struct Crypto1State *s, uint32_t in, int is_encrypted)
|
||||
{
|
||||
uint32_t crypto1_word(struct Crypto1State *s, uint32_t in, int is_encrypted) {
|
||||
/*
|
||||
uint32_t i, ret = 0;
|
||||
|
||||
|
@ -136,8 +130,7 @@ uint32_t crypto1_word(struct Crypto1State *s, uint32_t in, int is_encrypted)
|
|||
/* prng_successor
|
||||
* helper used to obscure the keystream during authentication
|
||||
*/
|
||||
uint32_t prng_successor(uint32_t x, uint32_t n)
|
||||
{
|
||||
uint32_t prng_successor(uint32_t x, uint32_t n) {
|
||||
SWAPENDIAN(x);
|
||||
while (n--)
|
||||
x = x >> 1 | (x >> 16 ^ x >> 18 ^ x >> 19 ^ x >> 21) << 31;
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(const int argc, const char *argv[])
|
||||
{
|
||||
int main(const int argc, const char *argv[]) {
|
||||
struct Crypto1State *state;
|
||||
uint32_t pos, uid, nt, nr, rr, nr_diff;
|
||||
uint8_t bt, i, ks3x[8], par[8][8];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue