mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 22:03:42 -07:00
style
This commit is contained in:
parent
111af2bacb
commit
b485461fba
10 changed files with 121 additions and 167 deletions
|
@ -229,8 +229,7 @@ static uint32_t hitag2_crypt(uint64_t x);
|
||||||
((S >> (C - 3)) & 8) )
|
((S >> (C - 3)) & 8) )
|
||||||
|
|
||||||
|
|
||||||
static uint32_t hitag2_crypt(uint64_t s)
|
static uint32_t hitag2_crypt(uint64_t s) {
|
||||||
{
|
|
||||||
const uint32_t ht2_function4a = 0x2C79; // 0010 1100 0111 1001
|
const uint32_t ht2_function4a = 0x2C79; // 0010 1100 0111 1001
|
||||||
const uint32_t ht2_function4b = 0x6671; // 0110 0110 0111 0001
|
const uint32_t ht2_function4b = 0x6671; // 0110 0110 0111 0001
|
||||||
const uint32_t ht2_function5c = 0x7907287B; // 0111 1001 0000 0111 0010 1000 0111 1011
|
const uint32_t ht2_function5c = 0x7907287B; // 0111 1001 0000 0111 0010 1000 0111 1011
|
||||||
|
@ -253,8 +252,7 @@ static uint32_t hitag2_crypt(uint64_t s)
|
||||||
* uint32_t serialnum - 32 bit tag serial number
|
* uint32_t serialnum - 32 bit tag serial number
|
||||||
* uint32_t initvector - 32 bit random IV from reader, part of tag authentication
|
* uint32_t initvector - 32 bit random IV from reader, part of tag authentication
|
||||||
*/
|
*/
|
||||||
void hitag2_init(Hitag_State* pstate, uint64_t sharedkey, uint32_t serialnum, uint32_t initvector)
|
void hitag2_init(Hitag_State *pstate, uint64_t sharedkey, uint32_t serialnum, uint32_t initvector) {
|
||||||
{
|
|
||||||
// init state, from serial number and lowest 16 bits of shared key
|
// init state, from serial number and lowest 16 bits of shared key
|
||||||
uint64_t state = ((sharedkey & 0xFFFF) << 32) | serialnum;
|
uint64_t state = ((sharedkey & 0xFFFF) << 32) | serialnum;
|
||||||
|
|
||||||
|
@ -338,8 +336,7 @@ void hitag2_init(Hitag_State* pstate, uint64_t sharedkey, uint32_t serialnum, ui
|
||||||
* Hitag_State* pstate - in/out, internal cipher state after initialisation
|
* Hitag_State* pstate - in/out, internal cipher state after initialisation
|
||||||
* uint32_t steps - number of bits requested, (capped at 32)
|
* uint32_t steps - number of bits requested, (capped at 32)
|
||||||
*/
|
*/
|
||||||
uint32_t hitag2_nstep(Hitag_State* pstate, uint32_t steps)
|
uint32_t hitag2_nstep(Hitag_State *pstate, uint32_t steps) {
|
||||||
{
|
|
||||||
uint64_t state = pstate->shiftreg;
|
uint64_t state = pstate->shiftreg;
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
uint64_t lfsr = pstate->lfsr;
|
uint64_t lfsr = pstate->lfsr;
|
||||||
|
@ -471,8 +468,7 @@ unsigned hitag2_verifytest()
|
||||||
|
|
||||||
#ifdef UNIT_TEST
|
#ifdef UNIT_TEST
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char *argv[]) {
|
||||||
{
|
|
||||||
unsigned pass = hitag2_verifytest();
|
unsigned pass = hitag2_verifytest();
|
||||||
|
|
||||||
printf("Crypto Verify test = %s\n\n", pass ? "PASS" : "FAIL");
|
printf("Crypto Verify test = %s\n\n", pass ? "PASS" : "FAIL");
|
||||||
|
|
|
@ -53,8 +53,7 @@ uint64_t d2[48];
|
||||||
int nsteps2;
|
int nsteps2;
|
||||||
|
|
||||||
// create table entry
|
// create table entry
|
||||||
void create_table(struct table *t, int d1, int d2)
|
void create_table(struct table *t, int d1, int d2) {
|
||||||
{
|
|
||||||
if (!t) {
|
if (!t) {
|
||||||
printf("create_table: t is NULL\n");
|
printf("create_table: t is NULL\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -83,8 +82,7 @@ void create_table(struct table *t, int d1, int d2)
|
||||||
|
|
||||||
|
|
||||||
// create all table entries
|
// create all table entries
|
||||||
void create_tables(struct table *t)
|
void create_tables(struct table *t) {
|
||||||
{
|
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
if (!t) {
|
if (!t) {
|
||||||
|
@ -101,8 +99,7 @@ void create_tables(struct table *t)
|
||||||
|
|
||||||
|
|
||||||
// free the table memory
|
// free the table memory
|
||||||
void free_tables(struct table *t)
|
void free_tables(struct table *t) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
struct table *ttmp;
|
struct table *ttmp;
|
||||||
|
|
||||||
|
@ -120,8 +117,7 @@ void free_tables(struct table *t)
|
||||||
|
|
||||||
|
|
||||||
// write (partial) table to file
|
// write (partial) table to file
|
||||||
void writetable(struct table *t1)
|
void writetable(struct table *t1) {
|
||||||
{
|
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (debug) printf("writetable %s\n", t1->path);
|
if (debug) printf("writetable %s\n", t1->path);
|
||||||
|
@ -146,8 +142,7 @@ void writetable(struct table *t1)
|
||||||
|
|
||||||
|
|
||||||
// store value in table
|
// store value in table
|
||||||
void store(unsigned char *data)
|
void store(unsigned char *data) {
|
||||||
{
|
|
||||||
unsigned char d1, d2;
|
unsigned char d1, d2;
|
||||||
int offset;
|
int offset;
|
||||||
struct table *t1;
|
struct table *t1;
|
||||||
|
@ -199,8 +194,7 @@ void store(unsigned char *data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writes the ks (keystream) and s (state)
|
// writes the ks (keystream) and s (state)
|
||||||
void write_ks_s(uint32_t ks1, uint32_t ks2, uint64_t shiftreg)
|
void write_ks_s(uint32_t ks1, uint32_t ks2, uint64_t shiftreg) {
|
||||||
{
|
|
||||||
unsigned char buf[16];
|
unsigned char buf[16];
|
||||||
|
|
||||||
// create buffer
|
// create buffer
|
||||||
|
@ -215,8 +209,7 @@ void write_ks_s(uint32_t ks1, uint32_t ks2, uint64_t shiftreg)
|
||||||
|
|
||||||
|
|
||||||
// builds the di table for jumping
|
// builds the di table for jumping
|
||||||
void builddi(int steps, int table)
|
void builddi(int steps, int table) {
|
||||||
{
|
|
||||||
uint64_t statemask;
|
uint64_t statemask;
|
||||||
int i;
|
int i;
|
||||||
Hitag_State mystate;
|
Hitag_State mystate;
|
||||||
|
@ -248,8 +241,7 @@ void builddi(int steps, int table)
|
||||||
}
|
}
|
||||||
|
|
||||||
// jump function - quickly jumps a load of steps
|
// jump function - quickly jumps a load of steps
|
||||||
void jumpnsteps(Hitag_State *hstate, int table)
|
void jumpnsteps(Hitag_State *hstate, int table) {
|
||||||
{
|
|
||||||
uint64_t output = 0;
|
uint64_t output = 0;
|
||||||
uint64_t bitmask;
|
uint64_t bitmask;
|
||||||
int i;
|
int i;
|
||||||
|
@ -285,8 +277,7 @@ void jumpnsteps(Hitag_State *hstate, int table)
|
||||||
|
|
||||||
|
|
||||||
// thread to build a part of the table
|
// thread to build a part of the table
|
||||||
void *buildtable(void *d)
|
void *buildtable(void *d) {
|
||||||
{
|
|
||||||
Hitag_State hstate;
|
Hitag_State hstate;
|
||||||
Hitag_State hstate2;
|
Hitag_State hstate2;
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
|
@ -343,8 +334,7 @@ void *buildtable(void *d)
|
||||||
|
|
||||||
|
|
||||||
// make 'table/' (unsorted) and 'sorted/' dir structures
|
// make 'table/' (unsorted) and 'sorted/' dir structures
|
||||||
void makedirs()
|
void makedirs() {
|
||||||
{
|
|
||||||
char path[32];
|
char path[32];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -371,16 +361,14 @@ void makedirs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int datacmp(const void *p1, const void *p2, void *dummy)
|
static int datacmp(const void *p1, const void *p2, void *dummy) {
|
||||||
{
|
|
||||||
unsigned char *d1 = (unsigned char *)p1;
|
unsigned char *d1 = (unsigned char *)p1;
|
||||||
unsigned char *d2 = (unsigned char *)p2;
|
unsigned char *d2 = (unsigned char *)p2;
|
||||||
|
|
||||||
return memcmp(d1, d2, DATASIZE);
|
return memcmp(d1, d2, DATASIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *sorttable(void *d)
|
void *sorttable(void *d) {
|
||||||
{
|
|
||||||
int i, j;
|
int i, j;
|
||||||
int fdin;
|
int fdin;
|
||||||
int fdout;
|
int fdout;
|
||||||
|
@ -464,8 +452,7 @@ void *sorttable(void *d)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) {
|
||||||
{
|
|
||||||
pthread_t threads[NUM_BUILD_THREADS];
|
pthread_t threads[NUM_BUILD_THREADS];
|
||||||
void *status;
|
void *status;
|
||||||
long i;
|
long i;
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
#include "ht2crack2utils.h"
|
#include "ht2crack2utils.h"
|
||||||
|
|
||||||
|
|
||||||
int makerandom(char *hex, unsigned int len, int fd)
|
int makerandom(char *hex, unsigned int len, int fd) {
|
||||||
{
|
|
||||||
unsigned char raw[32];
|
unsigned char raw[32];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -34,8 +33,7 @@ int makerandom(char *hex, unsigned int len, int fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) {
|
||||||
{
|
|
||||||
Hitag_State hstate;
|
Hitag_State hstate;
|
||||||
char key[32];
|
char key[32];
|
||||||
char uid[32];
|
char uid[32];
|
||||||
|
|
|
@ -17,16 +17,14 @@ struct rngdata {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int datacmp(const void *p1, const void *p2)
|
static int datacmp(const void *p1, const void *p2) {
|
||||||
{
|
|
||||||
unsigned char *d1 = (unsigned char *)p1;
|
unsigned char *d1 = (unsigned char *)p1;
|
||||||
unsigned char *d2 = (unsigned char *)p2;
|
unsigned char *d2 = (unsigned char *)p2;
|
||||||
|
|
||||||
return memcmp(d1, d2, DATASIZE - 6);
|
return memcmp(d1, d2, DATASIZE - 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
int loadrngdata(struct rngdata *r, char *file)
|
int loadrngdata(struct rngdata *r, char *file) {
|
||||||
{
|
|
||||||
int fd;
|
int fd;
|
||||||
int i, j;
|
int i, j;
|
||||||
int nibble;
|
int nibble;
|
||||||
|
@ -93,8 +91,7 @@ int loadrngdata(struct rngdata *r, char *file)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int makecand(unsigned char *c, struct rngdata *r, int bitoffset)
|
int makecand(unsigned char *c, struct rngdata *r, int bitoffset) {
|
||||||
{
|
|
||||||
int bytenum;
|
int bytenum;
|
||||||
int bitnum;
|
int bitnum;
|
||||||
int i;
|
int i;
|
||||||
|
@ -120,8 +117,7 @@ int makecand(unsigned char *c, struct rngdata *r, int bitoffset)
|
||||||
|
|
||||||
|
|
||||||
// test the candidate against the next or previous rng data
|
// test the candidate against the next or previous rng data
|
||||||
int testcand(unsigned char *f, unsigned char *rt, int fwd)
|
int testcand(unsigned char *f, unsigned char *rt, int fwd) {
|
||||||
{
|
|
||||||
Hitag_State hstate;
|
Hitag_State hstate;
|
||||||
int i;
|
int i;
|
||||||
uint32_t ks1;
|
uint32_t ks1;
|
||||||
|
@ -159,8 +155,7 @@ int testcand(unsigned char *f, unsigned char *rt, int fwd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int searchcand(unsigned char *c, unsigned char *rt, int fwd, unsigned char *m, unsigned char *s)
|
int searchcand(unsigned char *c, unsigned char *rt, int fwd, unsigned char *m, unsigned char *s) {
|
||||||
{
|
|
||||||
int fd;
|
int fd;
|
||||||
struct stat filestat;
|
struct stat filestat;
|
||||||
char file[64];
|
char file[64];
|
||||||
|
@ -228,8 +223,7 @@ int searchcand(unsigned char *c, unsigned char *rt, int fwd, unsigned char *m, u
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int findmatch(struct rngdata *r, unsigned char *outmatch, unsigned char *outstate, int *bitoffset)
|
int findmatch(struct rngdata *r, unsigned char *outmatch, unsigned char *outstate, int *bitoffset) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
int bitlen;
|
int bitlen;
|
||||||
unsigned char cand[6];
|
unsigned char cand[6];
|
||||||
|
@ -283,8 +277,7 @@ int findmatch(struct rngdata *r, unsigned char *outmatch, unsigned char *outstat
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void rollbackrng(Hitag_State *hstate, unsigned char *s, int offset)
|
void rollbackrng(Hitag_State *hstate, unsigned char *s, int offset) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!s) {
|
if (!s) {
|
||||||
|
@ -313,8 +306,7 @@ void rollbackrng(Hitag_State *hstate, unsigned char *s, int offset)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t recoverkey(Hitag_State *hstate, char *uidstr, char *nRstr)
|
uint64_t recoverkey(Hitag_State *hstate, char *uidstr, char *nRstr) {
|
||||||
{
|
|
||||||
uint64_t key;
|
uint64_t key;
|
||||||
uint64_t keyupper;
|
uint64_t keyupper;
|
||||||
uint32_t uid;
|
uint32_t uid;
|
||||||
|
@ -364,8 +356,7 @@ uint64_t recoverkey(Hitag_State *hstate, char *uidstr, char *nRstr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[]) {
|
||||||
{
|
|
||||||
Hitag_State hstate;
|
Hitag_State hstate;
|
||||||
struct rngdata rng;
|
struct rngdata rng;
|
||||||
int bitoffset = 0;
|
int bitoffset = 0;
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
#include "ht2crack2utils.h"
|
#include "ht2crack2utils.h"
|
||||||
|
|
||||||
// writes a value into a buffer as a series of bytes
|
// writes a value into a buffer as a series of bytes
|
||||||
void writebuf(unsigned char *buf, uint64_t val, unsigned int len)
|
void writebuf(unsigned char *buf, uint64_t val, unsigned int len) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
for (i=len-1; i>=0; i--)
|
for (i = len - 1; i >= 0; i--) {
|
||||||
{
|
|
||||||
c = val & 0xff;
|
c = val & 0xff;
|
||||||
buf[i] = c;
|
buf[i] = c;
|
||||||
val = val >> 8;
|
val = val >> 8;
|
||||||
|
@ -17,8 +15,7 @@ void writebuf(unsigned char *buf, uint64_t val, unsigned int len)
|
||||||
|
|
||||||
|
|
||||||
/* simple hexdump for testing purposes */
|
/* simple hexdump for testing purposes */
|
||||||
void shexdump(unsigned char *data, int data_len)
|
void shexdump(unsigned char *data, int data_len) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!data || (data_len <= 0)) {
|
if (!data || (data_len <= 0)) {
|
||||||
|
@ -39,8 +36,7 @@ void shexdump(unsigned char *data, int data_len)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void printbin(unsigned char *c)
|
void printbin(unsigned char *c) {
|
||||||
{
|
|
||||||
int i, j;
|
int i, j;
|
||||||
unsigned char x;
|
unsigned char x;
|
||||||
|
|
||||||
|
@ -60,8 +56,7 @@ void printbin(unsigned char *c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printbin2(uint64_t val, unsigned int size)
|
void printbin2(uint64_t val, unsigned int size) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
uint64_t mask = 1;
|
uint64_t mask = 1;
|
||||||
|
|
||||||
|
@ -78,8 +73,7 @@ void printbin2(uint64_t val, unsigned int size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printstate(Hitag_State *hstate)
|
void printstate(Hitag_State *hstate) {
|
||||||
{
|
|
||||||
printf("shiftreg =\t");
|
printf("shiftreg =\t");
|
||||||
printbin2(hstate->shiftreg, 48);
|
printbin2(hstate->shiftreg, 48);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
@ -89,8 +83,7 @@ void printstate(Hitag_State *hstate)
|
||||||
|
|
||||||
|
|
||||||
// convert hex char to binary
|
// convert hex char to binary
|
||||||
unsigned char hex2bin(unsigned char c)
|
unsigned char hex2bin(unsigned char c) {
|
||||||
{
|
|
||||||
if ((c >= '0') && (c <= '9')) {
|
if ((c >= '0') && (c <= '9')) {
|
||||||
return (c - '0');
|
return (c - '0');
|
||||||
} else if ((c >= 'a') && (c <= 'f')) {
|
} else if ((c >= 'a') && (c <= 'f')) {
|
||||||
|
@ -103,8 +96,7 @@ unsigned char hex2bin(unsigned char c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a single bit from a value
|
// return a single bit from a value
|
||||||
int bitn(uint64_t x, int bit)
|
int bitn(uint64_t x, int bit) {
|
||||||
{
|
|
||||||
uint64_t bitmask = 1;
|
uint64_t bitmask = 1;
|
||||||
|
|
||||||
bitmask = bitmask << bit;
|
bitmask = bitmask << bit;
|
||||||
|
@ -118,8 +110,7 @@ int bitn(uint64_t x, int bit)
|
||||||
|
|
||||||
|
|
||||||
// the sub-function R that rollback depends upon
|
// the sub-function R that rollback depends upon
|
||||||
int fnR(uint64_t x)
|
int fnR(uint64_t x) {
|
||||||
{
|
|
||||||
// renumbered bits because my state is 0-47, not 1-48
|
// renumbered bits because my state is 0-47, not 1-48
|
||||||
return (bitn(x, 1) ^ bitn(x, 2) ^ bitn(x, 5) ^ bitn(x, 6) ^ bitn(x, 7) ^
|
return (bitn(x, 1) ^ bitn(x, 2) ^ bitn(x, 5) ^ bitn(x, 6) ^ bitn(x, 7) ^
|
||||||
bitn(x, 15) ^ bitn(x, 21) ^ bitn(x, 22) ^ bitn(x, 25) ^ bitn(x, 29) ^ bitn(x, 40) ^
|
bitn(x, 15) ^ bitn(x, 21) ^ bitn(x, 22) ^ bitn(x, 25) ^ bitn(x, 29) ^ bitn(x, 40) ^
|
||||||
|
@ -127,8 +118,7 @@ int fnR(uint64_t x)
|
||||||
}
|
}
|
||||||
|
|
||||||
// the rollback function that lets us go backwards in time
|
// the rollback function that lets us go backwards in time
|
||||||
void rollback(Hitag_State *hstate, unsigned int steps)
|
void rollback(Hitag_State *hstate, unsigned int steps) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < steps; i++) {
|
for (i = 0; i < steps; i++) {
|
||||||
|
@ -139,24 +129,20 @@ void rollback(Hitag_State *hstate, unsigned int steps)
|
||||||
|
|
||||||
|
|
||||||
// the three filter sub-functions that feed fnf
|
// the three filter sub-functions that feed fnf
|
||||||
int fa(unsigned int i)
|
int fa(unsigned int i) {
|
||||||
{
|
|
||||||
return bitn(0x2C79, i);
|
return bitn(0x2C79, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fb(unsigned int i)
|
int fb(unsigned int i) {
|
||||||
{
|
|
||||||
return bitn(0x6671, i);
|
return bitn(0x6671, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fc(unsigned int i)
|
int fc(unsigned int i) {
|
||||||
{
|
|
||||||
return bitn(0x7907287B, i);
|
return bitn(0x7907287B, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// the filter function that generates a bit of output from the prng state
|
// the filter function that generates a bit of output from the prng state
|
||||||
int fnf(uint64_t s)
|
int fnf(uint64_t s) {
|
||||||
{
|
|
||||||
unsigned int x1, x2, x3, x4, x5, x6;
|
unsigned int x1, x2, x3, x4, x5, x6;
|
||||||
|
|
||||||
x1 = (bitn(s, 2) << 0) | (bitn(s, 3) << 1) | (bitn(s, 5) << 2) | (bitn(s, 6) << 3);
|
x1 = (bitn(s, 2) << 0) | (bitn(s, 3) << 1) | (bitn(s, 5) << 2) | (bitn(s, 6) << 3);
|
||||||
|
@ -171,8 +157,7 @@ int fnf(uint64_t s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// builds the lfsr for the prng (quick calcs for hitag2_nstep())
|
// builds the lfsr for the prng (quick calcs for hitag2_nstep())
|
||||||
void buildlfsr(Hitag_State *hstate)
|
void buildlfsr(Hitag_State *hstate) {
|
||||||
{
|
|
||||||
uint64_t state = hstate->shiftreg;
|
uint64_t state = hstate->shiftreg;
|
||||||
uint64_t temp;
|
uint64_t temp;
|
||||||
|
|
||||||
|
|
|
@ -142,8 +142,7 @@ rtccTime RTC_time; // time structure
|
||||||
rtccDate RTC_date; // date structure
|
rtccDate RTC_date; // date structure
|
||||||
|
|
||||||
// convert byte-reversed 8 digit hex to unsigned long
|
// convert byte-reversed 8 digit hex to unsigned long
|
||||||
unsigned long hexreversetoulong(BYTE *hex)
|
unsigned long hexreversetoulong(BYTE *hex) {
|
||||||
{
|
|
||||||
unsigned long ret = 0L;
|
unsigned long ret = 0L;
|
||||||
unsigned int x;
|
unsigned int x;
|
||||||
BYTE i;
|
BYTE i;
|
||||||
|
@ -151,8 +150,7 @@ unsigned long hexreversetoulong(BYTE *hex)
|
||||||
if (strlen(hex) != 8)
|
if (strlen(hex) != 8)
|
||||||
return 0L;
|
return 0L;
|
||||||
|
|
||||||
for(i= 0 ; i < 4 ; ++i)
|
for (i = 0 ; i < 4 ; ++i) {
|
||||||
{
|
|
||||||
if (sscanf(hex, "%2X", &x) != 1)
|
if (sscanf(hex, "%2X", &x) != 1)
|
||||||
return 0L;
|
return 0L;
|
||||||
ret += ((unsigned long) x) << i * 8;
|
ret += ((unsigned long) x) << i * 8;
|
||||||
|
@ -162,8 +160,7 @@ unsigned long hexreversetoulong(BYTE *hex)
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert byte-reversed 12 digit hex to unsigned long
|
// convert byte-reversed 12 digit hex to unsigned long
|
||||||
unsigned long long hexreversetoulonglong(BYTE *hex)
|
unsigned long long hexreversetoulonglong(BYTE *hex) {
|
||||||
{
|
|
||||||
unsigned long long ret = 0LL;
|
unsigned long long ret = 0LL;
|
||||||
BYTE tmp[9];
|
BYTE tmp[9];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue