optimized_cipherutils.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //-----------------------------------------------------------------------------
  2. // Borrowed initially from https://github.com/holiman/loclass
  3. // More recently from https://github.com/RfidResearchGroup/proxmark3
  4. // Copyright (C) 2014 Martin Holst Swende
  5. // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
  6. //
  7. // This program is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation, either version 3 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // See LICENSE.txt for the text of the license.
  18. //-----------------------------------------------------------------------------
  19. // WARNING
  20. //
  21. // THIS CODE IS CREATED FOR EXPERIMENTATION AND EDUCATIONAL USE ONLY.
  22. //
  23. // USAGE OF THIS CODE IN OTHER WAYS MAY INFRINGE UPON THE INTELLECTUAL
  24. // PROPERTY OF OTHER PARTIES, SUCH AS INSIDE SECURE AND HID GLOBAL,
  25. // AND MAY EXPOSE YOU TO AN INFRINGEMENT ACTION FROM THOSE PARTIES.
  26. //
  27. // THIS CODE SHOULD NEVER BE USED TO INFRINGE PATENTS OR INTELLECTUAL PROPERTY RIGHTS.
  28. //-----------------------------------------------------------------------------
  29. // It is a reconstruction of the cipher engine used in iClass, and RFID techology.
  30. //
  31. // The implementation is based on the work performed by
  32. // Flavio D. Garcia, Gerhard de Koning Gans, Roel Verdult and
  33. // Milosch Meriac in the paper "Dismantling IClass".
  34. //-----------------------------------------------------------------------------
  35. #ifndef CIPHERUTILS_H
  36. #define CIPHERUTILS_H
  37. #include <stdint.h>
  38. #include <stdbool.h>
  39. #include <stdlib.h>
  40. typedef struct {
  41. uint8_t* buffer;
  42. uint8_t numbits;
  43. uint8_t position;
  44. } LoclassBitstreamIn_t;
  45. typedef struct {
  46. uint8_t* buffer;
  47. uint8_t numbits;
  48. uint8_t position;
  49. } LoclassBitstreamOut_t;
  50. bool loclass_headBit(LoclassBitstreamIn_t* stream);
  51. bool loclass_tailBit(LoclassBitstreamIn_t* stream);
  52. void loclass_pushBit(LoclassBitstreamOut_t* stream, bool bit);
  53. int loclass_bitsLeft(LoclassBitstreamIn_t* stream);
  54. void loclass_push6bits(LoclassBitstreamOut_t* stream, uint8_t bits);
  55. void loclass_x_num_to_bytes(uint64_t n, size_t len, uint8_t* dest);
  56. uint64_t loclass_x_bytes_to_num(uint8_t* src, size_t len);
  57. uint8_t loclass_reversebytes(uint8_t b);
  58. void loclass_reverse_arraybytes(uint8_t* arr, size_t len);
  59. void loclass_reverse_arraycopy(uint8_t* arr, uint8_t* dest, size_t len);
  60. #endif // CIPHERUTILS_H