blob: 301348b666fe5f81fa724f669e5dc79f6b716579 [file] [log] [blame]
Alexandre Lision67916dd2014-01-24 13:33:04 -05001/*
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-2006, 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
48#include "null_auth.h"
49#include "alloc.h"
50
51/* null_auth uses the auth debug module */
52
53extern debug_module_t mod_auth;
54
55err_status_t
56null_auth_alloc(auth_t **a, int key_len, int out_len) {
57 extern auth_type_t null_auth;
58 uint8_t *pointer;
59
60 debug_print(mod_auth, "allocating auth func with key length %d", key_len);
61 debug_print(mod_auth, " tag length %d", out_len);
62
63 /* allocate memory for auth and null_auth_ctx_t structures */
64 pointer = (uint8_t*)crypto_alloc(sizeof(null_auth_ctx_t) + sizeof(auth_t));
65 if (pointer == NULL)
66 return err_status_alloc_fail;
67
68 /* set pointers */
69 *a = (auth_t *)pointer;
70 (*a)->type = &null_auth;
71 (*a)->state = pointer + sizeof (auth_t);
72 (*a)->out_len = out_len;
73 (*a)->prefix_len = out_len;
74 (*a)->key_len = key_len;
75
76 /* increment global count of all null_auth uses */
77 null_auth.ref_count++;
78
79 return err_status_ok;
80}
81
82err_status_t
83null_auth_dealloc(auth_t *a) {
84 extern auth_type_t null_auth;
85
86 /* zeroize entire state*/
87 octet_string_set_to_zero((uint8_t *)a,
88 sizeof(null_auth_ctx_t) + sizeof(auth_t));
89
90 /* free memory */
91 crypto_free(a);
92
93 /* decrement global count of all null_auth uses */
94 null_auth.ref_count--;
95
96 return err_status_ok;
97}
98
99err_status_t
100null_auth_init(null_auth_ctx_t *state, const uint8_t *key, int key_len) {
101
102 /* accept any length of key, and do nothing */
103
104 return err_status_ok;
105}
106
107err_status_t
108null_auth_compute(null_auth_ctx_t *state, uint8_t *message,
109 int msg_octets, int tag_len, uint8_t *result) {
110
111 return err_status_ok;
112}
113
114err_status_t
115null_auth_update(null_auth_ctx_t *state, uint8_t *message,
116 int msg_octets) {
117
118 return err_status_ok;
119}
120
121err_status_t
122null_auth_start(null_auth_ctx_t *state) {
123 return err_status_ok;
124}
125
126/*
127 * auth_type_t - defines description, test case, and null_auth
128 * metaobject
129 */
130
131/* begin test case 0 */
132
133auth_test_case_t
134null_auth_test_case_0 = {
135 0, /* octets in key */
136 NULL, /* key */
137 0, /* octets in data */
138 NULL, /* data */
139 0, /* octets in tag */
140 NULL, /* tag */
141 NULL /* pointer to next testcase */
142};
143
144/* end test case 0 */
145
146char null_auth_description[] = "null authentication function";
147
148auth_type_t
149null_auth = {
150 (auth_alloc_func) null_auth_alloc,
151 (auth_dealloc_func) null_auth_dealloc,
152 (auth_init_func) null_auth_init,
153 (auth_compute_func) null_auth_compute,
154 (auth_update_func) null_auth_update,
155 (auth_start_func) null_auth_start,
156 (char *) null_auth_description,
157 (int) 0, /* instance count */
158 (auth_test_case_t *) &null_auth_test_case_0
159};
160