2
0

null_auth.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * null_auth.c
  3. *
  4. * implements the do-nothing auth algorithm
  5. *
  6. * David A. McGrew
  7. * Cisco Systems, Inc.
  8. *
  9. */
  10. /*
  11. *
  12. * Copyright (c) 2001-2006, Cisco Systems, Inc.
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions
  17. * are met:
  18. *
  19. * Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. *
  22. * Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials provided
  25. * with the distribution.
  26. *
  27. * Neither the name of the Cisco Systems, Inc. nor the names of its
  28. * contributors may be used to endorse or promote products derived
  29. * from this software without specific prior written permission.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  34. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  35. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  36. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  37. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  38. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  42. * OF THE POSSIBILITY OF SUCH DAMAGE.
  43. *
  44. */
  45. #include "null_auth.h"
  46. #include "alloc.h"
  47. /* null_auth uses the auth debug module */
  48. extern debug_module_t mod_auth;
  49. err_status_t
  50. null_auth_alloc(auth_t **a, int key_len, int out_len) {
  51. extern auth_type_t null_auth;
  52. uint8_t *pointer;
  53. debug_print(mod_auth, "allocating auth func with key length %d", key_len);
  54. debug_print(mod_auth, " tag length %d", out_len);
  55. /* allocate memory for auth and null_auth_ctx_t structures */
  56. pointer = (uint8_t*)crypto_alloc(sizeof(null_auth_ctx_t) + sizeof(auth_t));
  57. if (pointer == NULL)
  58. return err_status_alloc_fail;
  59. /* set pointers */
  60. *a = (auth_t *)pointer;
  61. (*a)->type = &null_auth;
  62. (*a)->state = pointer + sizeof (auth_t);
  63. (*a)->out_len = out_len;
  64. (*a)->prefix_len = out_len;
  65. (*a)->key_len = key_len;
  66. /* increment global count of all null_auth uses */
  67. null_auth.ref_count++;
  68. return err_status_ok;
  69. }
  70. err_status_t
  71. null_auth_dealloc(auth_t *a) {
  72. extern auth_type_t null_auth;
  73. /* zeroize entire state*/
  74. octet_string_set_to_zero((uint8_t *)a,
  75. sizeof(null_auth_ctx_t) + sizeof(auth_t));
  76. /* free memory */
  77. crypto_free(a);
  78. /* decrement global count of all null_auth uses */
  79. null_auth.ref_count--;
  80. return err_status_ok;
  81. }
  82. err_status_t
  83. null_auth_init(null_auth_ctx_t *state, const uint8_t *key, int key_len) {
  84. /* accept any length of key, and do nothing */
  85. return err_status_ok;
  86. }
  87. err_status_t
  88. null_auth_compute(null_auth_ctx_t *state, uint8_t *message,
  89. int msg_octets, int tag_len, uint8_t *result) {
  90. return err_status_ok;
  91. }
  92. err_status_t
  93. null_auth_update(null_auth_ctx_t *state, uint8_t *message,
  94. int msg_octets) {
  95. return err_status_ok;
  96. }
  97. err_status_t
  98. null_auth_start(null_auth_ctx_t *state) {
  99. return err_status_ok;
  100. }
  101. /*
  102. * auth_type_t - defines description, test case, and null_auth
  103. * metaobject
  104. */
  105. /* begin test case 0 */
  106. auth_test_case_t
  107. null_auth_test_case_0 = {
  108. 0, /* octets in key */
  109. NULL, /* key */
  110. 0, /* octets in data */
  111. NULL, /* data */
  112. 0, /* octets in tag */
  113. NULL, /* tag */
  114. NULL /* pointer to next testcase */
  115. };
  116. /* end test case 0 */
  117. char null_auth_description[] = "null authentication function";
  118. auth_type_t
  119. null_auth = {
  120. (auth_alloc_func) null_auth_alloc,
  121. (auth_dealloc_func) null_auth_dealloc,
  122. (auth_init_func) null_auth_init,
  123. (auth_compute_func) null_auth_compute,
  124. (auth_update_func) null_auth_update,
  125. (auth_start_func) null_auth_start,
  126. (char *) null_auth_description,
  127. (int) 0, /* instance count */
  128. (auth_test_case_t *) &null_auth_test_case_0,
  129. (debug_module_t *) NULL,
  130. (auth_type_id_t) NULL_AUTH
  131. };