seos_common.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_READER,
  28. FLOW_CRED,
  29. FLOW_READER_SCANNER,
  30. FLOW_CRED_SCANNER,
  31. } FlowMode;
  32. typedef enum {
  33. SELECT_AID,
  34. SELECT_ADF,
  35. GENERAL_AUTHENTICATION_1,
  36. GENERAL_AUTHENTICATION_2,
  37. REQUEST_SIO,
  38. } SeosPhase;
  39. typedef struct {
  40. uint8_t diversifier[16];
  41. size_t diversifier_len;
  42. uint8_t sio[128];
  43. size_t sio_len;
  44. uint8_t priv_key[16];
  45. uint8_t auth_key[16];
  46. uint8_t adf_response[72];
  47. } SeosCredential;
  48. typedef struct {
  49. uint8_t rndICC[8];
  50. uint8_t UID[8];
  51. uint8_t cNonce[16];
  52. uint8_t rNonce[16];
  53. uint8_t priv_key[16];
  54. uint8_t auth_key[16];
  55. uint8_t key_no;
  56. uint8_t cipher;
  57. uint8_t hash;
  58. } AuthParameters;
  59. void seos_log_bitbuffer(char* TAG, char* prefix, BitBuffer* buffer);
  60. void seos_log_buffer(char* TAG, char* prefix, uint8_t* buffer, size_t buffer_len);
  61. void seos_common_copy_credential(const SeosCredential* src, SeosCredential* dst);
  62. void seos_worker_diversify_key(
  63. uint8_t master_key_value[16],
  64. uint8_t* diversifier,
  65. size_t diversifier_len,
  66. uint8_t* adf_oid,
  67. size_t adf_oid_len,
  68. uint8_t algo_id1,
  69. uint8_t algo_id2,
  70. uint8_t reference_qualifier,
  71. bool is_encryption,
  72. uint8_t* div_key);
  73. void seos_worker_aes_decrypt(
  74. uint8_t key[16],
  75. size_t length,
  76. const uint8_t* encrypted,
  77. uint8_t* clear);
  78. void seos_worker_des_decrypt(
  79. uint8_t key[16],
  80. size_t length,
  81. const uint8_t* encrypted,
  82. uint8_t* clear);
  83. void seos_worker_aes_encrypt(
  84. uint8_t key[16],
  85. size_t length,
  86. const uint8_t* clear,
  87. uint8_t* encrypted);
  88. void seos_worker_des_encrypt(
  89. uint8_t key[16],
  90. size_t length,
  91. const uint8_t* clear,
  92. uint8_t* encrypted);