null_auth.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. (void)statev;
  93. (void)key;
  94. (void)key_len;
  95. /* accept any length of key, and do nothing */
  96. return srtp_err_status_ok;
  97. }
  98. static srtp_err_status_t srtp_null_auth_compute(void *statev,
  99. const uint8_t *message,
  100. int msg_octets,
  101. int tag_len,
  102. uint8_t *result)
  103. {
  104. /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
  105. (void)statev;
  106. (void)message;
  107. (void)msg_octets;
  108. (void)tag_len;
  109. (void)result;
  110. return srtp_err_status_ok;
  111. }
  112. static srtp_err_status_t srtp_null_auth_update(void *statev,
  113. const uint8_t *message,
  114. int msg_octets)
  115. {
  116. /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
  117. (void)statev;
  118. (void)message;
  119. (void)msg_octets;
  120. return srtp_err_status_ok;
  121. }
  122. static srtp_err_status_t srtp_null_auth_start(void *statev)
  123. {
  124. /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
  125. (void)statev;
  126. return srtp_err_status_ok;
  127. }
  128. /*
  129. * srtp_auth_type_t - defines description, test case, and null_auth
  130. * metaobject
  131. */
  132. /* begin test case 0 */
  133. static const srtp_auth_test_case_t srtp_null_auth_test_case_0 = {
  134. 0, /* octets in key */
  135. NULL, /* key */
  136. 0, /* octets in data */
  137. NULL, /* data */
  138. 0, /* octets in tag */
  139. NULL, /* tag */
  140. NULL /* pointer to next testcase */
  141. };
  142. /* end test case 0 */
  143. static const char srtp_null_auth_description[] = "null authentication function";
  144. const srtp_auth_type_t srtp_null_auth = {
  145. srtp_null_auth_alloc, /* */
  146. srtp_null_auth_dealloc, /* */
  147. srtp_null_auth_init, /* */
  148. srtp_null_auth_compute, /* */
  149. srtp_null_auth_update, /* */
  150. srtp_null_auth_start, /* */
  151. srtp_null_auth_description, /* */
  152. &srtp_null_auth_test_case_0, /* */
  153. SRTP_NULL_AUTH /* */
  154. };