qdf_crypto.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /**
  19. * DOC: qdf_crypto.h
  20. * This file provides OS abstraction for crypto APIs.
  21. */
  22. #if !defined(__QDF_CRYPTO_H)
  23. #define __QDF_CRYPTO_H
  24. /* Include Files */
  25. #include "qdf_status.h"
  26. #include <qdf_types.h>
  27. #include <qdf_trace.h>
  28. /* Preprocessor definitions and constants */
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif /* __cplusplus */
  32. #define AES_BLOCK_SIZE 16
  33. #define HMAC_SHA256_CRYPTO_TYPE "hmac(sha256)"
  34. #define HMAC_SHA386_CRYPTO_TYPE "hmac(sha384)"
  35. #define SHA256_CRYPTO_TYPE "sha256"
  36. #define SHA386_CRYPTO_TYPE "sha384"
  37. #define SHA256_DIGEST_SIZE 32
  38. #define SHA384_DIGEST_SIZE 48
  39. #define FIXED_PARAM_OFFSET_ASSOC_REQ 4
  40. #define FIXED_PARAM_OFFSET_ASSOC_RSP 6
  41. #define AAD_LEN 20
  42. #define IEEE80211_MMIE_GMAC_MICLEN 16
  43. #define IS_VALID_CTR_KEY_LEN(len) ((((len) == 16) || ((len) == 32) || \
  44. ((len) == 48)) ? 1 : 0)
  45. /* Function declarations and documenation */
  46. /**
  47. * qdf_get_hash: API to get hash using specific crypto and scatterlist
  48. * @type: crypto type
  49. * @element_cnt: scatterlist element count
  50. * @addr: scatterlist element array
  51. * @addr_len: element length array
  52. * @hash: new hash
  53. *
  54. * Return: 0 if success else error code
  55. */
  56. int qdf_get_hash(uint8_t *type, uint8_t element_cnt,
  57. uint8_t *addr[], uint32_t *addr_len,
  58. int8_t *hash);
  59. /**
  60. * qdf_get_hmac_hash: API to get hmac hash using specific crypto and
  61. * scatterlist elements.
  62. * @type: crypto type
  63. * @key: key needs to be used for hmac api
  64. * @keylen: length of key
  65. * @element_cnt: scatterlist element count
  66. * @addr: scatterlist element array
  67. * @addr_len: element length array
  68. * @hash: new hash
  69. *
  70. * Return: 0 if success else error code
  71. */
  72. int qdf_get_hmac_hash(uint8_t *type, uint8_t *key,
  73. uint32_t keylen, uint8_t element_cnt,
  74. uint8_t *addr[], uint32_t *addr_len, int8_t *hash);
  75. /**
  76. * qdf_get_keyed_hash: API to get hash using specific crypto and
  77. * scatterlist elements.
  78. * @type: crypto type
  79. * @key: key needs to be used for hmac api
  80. * @keylen: length of key
  81. * @element_cnt: scatterlist element count
  82. * @addr: scatterlist element array
  83. * @addr_len: element length array
  84. * @hash: new hash
  85. *
  86. * Return: 0 if success else error code
  87. */
  88. int qdf_get_keyed_hash(const char *alg, const uint8_t *key,
  89. unsigned int key_len, const uint8_t *src[],
  90. size_t *src_len, size_t num_elements, uint8_t *out);
  91. /**
  92. * qdf_update_dbl: This API does the doubling operation as defined in RFC5297
  93. * @d: input for doubling
  94. *
  95. * Return: None
  96. */
  97. void qdf_update_dbl(uint8_t *d);
  98. /**
  99. * qdf_aes_s2v: This API gets vector from AES string as defined in RFC5297
  100. * output length will be AES_BLOCK_SIZE.
  101. * @key: key used for operation
  102. * @key_len: key len
  103. * @s: addresses of elements to be used
  104. * @s_len: array of element length
  105. * @num_s: number of elements
  106. * @out: pointer to output vector
  107. *
  108. * Return: 0 if success else Error number
  109. */
  110. int qdf_aes_s2v(const uint8_t *key, unsigned int key_len, const uint8_t *s[],
  111. size_t s_len[], size_t num_s, uint8_t *out);
  112. /**
  113. * qdf_aes_ctr: This API defines AES Counter Mode
  114. * @key: key used for operation
  115. * @key_len: key len
  116. * @siv: Initialization vector
  117. * @src: input
  118. * @src_len: input len
  119. * @dest: output
  120. * @enc: if encryption needs to be done or decryption
  121. *
  122. * Return: 0 if success else Error number
  123. */
  124. int qdf_aes_ctr(const uint8_t *key, unsigned int key_len, uint8_t *siv,
  125. const uint8_t *src, size_t src_len, uint8_t *dest, bool enc);
  126. /**
  127. * qdf_crypto_aes_gmac: This API calculates MIC for GMAC
  128. * @key: key used for operation
  129. * @key_length: key length
  130. * @iv: Initialization vector
  131. * @aad: Additional authentication data
  132. * @data: Pointer to data
  133. * @data_len: Length of data
  134. * @mic: Pointer to MIC
  135. *
  136. * Return: 0 if success else Error number
  137. */
  138. int qdf_crypto_aes_gmac(uint8_t *key, uint16_t key_length,
  139. uint8_t *iv, uint8_t *aad, uint8_t *data,
  140. uint16_t data_len, uint8_t *mic);
  141. #ifdef __cplusplus
  142. }
  143. #endif /* __cplusplus */
  144. #endif /* __QDF_CRYPTO_H */