4
* common interface to authentication functions
12
* Copyright (c) 2001-2006, Cisco Systems, Inc.
13
* All rights reserved.
15
* Redistribution and use in source and binary forms, with or without
16
* modification, are permitted provided that the following conditions
19
* Redistributions of source code must retain the above copyright
20
* notice, this list of conditions and the following disclaimer.
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.
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.
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.
49
#include "datatypes.h"
50
#include "err.h" /* error codes */
52
typedef struct auth_type_t *auth_type_pointer;
53
typedef struct auth_t *auth_pointer_t;
55
typedef err_status_t (*auth_alloc_func)
56
(auth_pointer_t *ap, int key_len, int out_len);
58
typedef err_status_t (*auth_init_func)
59
(void *state, const uint8_t *key, int key_len);
61
typedef err_status_t (*auth_dealloc_func)(auth_pointer_t ap);
63
typedef err_status_t (*auth_compute_func)
64
(void *state, uint8_t *buffer, int octets_to_auth,
65
int tag_len, uint8_t *tag);
67
typedef err_status_t (*auth_update_func)
68
(void *state, uint8_t *buffer, int octets_to_auth);
70
typedef err_status_t (*auth_start_func)(void *state);
72
/* some syntactic sugar on these function types */
74
#define auth_type_alloc(at, a, klen, outlen) \
75
((at)->alloc((a), (klen), (outlen)))
77
#define auth_init(a, key) \
78
(((a)->type)->init((a)->state, (key), ((a)->key_len)))
80
#define auth_compute(a, buf, len, res) \
81
(((a)->type)->compute((a)->state, (buf), (len), (a)->out_len, (res)))
83
#define auth_update(a, buf, len) \
84
(((a)->type)->update((a)->state, (buf), (len)))
86
#define auth_start(a)(((a)->type)->start((a)->state))
88
#define auth_dealloc(c) (((c)->type)->dealloc(c))
90
/* functions to get information about a particular auth_t */
93
auth_get_key_length(const struct auth_t *a);
96
auth_get_tag_length(const struct auth_t *a);
99
auth_get_prefix_length(const struct auth_t *a);
102
* auth_test_case_t is a (list of) key/message/tag values that are
103
* known to be correct for a particular cipher. this data can be used
104
* to test an implementation in an on-the-fly self test of the
105
* correcness of the implementation. (see the auth_type_self_test()
109
typedef struct auth_test_case_t {
110
int key_length_octets; /* octets in key */
111
uint8_t *key; /* key */
112
int data_length_octets; /* octets in data */
113
uint8_t *data; /* data */
114
int tag_length_octets; /* octets in tag */
115
uint8_t *tag; /* tag */
116
struct auth_test_case_t *next_test_case; /* pointer to next testcase */
121
typedef struct auth_type_t {
122
auth_alloc_func alloc;
123
auth_dealloc_func dealloc;
125
auth_compute_func compute;
126
auth_update_func update;
127
auth_start_func start;
130
auth_test_case_t *test_data;
131
debug_module_t *debug;
134
typedef struct auth_t {
137
int out_len; /* length of output tag in octets */
138
int key_len; /* length of key in octets */
139
int prefix_len; /* length of keystream prefix */
143
* auth_type_self_test() tests an auth_type against test cases
144
* provided in an array of values of key/message/tag that is known to
149
auth_type_self_test(const auth_type_t *at);
152
* auth_type_get_ref_count(at) returns the reference count (the number
153
* of instantiations) of the auth_type_t at
157
auth_type_get_ref_count(const auth_type_t *at);