crypto.h 4.2 KB

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