mirror of
				https://github.com/Proxmark/proxmark3.git
				synced 2025-10-25 21:46:59 +08:00 
			
		
		
		
	Merge remote-tracking branch 'upstream/master'
This commit is contained in:
		
						commit
						df51693f95
					
				
					 6 changed files with 122 additions and 101 deletions
				
			
		|  | @ -1,21 +1,21 @@ | |||
| /*  crapto1.c
 | ||||
| 
 | ||||
|     This program is free software; you can redistribute it and/or | ||||
|     modify it under the terms of the GNU General Public License | ||||
|     as published by the Free Software Foundation; either version 2 | ||||
|     of the License, or (at your option) any later version. | ||||
| 	This program is free software; you can redistribute it and/or | ||||
| 	modify it under the terms of the GNU General Public License | ||||
| 	as published by the Free Software Foundation; either version 2 | ||||
| 	of the License, or (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 	This program is distributed in the hope that it will be useful, | ||||
| 	but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| 	GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program; if not, write to the Free Software | ||||
|     Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
|     Boston, MA  02110-1301, US$ | ||||
| 	You should have received a copy of the GNU General Public License | ||||
| 	along with this program; if not, write to the Free Software | ||||
| 	Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
| 	Boston, MA  02110-1301, US$ | ||||
| 
 | ||||
|     Copyright (C) 2008-2008 bla <blapost@gmail.com> | ||||
| 	Copyright (C) 2008-2008 bla <blapost@gmail.com> | ||||
| */ | ||||
| #include "crapto1.h" | ||||
| #include <stdlib.h> | ||||
|  | @ -24,9 +24,9 @@ | |||
| static uint8_t filterlut[1 << 20]; | ||||
| static void __attribute__((constructor)) fill_lut() | ||||
| { | ||||
|         uint32_t i; | ||||
|         for(i = 0; i < 1 << 20; ++i) | ||||
|                 filterlut[i] = filter(i); | ||||
| 	uint32_t i; | ||||
| 	for(i = 0; i < 1 << 20; ++i) | ||||
| 		filterlut[i] = filter(i); | ||||
| } | ||||
| #define filter(x) (filterlut[(x) & 0xfffff]) | ||||
| #endif | ||||
|  | @ -34,6 +34,7 @@ static void __attribute__((constructor)) fill_lut() | |||
| static void quicksort(uint32_t* const start, uint32_t* const stop) | ||||
| { | ||||
| 	uint32_t *it = start + 1, *rit = stop; | ||||
| 	uint32_t tmp; | ||||
| 
 | ||||
| 	if(it > rit) | ||||
| 		return; | ||||
|  | @ -43,13 +44,19 @@ static void quicksort(uint32_t* const start, uint32_t* const stop) | |||
| 			++it; | ||||
| 		else if(*rit > *start) | ||||
| 			--rit; | ||||
| 		else | ||||
| 			*it ^= (*it ^= *rit, *rit ^= *it); | ||||
| 		else { | ||||
| 			tmp = *it; | ||||
| 			*it = *rit; | ||||
| 			*rit = tmp; | ||||
| 		} | ||||
| 
 | ||||
| 	if(*rit >= *start) | ||||
| 		--rit; | ||||
| 	if(rit != start) | ||||
| 		*rit ^= (*rit ^= *start, *start ^= *rit); | ||||
| 	if(rit != start) { | ||||
| 		tmp = *rit; | ||||
| 		*rit = *start; | ||||
| 		*start = tmp; | ||||
| 	} | ||||
| 
 | ||||
| 	quicksort(start, rit - 1); | ||||
| 	quicksort(rit + 1, stop); | ||||
|  | @ -145,12 +152,12 @@ recover(uint32_t *o_head, uint32_t *o_tail, uint32_t oks, | |||
| 		eks >>= 1; | ||||
| 		in >>= 2; | ||||
| 		extend_table(o_head, &o_tail, oks & 1, LF_POLY_EVEN << 1 | 1, | ||||
| 			     LF_POLY_ODD << 1, 0); | ||||
| 				 LF_POLY_ODD << 1, 0); | ||||
| 		if(o_head > o_tail) | ||||
| 			return sl; | ||||
| 
 | ||||
| 		extend_table(e_head, &e_tail, eks & 1, LF_POLY_ODD, | ||||
| 			     LF_POLY_EVEN << 1 | 1, in & 3); | ||||
| 				 LF_POLY_EVEN << 1 | 1, in & 3); | ||||
| 		if(e_head > e_tail) | ||||
| 			return sl; | ||||
| 	} | ||||
|  | @ -163,7 +170,7 @@ recover(uint32_t *o_head, uint32_t *o_tail, uint32_t oks, | |||
| 			o_tail = binsearch(o_head, o = o_tail); | ||||
| 			e_tail = binsearch(e_head, e = e_tail); | ||||
| 			sl = recover(o_tail--, o, oks, | ||||
| 				     e_tail--, e, eks, rem, sl, in); | ||||
| 					 e_tail--, e, eks, rem, sl, in); | ||||
| 		} | ||||
| 		else if(*o_tail > *e_tail) | ||||
| 			o_tail = binsearch(o_head, o_tail) - 1; | ||||
|  | @ -319,9 +326,12 @@ uint8_t lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb) | |||
| { | ||||
| 	int out; | ||||
| 	uint8_t ret; | ||||
| 	uint32_t tmp; | ||||
| 
 | ||||
| 	s->odd &= 0xffffff; | ||||
| 	s->odd ^= (s->odd ^= s->even, s->even ^= s->odd); | ||||
| 	tmp = s->odd; | ||||
| 	s->odd = s->even; | ||||
| 	s->even = tmp; | ||||
| 
 | ||||
| 	out = s->even & 1; | ||||
| 	out ^= LF_POLY_EVEN & (s->even >>= 1); | ||||
|  | @ -414,7 +424,7 @@ uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd) | |||
|  */ | ||||
| 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 odd, uint32_t even, struct Crypto1State* sl) | ||||
| { | ||||
| 	uint32_t ks1, nr, ks2, rr, ks3, c, good = 1; | ||||
| 
 | ||||
|  | @ -440,7 +450,7 @@ check_pfx_parity(uint32_t prefix, uint32_t rresp, uint8_t parities[8][8], | |||
| 	} | ||||
| 
 | ||||
| 	return sl + good; | ||||
| }  | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| /** lfsr_common_prefix
 | ||||
|  | @ -459,7 +469,7 @@ lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8]) | |||
| 	if(!s || !odd || !even) { | ||||
| 		free(statelist); | ||||
| 		statelist = 0; | ||||
|                 goto out; | ||||
| 		goto out; | ||||
| 	} | ||||
| 
 | ||||
| 	for(o = odd; *o + 1; ++o) | ||||
|  |  | |||
|  | @ -1,21 +1,21 @@ | |||
| /*  crypto1.c
 | ||||
| 
 | ||||
|     This program is free software; you can redistribute it and/or | ||||
|     modify it under the terms of the GNU General Public License | ||||
|     as published by the Free Software Foundation; either version 2 | ||||
|     of the License, or (at your option) any later version. | ||||
| 	This program is free software; you can redistribute it and/or | ||||
| 	modify it under the terms of the GNU General Public License | ||||
| 	as published by the Free Software Foundation; either version 2 | ||||
| 	of the License, or (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 	This program is distributed in the hope that it will be useful, | ||||
| 	but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| 	GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program; if not, write to the Free Software | ||||
|     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||||
|     MA  02110-1301, US | ||||
| 	You should have received a copy of the GNU General Public License | ||||
| 	along with this program; if not, write to the Free Software | ||||
| 	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||||
| 	MA  02110-1301, US | ||||
| 
 | ||||
|     Copyright (C) 2008-2008 bla <blapost@gmail.com> | ||||
| 	Copyright (C) 2008-2008 bla <blapost@gmail.com> | ||||
| */ | ||||
| #include "crapto1.h" | ||||
| #include <stdlib.h> | ||||
|  | @ -37,8 +37,8 @@ void crypto1_create(struct Crypto1State *s, uint64_t key) | |||
| void crypto1_destroy(struct Crypto1State *state) | ||||
| { | ||||
| //	free(state);
 | ||||
|   state->odd = 0; | ||||
|   state->even = 0; | ||||
| 	state->odd = 0; | ||||
| 	state->even = 0; | ||||
| } | ||||
| void crypto1_get_lfsr(struct Crypto1State *state, uint64_t *lfsr) | ||||
| { | ||||
|  | @ -51,6 +51,7 @@ void crypto1_get_lfsr(struct Crypto1State *state, uint64_t *lfsr) | |||
| 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); | ||||
| 
 | ||||
| 	feedin  = ret & !!is_encrypted; | ||||
|  | @ -59,7 +60,9 @@ uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted) | |||
| 	feedin ^= LF_POLY_EVEN & s->even; | ||||
| 	s->even = s->even << 1 | parity(feedin); | ||||
| 
 | ||||
| 	s->odd ^= (s->odd ^= s->even, s->even ^= s->odd); | ||||
| 	tmp = s->odd; | ||||
| 	s->odd = s->even; | ||||
| 	s->even = tmp; | ||||
| 
 | ||||
| 	return ret; | ||||
| } | ||||
|  |  | |||
|  | @ -1,21 +1,21 @@ | |||
| /*  crapto1.c
 | ||||
| 
 | ||||
|     This program is free software; you can redistribute it and/or | ||||
|     modify it under the terms of the GNU General Public License | ||||
|     as published by the Free Software Foundation; either version 2 | ||||
|     of the License, or (at your option) any later version. | ||||
| 	This program is free software; you can redistribute it and/or | ||||
| 	modify it under the terms of the GNU General Public License | ||||
| 	as published by the Free Software Foundation; either version 2 | ||||
| 	of the License, or (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 	This program is distributed in the hope that it will be useful, | ||||
| 	but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| 	GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program; if not, write to the Free Software | ||||
|     Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
|     Boston, MA  02110-1301, US$ | ||||
| 	You should have received a copy of the GNU General Public License | ||||
| 	along with this program; if not, write to the Free Software | ||||
| 	Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
| 	Boston, MA  02110-1301, US$ | ||||
| 
 | ||||
|     Copyright (C) 2008-2008 bla <blapost@gmail.com> | ||||
| 	Copyright (C) 2008-2008 bla <blapost@gmail.com> | ||||
| */ | ||||
| #include "crapto1.h" | ||||
| #include <stdlib.h> | ||||
|  | @ -24,9 +24,9 @@ | |||
| static uint8_t filterlut[1 << 20]; | ||||
| static void __attribute__((constructor)) fill_lut() | ||||
| { | ||||
|         uint32_t i; | ||||
|         for(i = 0; i < 1 << 20; ++i) | ||||
|                 filterlut[i] = filter(i); | ||||
| 		uint32_t i; | ||||
| 		for(i = 0; i < 1 << 20; ++i) | ||||
| 				filterlut[i] = filter(i); | ||||
| } | ||||
| #define filter(x) (filterlut[(x) & 0xfffff]) | ||||
| #endif | ||||
|  | @ -46,7 +46,7 @@ typedef struct bucket_info { | |||
| 		} bucket_info[2][0x100]; | ||||
| 		uint32_t numbuckets; | ||||
| 	} bucket_info_t; | ||||
| 	 | ||||
| 
 | ||||
| 
 | ||||
| static void bucket_sort_intersect(uint32_t* const estart, uint32_t* const estop, | ||||
| 								  uint32_t* const ostart, uint32_t* const ostop, | ||||
|  | @ -55,28 +55,28 @@ static void bucket_sort_intersect(uint32_t* const estart, uint32_t* const estop, | |||
| 	uint32_t *p1, *p2; | ||||
| 	uint32_t *start[2]; | ||||
| 	uint32_t *stop[2]; | ||||
| 	 | ||||
| 
 | ||||
| 	start[0] = estart; | ||||
| 	stop[0] = estop; | ||||
| 	start[1] = ostart; | ||||
| 	stop[1] = ostop; | ||||
| 	 | ||||
| 
 | ||||
| 	// init buckets to be empty
 | ||||
| 	for (uint32_t i = 0; i < 2; i++) { | ||||
| 		for (uint32_t j = 0x00; j <= 0xff; j++) { | ||||
| 			bucket[i][j].bp = bucket[i][j].head; | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 
 | ||||
| 	// sort the lists into the buckets based on the MSB (contribution bits)
 | ||||
| 	for (uint32_t i = 0; i < 2; i++) {  | ||||
| 	for (uint32_t i = 0; i < 2; i++) { | ||||
| 		for (p1 = start[i]; p1 <= stop[i]; p1++) { | ||||
| 			uint32_t bucket_index = (*p1 & 0xff000000) >> 24; | ||||
| 			*(bucket[i][bucket_index].bp++) = *p1; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	 | ||||
| 
 | ||||
| 	// write back intersecting buckets as sorted list.
 | ||||
| 	// fill in bucket_info with head and tail of the bucket contents in the list and number of non-empty buckets.
 | ||||
| 	uint32_t nonempty_bucket; | ||||
|  | @ -147,9 +147,9 @@ extend_table(uint32_t *tbl, uint32_t **end, int bit, int m1, int m2, uint32_t in | |||
| 			*p ^= in; | ||||
| 		} else {										// drop
 | ||||
| 			*p-- = *(*end)--; | ||||
| 		}  | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | @ -159,7 +159,7 @@ extend_table(uint32_t *tbl, uint32_t **end, int bit, int m1, int m2, uint32_t in | |||
| static inline void | ||||
| extend_table_simple(uint32_t *tbl, uint32_t **end, int bit) | ||||
| { | ||||
| 	for(*tbl <<= 1; tbl <= *end; *++tbl <<= 1)	 | ||||
| 	for(*tbl <<= 1; tbl <= *end; *++tbl <<= 1) | ||||
| 		if(filter(*tbl) ^ filter(*tbl | 1)) {	// replace
 | ||||
| 			*tbl |= filter(*tbl) ^ bit; | ||||
| 		} else if(filter(*tbl) == bit) {		// insert
 | ||||
|  | @ -206,13 +206,13 @@ recover(uint32_t *o_head, uint32_t *o_tail, uint32_t oks, | |||
| 	} | ||||
| 
 | ||||
| 	bucket_sort_intersect(e_head, e_tail, o_head, o_tail, &bucket_info, bucket); | ||||
| 	 | ||||
| 
 | ||||
| 	for (int i = bucket_info.numbuckets - 1; i >= 0; i--) { | ||||
| 		sl = recover(bucket_info.bucket_info[1][i].head, bucket_info.bucket_info[1][i].tail, oks, | ||||
| 				     bucket_info.bucket_info[0][i].head, bucket_info.bucket_info[0][i].tail, eks, | ||||
| 					 bucket_info.bucket_info[0][i].head, bucket_info.bucket_info[0][i].tail, eks, | ||||
| 					 rem, sl, in, bucket); | ||||
| 	} | ||||
| 	 | ||||
| 
 | ||||
| 	return sl; | ||||
| } | ||||
| /** lfsr_recovery
 | ||||
|  | @ -251,7 +251,7 @@ struct Crypto1State* lfsr_recovery32(uint32_t ks2, uint32_t in) | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 	 | ||||
| 
 | ||||
| 	// initialize statelists: add all possible states which would result into the rightmost 2 bits of the keystream
 | ||||
| 	for(i = 1 << 20; i >= 0; --i) { | ||||
| 		if(filter(i) == (oks & 1)) | ||||
|  | @ -282,7 +282,7 @@ out: | |||
| 	for (uint32_t i = 0; i < 2; i++) | ||||
| 		for (uint32_t j = 0; j <= 0xff; j++) | ||||
| 			free(bucket[i][j].head); | ||||
| 	 | ||||
| 
 | ||||
| 	return statelist; | ||||
| } | ||||
| 
 | ||||
|  | @ -382,9 +382,12 @@ struct Crypto1State* lfsr_recovery64(uint32_t ks2, uint32_t ks3) | |||
| void lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb) | ||||
| { | ||||
| 	int out; | ||||
| 	uint32_t tmp; | ||||
| 
 | ||||
| 	s->odd &= 0xffffff; | ||||
| 	s->odd ^= (s->odd ^= s->even, s->even ^= s->odd); | ||||
| 	tmp = s->odd; | ||||
| 	s->odd = s->even; | ||||
| 	s->even = tmp; | ||||
| 
 | ||||
| 	out = s->even & 1; | ||||
| 	out ^= LF_POLY_EVEN & (s->even >>= 1); | ||||
|  | @ -481,7 +484,7 @@ uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd) | |||
|  */ | ||||
| static struct Crypto1State* | ||||
| brute_top(uint32_t prefix, uint32_t rresp, unsigned char parities[8][8], | ||||
|           uint32_t odd, uint32_t even, struct Crypto1State* sl, uint8_t no_chk) | ||||
| 		  uint32_t odd, uint32_t even, struct Crypto1State* sl, uint8_t no_chk) | ||||
| { | ||||
| 	struct Crypto1State s; | ||||
| 	uint32_t ks1, nr, ks2, rr, ks3, good, c; | ||||
|  | @ -489,20 +492,20 @@ brute_top(uint32_t prefix, uint32_t rresp, unsigned char parities[8][8], | |||
| 	for(c = 0; c < 8; ++c) { | ||||
| 		s.odd = odd ^ fastfwd[1][c]; | ||||
| 		s.even = even ^ fastfwd[0][c]; | ||||
| 		 | ||||
| 
 | ||||
| 		lfsr_rollback_bit(&s, 0, 0); | ||||
| 		lfsr_rollback_bit(&s, 0, 0); | ||||
| 		lfsr_rollback_bit(&s, 0, 0); | ||||
| 		 | ||||
| 
 | ||||
| 		lfsr_rollback_word(&s, 0, 0); | ||||
| 		lfsr_rollback_word(&s, prefix | c << 5, 1); | ||||
| 		 | ||||
| 
 | ||||
| 		sl->odd = s.odd; | ||||
| 		sl->even = s.even; | ||||
| 		 | ||||
| 
 | ||||
| 		if (no_chk) | ||||
| 			break; | ||||
| 	 | ||||
| 
 | ||||
| 		ks1 = crypto1_word(&s, prefix | c << 5, 1); | ||||
| 		ks2 = crypto1_word(&s,0,0); | ||||
| 		ks3 = crypto1_word(&s, 0,0); | ||||
|  | @ -521,7 +524,7 @@ brute_top(uint32_t prefix, uint32_t rresp, unsigned char parities[8][8], | |||
| 	} | ||||
| 
 | ||||
| 	return ++sl; | ||||
| }  | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| /** lfsr_common_prefix
 | ||||
|  | @ -542,13 +545,13 @@ lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8], | |||
| 	odd = lfsr_prefix_ks(ks, 1); | ||||
| 	even = lfsr_prefix_ks(ks, 0); | ||||
| 
 | ||||
| 	statelist = malloc((sizeof *statelist) << 21);	//how large should be? 
 | ||||
| 	statelist = malloc((sizeof *statelist) << 21);	//how large should be?
 | ||||
| 	if(!statelist || !odd || !even) | ||||
| 	{ | ||||
| 				free(statelist); | ||||
| 				free(odd); | ||||
| 				free(even); | ||||
|                 return 0; | ||||
| 				return 0; | ||||
| 	} | ||||
| 
 | ||||
| 	s = statelist; | ||||
|  | @ -560,7 +563,7 @@ lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8], | |||
| 				s = brute_top(pfx, rr, par, *o, *e, s, no_par); | ||||
| 			} | ||||
| 
 | ||||
| 	s->odd = s->even = -1;	 | ||||
| 	s->odd = s->even = -1; | ||||
| 	//printf("state count = %d\n",s-statelist);
 | ||||
| 
 | ||||
| 	free(odd); | ||||
|  |  | |||
|  | @ -1,21 +1,21 @@ | |||
| /*  crypto1.c
 | ||||
| 
 | ||||
|     This program is free software; you can redistribute it and/or | ||||
|     modify it under the terms of the GNU General Public License | ||||
|     as published by the Free Software Foundation; either version 2 | ||||
|     of the License, or (at your option) any later version. | ||||
| 	This program is free software; you can redistribute it and/or | ||||
| 	modify it under the terms of the GNU General Public License | ||||
| 	as published by the Free Software Foundation; either version 2 | ||||
| 	of the License, or (at your option) any later version. | ||||
| 
 | ||||
|     This program is distributed in the hope that it will be useful, | ||||
|     but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|     GNU General Public License for more details. | ||||
| 	This program is distributed in the hope that it will be useful, | ||||
| 	but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| 	GNU General Public License for more details. | ||||
| 
 | ||||
|     You should have received a copy of the GNU General Public License | ||||
|     along with this program; if not, write to the Free Software | ||||
|     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||||
|     MA  02110-1301, US | ||||
| 	You should have received a copy of the GNU General Public License | ||||
| 	along with this program; if not, write to the Free Software | ||||
| 	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||||
| 	MA  02110-1301, US | ||||
| 
 | ||||
|     Copyright (C) 2008-2008 bla <blapost@gmail.com> | ||||
| 	Copyright (C) 2008-2008 bla <blapost@gmail.com> | ||||
| */ | ||||
| #include "crapto1.h" | ||||
| #include <stdlib.h> | ||||
|  | @ -49,6 +49,7 @@ void crypto1_get_lfsr(struct Crypto1State *state, uint64_t *lfsr) | |||
| 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); | ||||
| 
 | ||||
| 	feedin  = ret & !!is_encrypted; | ||||
|  | @ -57,7 +58,9 @@ uint8_t crypto1_bit(struct Crypto1State *s, uint8_t in, int is_encrypted) | |||
| 	feedin ^= LF_POLY_EVEN & s->even; | ||||
| 	s->even = s->even << 1 | parity(feedin); | ||||
| 
 | ||||
| 	s->odd ^= (s->odd ^= s->even, s->even ^= s->odd); | ||||
| 	tmp = s->odd; | ||||
| 	s->odd = s->even; | ||||
| 	s->even = tmp; | ||||
| 
 | ||||
| 	return ret; | ||||
| } | ||||
|  |  | |||
							
								
								
									
										
											BIN
										
									
								
								fpga/fpga_lf.bit
									
										
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								fpga/fpga_lf.bit
									
										
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							|  | @ -35,10 +35,12 @@ wire tag_modulation = ssp_dout & !lf_field; | |||
| wire reader_modulation = !ssp_dout & lf_field & pck_divclk; | ||||
| 
 | ||||
| // No logic, straight through. | ||||
| assign pwr_oe1 = 1'b0; // not used in LF mode | ||||
| assign pwr_oe1 = 1'b0; 						// not used in LF mode  | ||||
| assign pwr_oe3 = 1'b0; 						// base antenna load = 33 Ohms | ||||
| // when modulating, add another 33 Ohms and 10k Ohms in parallel: | ||||
| assign pwr_oe2 = tag_modulation; | ||||
| assign pwr_oe3 = tag_modulation; | ||||
| assign pwr_oe4 = tag_modulation; | ||||
| assign pwr_oe4 = tag_modulation;  | ||||
| 
 | ||||
| assign ssp_clk = cross_lo; | ||||
| assign pwr_lo = reader_modulation; | ||||
| assign pwr_hi = 1'b0; | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue