auth.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * auth.h
  3. *
  4. * common interface to authentication functions
  5. *
  6. * David A. McGrew
  7. * Cisco Systems, Inc.
  8. */
  9. /*
  10. *
  11. * Copyright (c) 2001-2006, 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 AUTH_H
  45. #define AUTH_H
  46. #include "datatypes.h"
  47. #include "err.h" /* error codes */
  48. #include "crypto.h" /* for auth_type_id_t */
  49. #include "crypto_types.h" /* for values of auth_type_id_t */
  50. typedef struct auth_type_t *auth_type_pointer;
  51. typedef struct auth_t *auth_pointer_t;
  52. typedef err_status_t (*auth_alloc_func)
  53. (auth_pointer_t *ap, int key_len, int out_len);
  54. typedef err_status_t (*auth_init_func)
  55. (void *state, const uint8_t *key, int key_len);
  56. typedef err_status_t (*auth_dealloc_func)(auth_pointer_t ap);
  57. typedef err_status_t (*auth_compute_func)
  58. (void *state, uint8_t *buffer, int octets_to_auth,
  59. int tag_len, uint8_t *tag);
  60. typedef err_status_t (*auth_update_func)
  61. (void *state, uint8_t *buffer, int octets_to_auth);
  62. typedef err_status_t (*auth_start_func)(void *state);
  63. /* some syntactic sugar on these function types */
  64. #define auth_type_alloc(at, a, klen, outlen) \
  65. ((at)->alloc((a), (klen), (outlen)))
  66. #define auth_init(a, key) \
  67. (((a)->type)->init((a)->state, (key), ((a)->key_len)))
  68. #define auth_compute(a, buf, len, res) \
  69. (((a)->type)->compute((a)->state, (buf), (len), (a)->out_len, (res)))
  70. #define auth_update(a, buf, len) \
  71. (((a)->type)->update((a)->state, (buf), (len)))
  72. #define auth_start(a)(((a)->type)->start((a)->state))
  73. #define auth_dealloc(c) (((c)->type)->dealloc(c))
  74. /* functions to get information about a particular auth_t */
  75. int
  76. auth_get_key_length(const struct auth_t *a);
  77. int
  78. auth_get_tag_length(const struct auth_t *a);
  79. int
  80. auth_get_prefix_length(const struct auth_t *a);
  81. /*
  82. * auth_test_case_t is a (list of) key/message/tag values that are
  83. * known to be correct for a particular cipher. this data can be used
  84. * to test an implementation in an on-the-fly self test of the
  85. * correcness of the implementation. (see the auth_type_self_test()
  86. * function below)
  87. */
  88. typedef struct auth_test_case_t {
  89. int key_length_octets; /* octets in key */
  90. uint8_t *key; /* key */
  91. int data_length_octets; /* octets in data */
  92. uint8_t *data; /* data */
  93. int tag_length_octets; /* octets in tag */
  94. uint8_t *tag; /* tag */
  95. struct auth_test_case_t *next_test_case; /* pointer to next testcase */
  96. } auth_test_case_t;
  97. /* auth_type_t */
  98. typedef struct auth_type_t {
  99. auth_alloc_func alloc;
  100. auth_dealloc_func dealloc;
  101. auth_init_func init;
  102. auth_compute_func compute;
  103. auth_update_func update;
  104. auth_start_func start;
  105. char *description;
  106. int ref_count;
  107. auth_test_case_t *test_data;
  108. debug_module_t *debug;
  109. auth_type_id_t id;
  110. } auth_type_t;
  111. typedef struct auth_t {
  112. auth_type_t *type;
  113. void *state;
  114. int out_len; /* length of output tag in octets */
  115. int key_len; /* length of key in octets */
  116. int prefix_len; /* length of keystream prefix */
  117. } auth_t;
  118. /*
  119. * auth_type_self_test() tests an auth_type against test cases
  120. * provided in an array of values of key/message/tag that is known to
  121. * be good
  122. */
  123. err_status_t
  124. auth_type_self_test(const auth_type_t *at);
  125. /*
  126. * auth_type_test() tests an auth_type against external test cases
  127. * provided in an array of values of key/message/tag that is known to
  128. * be good
  129. */
  130. err_status_t
  131. auth_type_test(const auth_type_t *at, const auth_test_case_t *test_data);
  132. /*
  133. * auth_type_get_ref_count(at) returns the reference count (the number
  134. * of instantiations) of the auth_type_t at
  135. */
  136. int
  137. auth_type_get_ref_count(const auth_type_t *at);
  138. #endif /* AUTH_H */