null_auth.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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-2017, 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. #ifdef HAVE_CONFIG_H
  46. #include <config.h>
  47. #endif
  48. #include "null_auth.h"
  49. #include "err.h" /* for srtp_debug */
  50. #include "alloc.h"
  51. #include "cipher_types.h"
  52. static srtp_err_status_t srtp_null_auth_alloc(srtp_auth_t **a,
  53. int key_len,
  54. int out_len)
  55. {
  56. extern const srtp_auth_type_t srtp_null_auth;
  57. uint8_t *pointer;
  58. debug_print(srtp_mod_auth, "allocating auth func with key length %d",
  59. key_len);
  60. debug_print(srtp_mod_auth, " tag length %d",
  61. out_len);
  62. /* allocate memory for auth and srtp_null_auth_ctx_t structures */
  63. pointer = (uint8_t *)srtp_crypto_alloc(sizeof(srtp_null_auth_ctx_t) +
  64. sizeof(srtp_auth_t));
  65. if (pointer == NULL) {
  66. return srtp_err_status_alloc_fail;
  67. }
  68. /* set pointers */
  69. *a = (srtp_auth_t *)pointer;
  70. (*a)->type = &srtp_null_auth;
  71. (*a)->state = pointer + sizeof(srtp_auth_t);
  72. (*a)->out_len = out_len;
  73. (*a)->prefix_len = out_len;
  74. (*a)->key_len = key_len;
  75. return srtp_err_status_ok;
  76. }
  77. static srtp_err_status_t srtp_null_auth_dealloc(srtp_auth_t *a)
  78. {
  79. extern const srtp_auth_type_t srtp_null_auth;
  80. /* zeroize entire state*/
  81. octet_string_set_to_zero(a, sizeof(srtp_null_auth_ctx_t) +
  82. sizeof(srtp_auth_t));
  83. /* free memory */
  84. srtp_crypto_free(a);
  85. return srtp_err_status_ok;
  86. }
  87. static srtp_err_status_t srtp_null_auth_init(void *statev,
  88. const uint8_t *key,
  89. int key_len)
  90. {
  91. /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
  92. /* accept any length of key, and do nothing */
  93. return srtp_err_status_ok;
  94. }
  95. static srtp_err_status_t srtp_null_auth_compute(void *statev,
  96. const uint8_t *message,
  97. int msg_octets,
  98. int tag_len,
  99. uint8_t *result)
  100. {
  101. /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
  102. return srtp_err_status_ok;
  103. }
  104. static srtp_err_status_t srtp_null_auth_update(void *statev,
  105. const uint8_t *message,
  106. int msg_octets)
  107. {
  108. /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
  109. return srtp_err_status_ok;
  110. }
  111. static srtp_err_status_t srtp_null_auth_start(void *statev)
  112. {
  113. /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
  114. return srtp_err_status_ok;
  115. }
  116. /*
  117. * srtp_auth_type_t - defines description, test case, and null_auth
  118. * metaobject
  119. */
  120. /* begin test case 0 */
  121. static const srtp_auth_test_case_t srtp_null_auth_test_case_0 = {
  122. 0, /* octets in key */
  123. NULL, /* key */
  124. 0, /* octets in data */
  125. NULL, /* data */
  126. 0, /* octets in tag */
  127. NULL, /* tag */
  128. NULL /* pointer to next testcase */
  129. };
  130. /* end test case 0 */
  131. static const char srtp_null_auth_description[] = "null authentication function";
  132. const srtp_auth_type_t srtp_null_auth = {
  133. srtp_null_auth_alloc, /* */
  134. srtp_null_auth_dealloc, /* */
  135. srtp_null_auth_init, /* */
  136. srtp_null_auth_compute, /* */
  137. srtp_null_auth_update, /* */
  138. srtp_null_auth_start, /* */
  139. srtp_null_auth_description, /* */
  140. &srtp_null_auth_test_case_0, /* */
  141. SRTP_NULL_AUTH /* */
  142. };