crypto.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* SPDX-License-Identifier: LGPL-2.1-or-later */
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2018 Intel Corporation. All rights reserved.
  7. *
  8. *
  9. */
  10. #include <stdbool.h>
  11. #include <stdint.h>
  12. #include <stdlib.h>
  13. bool mesh_crypto_aes_ccm_encrypt(const uint8_t nonce[13], const uint8_t key[16],
  14. const uint8_t *aad, uint16_t aad_len,
  15. const void *msg, uint16_t msg_len,
  16. void *out_msg,
  17. void *out_mic, size_t mic_size);
  18. bool mesh_crypto_aes_ccm_decrypt(const uint8_t nonce[13], const uint8_t key[16],
  19. const uint8_t *aad, uint16_t aad_len,
  20. const void *enc_msg, uint16_t enc_msg_len,
  21. void *out_msg,
  22. void *out_mic, size_t mic_size);
  23. bool mesh_aes_ecb_one(const uint8_t key[16],
  24. const uint8_t plaintext[16], uint8_t encrypted[16]);
  25. bool mesh_crypto_nkik(const uint8_t network_key[16], uint8_t identity_key[16]);
  26. bool mesh_crypto_nkbk(const uint8_t network_key[16], uint8_t beacon_key[16]);
  27. bool mesh_crypto_nkpk(const uint8_t network_key[16], uint8_t proxy_key[16]);
  28. bool mesh_crypto_identity(const uint8_t net_key[16], uint16_t addr,
  29. uint8_t id[16]);
  30. bool mesh_crypto_beacon_cmac(const uint8_t encryption_key[16],
  31. const uint8_t network_id[8],
  32. uint32_t iv_index, bool kr,
  33. bool iu, uint64_t *cmac);
  34. bool mesh_crypto_device_key(const uint8_t secret[32],
  35. const uint8_t salt[16],
  36. uint8_t device_key[16]);
  37. bool mesh_crypto_virtual_addr(const uint8_t virtual_label[16],
  38. uint16_t *v_addr);
  39. bool mesh_crypto_nonce(const uint8_t secret[32],
  40. const uint8_t salt[16],
  41. uint8_t nonce[13]);
  42. bool mesh_crypto_k1(const uint8_t ikm[16], const uint8_t salt[16],
  43. const void *info, size_t info_len, uint8_t okm[16]);
  44. bool mesh_crypto_k2(const uint8_t n[16], const uint8_t *p, size_t p_len,
  45. uint8_t net_id[1],
  46. uint8_t enc_key[16],
  47. uint8_t priv_key[16]);
  48. bool mesh_crypto_k3(const uint8_t n[16], uint8_t out64[8]);
  49. bool mesh_crypto_k4(const uint8_t a[16], uint8_t out5[1]);
  50. bool mesh_crypto_s1(const void *info, size_t len, uint8_t salt[16]);
  51. bool mesh_crypto_prov_prov_salt(const uint8_t conf_salt[16],
  52. const uint8_t prov_rand[16],
  53. const uint8_t dev_rand[16],
  54. uint8_t prov_salt[16]);
  55. bool mesh_crypto_prov_conf_key(const uint8_t secret[32],
  56. const uint8_t salt[16],
  57. uint8_t conf_key[16]);
  58. bool mesh_crypto_session_key(const uint8_t secret[32],
  59. const uint8_t salt[16],
  60. uint8_t session_key[16]);
  61. bool mesh_crypto_packet_build(bool ctl, uint8_t ttl,
  62. uint32_t seq,
  63. uint16_t src, uint16_t dst,
  64. uint8_t opcode,
  65. bool segmented, uint8_t key_aid,
  66. bool szmic, bool relay, uint16_t seqZero,
  67. uint8_t segO, uint8_t segN,
  68. const uint8_t *payload, uint8_t payload_len,
  69. uint8_t *packet, uint8_t *packet_len);
  70. bool mesh_crypto_packet_parse(const uint8_t *packet, uint8_t packet_len,
  71. bool *ctl, uint8_t *ttl, uint32_t *seq,
  72. uint16_t *src, uint16_t *dst,
  73. uint32_t *cookie, uint8_t *opcode,
  74. bool *segmented, uint8_t *key_aid,
  75. bool *szmic, bool *relay, uint16_t *seqZero,
  76. uint8_t *segO, uint8_t *segN,
  77. const uint8_t **payload, uint8_t *payload_len);
  78. bool mesh_crypto_payload_encrypt(uint8_t *aad, const uint8_t *payload,
  79. uint8_t *out, uint16_t payload_len,
  80. uint16_t src, uint16_t dst, uint8_t key_aid,
  81. uint32_t seq_num, uint32_t iv_index,
  82. bool aszmic,
  83. const uint8_t application_key[16]);
  84. bool mesh_crypto_payload_decrypt(uint8_t *aad, uint16_t aad_len,
  85. const uint8_t *payload, uint16_t payload_len,
  86. bool szmict,
  87. uint16_t src, uint16_t dst, uint8_t key_aid,
  88. uint32_t seq_num, uint32_t iv_index,
  89. uint8_t *out,
  90. const uint8_t application_key[16]);
  91. bool mesh_crypto_packet_encode(uint8_t *packet, uint8_t packet_len,
  92. uint32_t iv_index,
  93. const uint8_t network_key[16],
  94. const uint8_t privacy_key[16]);
  95. bool mesh_crypto_packet_decode(const uint8_t *packet, uint8_t packet_len,
  96. bool proxy, uint8_t *out, uint32_t iv_index,
  97. const uint8_t network_key[16],
  98. const uint8_t privacy_key[16]);
  99. bool mesh_crypto_packet_label(uint8_t *packet, uint8_t packet_len,
  100. uint16_t iv_index, uint8_t network_id);
  101. uint8_t mesh_crypto_compute_fcs(const uint8_t *packet, uint8_t packet_len);
  102. bool mesh_crypto_check_fcs(const uint8_t *packet, uint8_t packet_len,
  103. uint8_t received_fcs);
  104. bool mesh_crypto_aes_cmac(const uint8_t key[16], const uint8_t *msg,
  105. size_t msg_len, uint8_t res[16]);
  106. bool mesh_crypto_check_avail(void);