]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/hitag2.c
More en masse cleanup (whitespace/newlines/headers/etc)
[proxmark3-svn] / armsrc / hitag2.c
index 886e19707825d127a0a786a130fc6d61e51a7f52..f2fbac84869a38c06de647cbc5a304c7f30879ed 100644 (file)
@@ -1,13 +1,13 @@
 /*
  * Hitag2 emulation
 /*
  * Hitag2 emulation
- * 
+ *
  * Contains state and functions for an emulated Hitag2 tag. Offers an entry
  * point to handle commands, needs a callback to send response.
  * Contains state and functions for an emulated Hitag2 tag. Offers an entry
  * point to handle commands, needs a callback to send response.
- * 
+ *
  * (c) 2009 Henryk Plötz <henryk@ploetzli.ch>
  */
 
  * (c) 2009 Henryk Plötz <henryk@ploetzli.ch>
  */
 
-#include <proxmark3.h>
+#include "proxmark3.h"
 #include <stdint.h>
 
 #include "apps.h"
 #include <stdint.h>
 
 #include "apps.h"
@@ -19,7 +19,7 @@ struct hitag2_cipher_state {
 
 struct hitag2_tag {
        uint32_t uid;
 
 struct hitag2_tag {
        uint32_t uid;
-       enum { 
+       enum {
                TAG_STATE_RESET,          // Just powered up, awaiting GetSnr
                TAG_STATE_ACTIVATING,     // In activation phase (password mode), sent UID, awaiting reader password
                TAG_STATE_AUTHENTICATING, // In activation phase (crypto mode), awaiting reader authentication
                TAG_STATE_RESET,          // Just powered up, awaiting GetSnr
                TAG_STATE_ACTIVATING,     // In activation phase (password mode), sent UID, awaiting reader password
                TAG_STATE_AUTHENTICATING, // In activation phase (crypto mode), awaiting reader authentication
@@ -74,7 +74,7 @@ int hitag2_handle_command(const char* data, const int length, hitag2_response_ca
                data = temp;
        }
 
                data = temp;
        }
 
-       
+
 handle_command_retry:
        switch(tag.state) {
        case TAG_STATE_RESET:
 handle_command_retry:
        switch(tag.state) {
        case TAG_STATE_RESET:
@@ -148,8 +148,8 @@ handle_command_retry:
                                        /* transmission error */
                                        DbpString("Transmission error (write) in activated state");
                                }
                                        /* transmission error */
                                        DbpString("Transmission error (write) in activated state");
                                }
-                       } 
-                               
+                       }
+
                }
        case TAG_STATE_WRITING:
                if(length == 32) {
                }
        case TAG_STATE_WRITING:
                if(length == 32) {
@@ -159,7 +159,7 @@ handle_command_retry:
                        done=1;
                }
        }
                        done=1;
                }
        }
-       
+
        if(!done && !retry) {
                /* We didn't respond, maybe our state is faulty. Reset and try again. */
                retry=1;
        if(!done && !retry) {
                /* We didn't respond, maybe our state is faulty. Reset and try again. */
                retry=1;
@@ -205,13 +205,13 @@ static const u32 ht2_f5c = 0x7907287B;    // 0111 1001 0000 0111 0010 1000 0111 101
 static u32 _f20 (const u64 x)
 {
        u32                                     i5;
 static u32 _f20 (const u64 x)
 {
        u32                                     i5;
-       
+
        i5 = ((ht2_f4a >> i4 (x, 1, 2, 4, 5)) & 1)* 1
           + ((ht2_f4b >> i4 (x, 7,11,13,14)) & 1)* 2
           + ((ht2_f4b >> i4 (x,16,20,22,25)) & 1)* 4
           + ((ht2_f4b >> i4 (x,27,28,30,32)) & 1)* 8
           + ((ht2_f4a >> i4 (x,33,42,43,45)) & 1)*16;
        i5 = ((ht2_f4a >> i4 (x, 1, 2, 4, 5)) & 1)* 1
           + ((ht2_f4b >> i4 (x, 7,11,13,14)) & 1)* 2
           + ((ht2_f4b >> i4 (x,16,20,22,25)) & 1)* 4
           + ((ht2_f4b >> i4 (x,27,28,30,32)) & 1)* 8
           + ((ht2_f4a >> i4 (x,33,42,43,45)) & 1)*16;
-       
+
        return (ht2_f5c >> i5) & 1;
 }
 
        return (ht2_f5c >> i5) & 1;
 }
 
@@ -219,7 +219,7 @@ static u64 _hitag2_init (const u64 key, const u32 serial, const u32 IV)
 {
        u32                                     i;
        u64                                     x = ((key & 0xFFFF) << 32) + serial;
 {
        u32                                     i;
        u64                                     x = ((key & 0xFFFF) << 32) + serial;
-       
+
        for (i = 0; i < 32; i++)
        {
                x >>= 1;
        for (i = 0; i < 32; i++)
        {
                x >>= 1;
@@ -231,13 +231,13 @@ static u64 _hitag2_init (const u64 key, const u32 serial, const u32 IV)
 static u64 _hitag2_round (u64 *state)
 {
        u64                                     x = *state;
 static u64 _hitag2_round (u64 *state)
 {
        u64                                     x = *state;
-       
+
        x = (x >>  1) +
         ((((x >>  0) ^ (x >>  2) ^ (x >>  3) ^ (x >>  6)
          ^ (x >>  7) ^ (x >>  8) ^ (x >> 16) ^ (x >> 22)
          ^ (x >> 23) ^ (x >> 26) ^ (x >> 30) ^ (x >> 41)
          ^ (x >> 42) ^ (x >> 43) ^ (x >> 46) ^ (x >> 47)) & 1) << 47);
        x = (x >>  1) +
         ((((x >>  0) ^ (x >>  2) ^ (x >>  3) ^ (x >>  6)
          ^ (x >>  7) ^ (x >>  8) ^ (x >> 16) ^ (x >> 22)
          ^ (x >> 23) ^ (x >> 26) ^ (x >> 30) ^ (x >> 41)
          ^ (x >> 42) ^ (x >> 43) ^ (x >> 46) ^ (x >> 47)) & 1) << 47);
-       
+
        *state = x;
        return _f20 (x);
 }
        *state = x;
        return _f20 (x);
 }
@@ -245,7 +245,7 @@ static u64 _hitag2_round (u64 *state)
 static u32 _hitag2_byte (u64 * x)
 {
        u32                                     i, c;
 static u32 _hitag2_byte (u64 * x)
 {
        u32                                     i, c;
-       
+
        for (i = 0, c = 0; i < 8; i++) c += (u32) _hitag2_round (x) << (i^7);
        return c;
 }
        for (i = 0, c = 0; i < 8; i++) c += (u32) _hitag2_round (x) << (i^7);
        return c;
 }
Impressum, Datenschutz