seos_common.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #pragma once
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <furi.h>
  5. #include <furi_hal.h>
  6. #include <lib/toolbox/bit_buffer.h>
  7. #include <mbedtls/des.h>
  8. #include <mbedtls/aes.h>
  9. #include "aes_cmac.h"
  10. #include "des_cmac.h"
  11. #define TWO_KEY_3DES_CBC_MODE 2
  12. #define THREE_KEY_3DES_CBC_MODE 4
  13. #define SHA1 6
  14. #define SHA256 7
  15. #define AES_128_CBC 9
  16. #define SEOS_WORKER_MAX_BUFFER_SIZE 128
  17. #define SEOS_WORKER_CMAC_SIZE 8
  18. #define SEOS_APP_EXTENSION ".seos"
  19. #define SEOS_FILE_NAME_MAX_LENGTH 32
  20. extern char* seos_file_header;
  21. extern uint32_t seos_file_version;
  22. typedef enum {
  23. BLE_PERIPHERAL,
  24. BLE_CENTRAL,
  25. } BleMode;
  26. typedef enum {
  27. FLOW_TEST,
  28. FLOW_READER,
  29. FLOW_CRED,
  30. FLOW_READER_SCANNER,
  31. FLOW_CRED_SCANNER,
  32. FLOW_INSPECT,
  33. } FlowMode;
  34. typedef enum {
  35. SELECT_AID,
  36. SELECT_ADF,
  37. GENERAL_AUTHENTICATION_1,
  38. GENERAL_AUTHENTICATION_2,
  39. REQUEST_SIO,
  40. } SeosPhase;
  41. typedef struct {
  42. uint8_t rndICC[8];
  43. uint8_t UID[8];
  44. uint8_t cNonce[16];
  45. uint8_t rNonce[16];
  46. uint8_t priv_key[16];
  47. uint8_t auth_key[16];
  48. uint8_t key_no;
  49. uint8_t cipher;
  50. uint8_t hash;
  51. } AuthParameters;
  52. void seos_log_bitbuffer(char* TAG, char* prefix, BitBuffer* buffer);
  53. void seos_log_buffer(char* TAG, char* prefix, uint8_t* buffer, size_t buffer_len);
  54. void seos_worker_diversify_key(
  55. uint8_t master_key_value[16],
  56. uint8_t* diversifier,
  57. size_t diversifier_len,
  58. uint8_t* adf_oid,
  59. size_t adf_oid_len,
  60. uint8_t algo_id1,
  61. uint8_t algo_id2,
  62. uint8_t reference_qualifier,
  63. bool is_encryption,
  64. uint8_t* div_key);
  65. void seos_worker_aes_decrypt(
  66. uint8_t key[16],
  67. size_t length,
  68. const uint8_t* encrypted,
  69. uint8_t* clear);
  70. void seos_worker_des_decrypt(
  71. uint8_t key[16],
  72. size_t length,
  73. const uint8_t* encrypted,
  74. uint8_t* clear);
  75. void seos_worker_aes_encrypt(
  76. uint8_t key[16],
  77. size_t length,
  78. const uint8_t* clear,
  79. uint8_t* encrypted);
  80. void seos_worker_des_encrypt(
  81. uint8_t key[16],
  82. size_t length,
  83. const uint8_t* clear,
  84. uint8_t* encrypted);