• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  *
13  * Copyright (c) 2001-2017, Cisco Systems, Inc.
14  * All rights reserved.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  *
20  *   Redistributions of source code must retain the above copyright
21  *   notice, this list of conditions and the following disclaimer.
22  *
23  *   Redistributions in binary form must reproduce the above
24  *   copyright notice, this list of conditions and the following
25  *   disclaimer in the documentation and/or other materials provided
26  *   with the distribution.
27  *
28  *   Neither the name of the Cisco Systems, Inc. nor the names of its
29  *   contributors may be used to endorse or promote products derived
30  *   from this software without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
35  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
36  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
37  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
39  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
43  * OF THE POSSIBILITY OF SUCH DAMAGE.
44  *
45  */
46 
47 #ifdef HAVE_CONFIG_H
48 #include <config.h>
49 #endif
50 
51 #include "null_auth.h"
52 #include "err.h" /* for srtp_debug */
53 #include "alloc.h"
54 #include "cipher_types.h"
55 
srtp_null_auth_alloc(srtp_auth_t ** a,int key_len,int out_len)56 static srtp_err_status_t srtp_null_auth_alloc(srtp_auth_t **a,
57                                               int key_len,
58                                               int out_len)
59 {
60     extern const srtp_auth_type_t srtp_null_auth;
61     uint8_t *pointer;
62 
63     debug_print(srtp_mod_auth, "allocating auth func with key length %d",
64                 key_len);
65     debug_print(srtp_mod_auth, "                          tag length %d",
66                 out_len);
67 
68     /* allocate memory for auth and srtp_null_auth_ctx_t structures */
69     pointer = (uint8_t *)srtp_crypto_alloc(sizeof(srtp_null_auth_ctx_t) +
70                                            sizeof(srtp_auth_t));
71     if (pointer == NULL) {
72         return srtp_err_status_alloc_fail;
73     }
74 
75     /* set pointers */
76     *a = (srtp_auth_t *)pointer;
77     (*a)->type = &srtp_null_auth;
78     (*a)->state = pointer + sizeof(srtp_auth_t);
79     (*a)->out_len = out_len;
80     (*a)->prefix_len = out_len;
81     (*a)->key_len = key_len;
82 
83     return srtp_err_status_ok;
84 }
85 
srtp_null_auth_dealloc(srtp_auth_t * a)86 static srtp_err_status_t srtp_null_auth_dealloc(srtp_auth_t *a)
87 {
88     extern const srtp_auth_type_t srtp_null_auth;
89 
90     /* zeroize entire state*/
91     octet_string_set_to_zero(a, sizeof(srtp_null_auth_ctx_t) +
92                                     sizeof(srtp_auth_t));
93 
94     /* free memory */
95     srtp_crypto_free(a);
96 
97     return srtp_err_status_ok;
98 }
99 
srtp_null_auth_init(void * statev,const uint8_t * key,int key_len)100 static srtp_err_status_t srtp_null_auth_init(void *statev,
101                                              const uint8_t *key,
102                                              int key_len)
103 {
104     /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
105     /* accept any length of key, and do nothing */
106 
107     return srtp_err_status_ok;
108 }
109 
srtp_null_auth_compute(void * statev,const uint8_t * message,int msg_octets,int tag_len,uint8_t * result)110 static srtp_err_status_t srtp_null_auth_compute(void *statev,
111                                                 const uint8_t *message,
112                                                 int msg_octets,
113                                                 int tag_len,
114                                                 uint8_t *result)
115 {
116     /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
117 
118     return srtp_err_status_ok;
119 }
120 
srtp_null_auth_update(void * statev,const uint8_t * message,int msg_octets)121 static srtp_err_status_t srtp_null_auth_update(void *statev,
122                                                const uint8_t *message,
123                                                int msg_octets)
124 {
125     /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
126 
127     return srtp_err_status_ok;
128 }
129 
srtp_null_auth_start(void * statev)130 static srtp_err_status_t srtp_null_auth_start(void *statev)
131 {
132     /* srtp_null_auth_ctx_t *state = (srtp_null_auth_ctx_t *)statev; */
133 
134     return srtp_err_status_ok;
135 }
136 
137 /*
138  * srtp_auth_type_t - defines description, test case, and null_auth
139  * metaobject
140  */
141 
142 /* begin test case 0 */
143 
144 static const srtp_auth_test_case_t srtp_null_auth_test_case_0 = {
145     0,    /* octets in key            */
146     NULL, /* key                      */
147     0,    /* octets in data           */
148     NULL, /* data                     */
149     0,    /* octets in tag            */
150     NULL, /* tag                      */
151     NULL  /* pointer to next testcase */
152 };
153 
154 /* end test case 0 */
155 
156 static const char srtp_null_auth_description[] = "null authentication function";
157 
158 const srtp_auth_type_t srtp_null_auth = {
159     srtp_null_auth_alloc,        /* */
160     srtp_null_auth_dealloc,      /* */
161     srtp_null_auth_init,         /* */
162     srtp_null_auth_compute,      /* */
163     srtp_null_auth_update,       /* */
164     srtp_null_auth_start,        /* */
165     srtp_null_auth_description,  /* */
166     &srtp_null_auth_test_case_0, /* */
167     SRTP_NULL_AUTH               /* */
168 };
169