qdf_crypto.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (c) 2017 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 IS_VALID_CTR_KEY_LEN(len) ((((len) == 16) || ((len) == 32) || \
  42. ((len) == 48)) ? 1 : 0)
  43. /* Function declarations and documenation */
  44. /**
  45. * qdf_get_hash: API to get hash using specific crypto and scatterlist
  46. * @type: crypto type
  47. * @element_cnt: scatterlist element count
  48. * @addr: scatterlist element array
  49. * @addr_len: element length array
  50. * @hash: new hash
  51. *
  52. * Return: 0 if success else error code
  53. */
  54. int qdf_get_hash(uint8_t *type, uint8_t element_cnt,
  55. uint8_t *addr[], uint32_t *addr_len,
  56. int8_t *hash);
  57. /**
  58. * qdf_get_hmac_hash: API to get hmac hash using specific crypto and
  59. * scatterlist elements.
  60. * @type: crypto type
  61. * @key: key needs to be used for hmac api
  62. * @keylen: length of key
  63. * @element_cnt: scatterlist element count
  64. * @addr: scatterlist element array
  65. * @addr_len: element length array
  66. * @hash: new hash
  67. *
  68. * Return: 0 if success else error code
  69. */
  70. int qdf_get_hmac_hash(uint8_t *type, uint8_t *key,
  71. uint32_t keylen, uint8_t element_cnt,
  72. uint8_t *addr[], uint32_t *addr_len, int8_t *hash);
  73. /**
  74. * qdf_get_keyed_hash: API to get hash using specific crypto and
  75. * scatterlist elements.
  76. * @type: crypto type
  77. * @key: key needs to be used for hmac api
  78. * @keylen: length of key
  79. * @element_cnt: scatterlist element count
  80. * @addr: scatterlist element array
  81. * @addr_len: element length array
  82. * @hash: new hash
  83. *
  84. * Return: 0 if success else error code
  85. */
  86. int qdf_get_keyed_hash(const char *alg, const uint8_t *key,
  87. unsigned int key_len, const uint8_t *src[],
  88. size_t *src_len, size_t num_elements, uint8_t *out);
  89. /**
  90. * qdf_update_dbl: This API does the doubling operation as defined in RFC5297
  91. * @d: input for doubling
  92. *
  93. * Return: None
  94. */
  95. void qdf_update_dbl(uint8_t *d);
  96. /**
  97. * qdf_aes_s2v: This API gets vector from AES string as defined in RFC5297
  98. * output length will be AES_BLOCK_SIZE.
  99. * @key: key used for operation
  100. * @key_len: key len
  101. * @s: addresses of elements to be used
  102. * @s_len: array of element length
  103. * @num_s: number of elements
  104. * @out: pointer to output vector
  105. *
  106. * Return: 0 if success else Error number
  107. */
  108. int qdf_aes_s2v(const uint8_t *key, unsigned int key_len, const uint8_t *s[],
  109. size_t s_len[], size_t num_s, uint8_t *out);
  110. /**
  111. * qdf_aes_ctr: This API defines AES Counter Mode
  112. * @key: key used for operation
  113. * @key_len: key len
  114. * @siv: Initialization vector
  115. * @src: input
  116. * @src_len: input len
  117. * @dest: output
  118. * @enc: if encryption needs to be done or decryption
  119. *
  120. * Return: 0 if success else Error number
  121. */
  122. int qdf_aes_ctr(const uint8_t *key, unsigned int key_len, uint8_t *siv,
  123. const uint8_t *src, size_t src_len, uint8_t *dest, bool enc);
  124. #ifdef __cplusplus
  125. }
  126. #endif /* __cplusplus */
  127. #endif /* __QDF_CRYPTO_H */