2
0

crypto_kernel.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * crypto_kernel.h
  3. *
  4. * header for the cryptographic kernel
  5. *
  6. * David A. McGrew
  7. * Cisco Systems, Inc.
  8. */
  9. /*
  10. *
  11. * Copyright(c) 2001-2017 Cisco Systems, Inc.
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. *
  18. * Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. *
  21. * Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials provided
  24. * with the distribution.
  25. *
  26. * Neither the name of the Cisco Systems, Inc. nor the names of its
  27. * contributors may be used to endorse or promote products derived
  28. * from this software without specific prior written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  33. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  34. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  35. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  36. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  37. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  41. * OF THE POSSIBILITY OF SUCH DAMAGE.
  42. *
  43. */
  44. #ifndef CRYPTO_KERNEL
  45. #define CRYPTO_KERNEL
  46. #include "cipher.h"
  47. #include "auth.h"
  48. #include "err.h"
  49. #include "crypto_types.h"
  50. #include "key.h"
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif
  54. /*
  55. * crypto_kernel_state_t defines the possible states:
  56. *
  57. * insecure - not yet initialized
  58. * secure - initialized and passed self-tests
  59. */
  60. typedef enum {
  61. srtp_crypto_kernel_state_insecure,
  62. srtp_crypto_kernel_state_secure
  63. } srtp_crypto_kernel_state_t;
  64. /*
  65. * linked list of cipher types
  66. */
  67. typedef struct srtp_kernel_cipher_type {
  68. srtp_cipher_type_id_t id;
  69. const srtp_cipher_type_t *cipher_type;
  70. struct srtp_kernel_cipher_type *next;
  71. } srtp_kernel_cipher_type_t;
  72. /*
  73. * linked list of auth types
  74. */
  75. typedef struct srtp_kernel_auth_type {
  76. srtp_auth_type_id_t id;
  77. const srtp_auth_type_t *auth_type;
  78. struct srtp_kernel_auth_type *next;
  79. } srtp_kernel_auth_type_t;
  80. /*
  81. * linked list of debug modules
  82. */
  83. typedef struct srtp_kernel_debug_module {
  84. srtp_debug_module_t *mod;
  85. struct srtp_kernel_debug_module *next;
  86. } srtp_kernel_debug_module_t;
  87. /*
  88. * crypto_kernel_t is the data structure for the crypto kernel
  89. *
  90. * note that there is *exactly one* instance of this data type,
  91. * a global variable defined in crypto_kernel.c
  92. */
  93. typedef struct {
  94. srtp_crypto_kernel_state_t state; /* current state of kernel */
  95. srtp_kernel_cipher_type_t *cipher_type_list; /* list of all cipher types */
  96. srtp_kernel_auth_type_t *auth_type_list; /* list of all auth func types */
  97. srtp_kernel_debug_module_t
  98. *debug_module_list; /* list of all debug modules */
  99. } srtp_crypto_kernel_t;
  100. /*
  101. * srtp_crypto_kernel_t external api
  102. */
  103. /*
  104. * The function srtp_crypto_kernel_init() initialized the crypto kernel and
  105. * runs the self-test operations on the random number generators and
  106. * crypto algorithms. Possible return values are:
  107. *
  108. * srtp_err_status_ok initialization successful
  109. * <other> init failure
  110. *
  111. * If any value other than srtp_err_status_ok is returned, the
  112. * crypto_kernel MUST NOT be used.
  113. */
  114. srtp_err_status_t srtp_crypto_kernel_init(void);
  115. /*
  116. * The function srtp_crypto_kernel_shutdown() de-initializes the
  117. * crypto_kernel, zeroizes keys and other cryptographic material, and
  118. * deallocates any dynamically allocated memory. Possible return
  119. * values are:
  120. *
  121. * srtp_err_status_ok shutdown successful
  122. * <other> shutdown failure
  123. *
  124. */
  125. srtp_err_status_t srtp_crypto_kernel_shutdown(void);
  126. /*
  127. * The function srtp_crypto_kernel_stats() checks the the crypto_kernel,
  128. * running tests on the ciphers, auth funcs, and rng, and prints out a
  129. * status report. Possible return values are:
  130. *
  131. * srtp_err_status_ok all tests were passed
  132. * <other> a test failed
  133. *
  134. */
  135. srtp_err_status_t srtp_crypto_kernel_status(void);
  136. /*
  137. * srtp_crypto_kernel_list_debug_modules() outputs a list of debugging modules
  138. *
  139. */
  140. srtp_err_status_t srtp_crypto_kernel_list_debug_modules(void);
  141. /*
  142. * srtp_crypto_kernel_load_cipher_type()
  143. *
  144. */
  145. srtp_err_status_t srtp_crypto_kernel_load_cipher_type(
  146. const srtp_cipher_type_t *ct,
  147. srtp_cipher_type_id_t id);
  148. srtp_err_status_t srtp_crypto_kernel_load_auth_type(const srtp_auth_type_t *ct,
  149. srtp_auth_type_id_t id);
  150. srtp_err_status_t srtp_crypto_kernel_load_debug_module(
  151. srtp_debug_module_t *new_dm);
  152. /*
  153. * srtp_crypto_kernel_alloc_cipher(id, cp, key_len);
  154. *
  155. * allocates a cipher of type id at location *cp, with key length
  156. * key_len octets. Return values are:
  157. *
  158. * srtp_err_status_ok no problems
  159. * srtp_err_status_alloc_fail an allocation failure occured
  160. * srtp_err_status_fail couldn't find cipher with identifier 'id'
  161. */
  162. srtp_err_status_t srtp_crypto_kernel_alloc_cipher(srtp_cipher_type_id_t id,
  163. srtp_cipher_pointer_t *cp,
  164. int key_len,
  165. int tag_len);
  166. /*
  167. * srtp_crypto_kernel_alloc_auth(id, ap, key_len, tag_len);
  168. *
  169. * allocates an auth function of type id at location *ap, with key
  170. * length key_len octets and output tag length of tag_len. Return
  171. * values are:
  172. *
  173. * srtp_err_status_ok no problems
  174. * srtp_err_status_alloc_fail an allocation failure occured
  175. * srtp_err_status_fail couldn't find auth with identifier 'id'
  176. */
  177. srtp_err_status_t srtp_crypto_kernel_alloc_auth(srtp_auth_type_id_t id,
  178. srtp_auth_pointer_t *ap,
  179. int key_len,
  180. int tag_len);
  181. /*
  182. * srtp_crypto_kernel_set_debug_module(mod_name, v)
  183. *
  184. * sets dynamic debugging to the value v (0 for off, 1 for on) for the
  185. * debug module with the name mod_name
  186. *
  187. * returns srtp_err_status_ok on success, srtp_err_status_fail otherwise
  188. */
  189. srtp_err_status_t srtp_crypto_kernel_set_debug_module(const char *mod_name,
  190. int v);
  191. #ifdef __cplusplus
  192. }
  193. #endif
  194. #endif /* CRYPTO_KERNEL */