1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/srtp/src/crypto/include/auth.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,171 @@ 1.4 +/* 1.5 + * auth.h 1.6 + * 1.7 + * common interface to authentication functions 1.8 + * 1.9 + * David A. McGrew 1.10 + * Cisco Systems, Inc. 1.11 + */ 1.12 + 1.13 +/* 1.14 + * 1.15 + * Copyright (c) 2001-2006, Cisco Systems, Inc. 1.16 + * All rights reserved. 1.17 + * 1.18 + * Redistribution and use in source and binary forms, with or without 1.19 + * modification, are permitted provided that the following conditions 1.20 + * are met: 1.21 + * 1.22 + * Redistributions of source code must retain the above copyright 1.23 + * notice, this list of conditions and the following disclaimer. 1.24 + * 1.25 + * Redistributions in binary form must reproduce the above 1.26 + * copyright notice, this list of conditions and the following 1.27 + * disclaimer in the documentation and/or other materials provided 1.28 + * with the distribution. 1.29 + * 1.30 + * Neither the name of the Cisco Systems, Inc. nor the names of its 1.31 + * contributors may be used to endorse or promote products derived 1.32 + * from this software without specific prior written permission. 1.33 + * 1.34 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.35 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.36 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1.37 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1.38 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 1.39 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 1.40 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 1.41 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.42 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 1.43 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.44 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 1.45 + * OF THE POSSIBILITY OF SUCH DAMAGE. 1.46 + * 1.47 + */ 1.48 + 1.49 +#ifndef AUTH_H 1.50 +#define AUTH_H 1.51 + 1.52 +#include "datatypes.h" 1.53 +#include "err.h" /* error codes */ 1.54 +#include "crypto.h" /* for auth_type_id_t */ 1.55 +#include "crypto_types.h" /* for values of auth_type_id_t */ 1.56 + 1.57 +typedef struct auth_type_t *auth_type_pointer; 1.58 +typedef struct auth_t *auth_pointer_t; 1.59 + 1.60 +typedef err_status_t (*auth_alloc_func) 1.61 + (auth_pointer_t *ap, int key_len, int out_len); 1.62 + 1.63 +typedef err_status_t (*auth_init_func) 1.64 + (void *state, const uint8_t *key, int key_len); 1.65 + 1.66 +typedef err_status_t (*auth_dealloc_func)(auth_pointer_t ap); 1.67 + 1.68 +typedef err_status_t (*auth_compute_func) 1.69 + (void *state, uint8_t *buffer, int octets_to_auth, 1.70 + int tag_len, uint8_t *tag); 1.71 + 1.72 +typedef err_status_t (*auth_update_func) 1.73 + (void *state, uint8_t *buffer, int octets_to_auth); 1.74 + 1.75 +typedef err_status_t (*auth_start_func)(void *state); 1.76 + 1.77 +/* some syntactic sugar on these function types */ 1.78 + 1.79 +#define auth_type_alloc(at, a, klen, outlen) \ 1.80 + ((at)->alloc((a), (klen), (outlen))) 1.81 + 1.82 +#define auth_init(a, key) \ 1.83 + (((a)->type)->init((a)->state, (key), ((a)->key_len))) 1.84 + 1.85 +#define auth_compute(a, buf, len, res) \ 1.86 + (((a)->type)->compute((a)->state, (buf), (len), (a)->out_len, (res))) 1.87 + 1.88 +#define auth_update(a, buf, len) \ 1.89 + (((a)->type)->update((a)->state, (buf), (len))) 1.90 + 1.91 +#define auth_start(a)(((a)->type)->start((a)->state)) 1.92 + 1.93 +#define auth_dealloc(c) (((c)->type)->dealloc(c)) 1.94 + 1.95 +/* functions to get information about a particular auth_t */ 1.96 + 1.97 +int 1.98 +auth_get_key_length(const struct auth_t *a); 1.99 + 1.100 +int 1.101 +auth_get_tag_length(const struct auth_t *a); 1.102 + 1.103 +int 1.104 +auth_get_prefix_length(const struct auth_t *a); 1.105 + 1.106 +/* 1.107 + * auth_test_case_t is a (list of) key/message/tag values that are 1.108 + * known to be correct for a particular cipher. this data can be used 1.109 + * to test an implementation in an on-the-fly self test of the 1.110 + * correcness of the implementation. (see the auth_type_self_test() 1.111 + * function below) 1.112 + */ 1.113 + 1.114 +typedef struct auth_test_case_t { 1.115 + int key_length_octets; /* octets in key */ 1.116 + uint8_t *key; /* key */ 1.117 + int data_length_octets; /* octets in data */ 1.118 + uint8_t *data; /* data */ 1.119 + int tag_length_octets; /* octets in tag */ 1.120 + uint8_t *tag; /* tag */ 1.121 + struct auth_test_case_t *next_test_case; /* pointer to next testcase */ 1.122 +} auth_test_case_t; 1.123 + 1.124 +/* auth_type_t */ 1.125 + 1.126 +typedef struct auth_type_t { 1.127 + auth_alloc_func alloc; 1.128 + auth_dealloc_func dealloc; 1.129 + auth_init_func init; 1.130 + auth_compute_func compute; 1.131 + auth_update_func update; 1.132 + auth_start_func start; 1.133 + char *description; 1.134 + int ref_count; 1.135 + auth_test_case_t *test_data; 1.136 + debug_module_t *debug; 1.137 + auth_type_id_t id; 1.138 +} auth_type_t; 1.139 + 1.140 +typedef struct auth_t { 1.141 + auth_type_t *type; 1.142 + void *state; 1.143 + int out_len; /* length of output tag in octets */ 1.144 + int key_len; /* length of key in octets */ 1.145 + int prefix_len; /* length of keystream prefix */ 1.146 +} auth_t; 1.147 + 1.148 +/* 1.149 + * auth_type_self_test() tests an auth_type against test cases 1.150 + * provided in an array of values of key/message/tag that is known to 1.151 + * be good 1.152 + */ 1.153 + 1.154 +err_status_t 1.155 +auth_type_self_test(const auth_type_t *at); 1.156 + 1.157 +/* 1.158 + * auth_type_test() tests an auth_type against external test cases 1.159 + * provided in an array of values of key/message/tag that is known to 1.160 + * be good 1.161 + */ 1.162 + 1.163 +err_status_t 1.164 +auth_type_test(const auth_type_t *at, const auth_test_case_t *test_data); 1.165 + 1.166 +/* 1.167 + * auth_type_get_ref_count(at) returns the reference count (the number 1.168 + * of instantiations) of the auth_type_t at 1.169 + */ 1.170 + 1.171 +int 1.172 +auth_type_get_ref_count(const auth_type_t *at); 1.173 + 1.174 +#endif /* AUTH_H */