michael@0: /* michael@0: * auth.h michael@0: * michael@0: * common interface to authentication functions michael@0: * michael@0: * David A. McGrew michael@0: * Cisco Systems, Inc. michael@0: */ michael@0: michael@0: /* michael@0: * michael@0: * Copyright (c) 2001-2006, Cisco Systems, Inc. michael@0: * All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * michael@0: * Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * michael@0: * Redistributions in binary form must reproduce the above michael@0: * copyright notice, this list of conditions and the following michael@0: * disclaimer in the documentation and/or other materials provided michael@0: * with the distribution. michael@0: * michael@0: * Neither the name of the Cisco Systems, Inc. nor the names of its michael@0: * contributors may be used to endorse or promote products derived michael@0: * from this software without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS michael@0: * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE michael@0: * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, michael@0: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES michael@0: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR michael@0: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) michael@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, michael@0: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) michael@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED michael@0: * OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: * michael@0: */ michael@0: michael@0: #ifndef AUTH_H michael@0: #define AUTH_H michael@0: michael@0: #include "datatypes.h" michael@0: #include "err.h" /* error codes */ michael@0: #include "crypto.h" /* for auth_type_id_t */ michael@0: #include "crypto_types.h" /* for values of auth_type_id_t */ michael@0: michael@0: typedef struct auth_type_t *auth_type_pointer; michael@0: typedef struct auth_t *auth_pointer_t; michael@0: michael@0: typedef err_status_t (*auth_alloc_func) michael@0: (auth_pointer_t *ap, int key_len, int out_len); michael@0: michael@0: typedef err_status_t (*auth_init_func) michael@0: (void *state, const uint8_t *key, int key_len); michael@0: michael@0: typedef err_status_t (*auth_dealloc_func)(auth_pointer_t ap); michael@0: michael@0: typedef err_status_t (*auth_compute_func) michael@0: (void *state, uint8_t *buffer, int octets_to_auth, michael@0: int tag_len, uint8_t *tag); michael@0: michael@0: typedef err_status_t (*auth_update_func) michael@0: (void *state, uint8_t *buffer, int octets_to_auth); michael@0: michael@0: typedef err_status_t (*auth_start_func)(void *state); michael@0: michael@0: /* some syntactic sugar on these function types */ michael@0: michael@0: #define auth_type_alloc(at, a, klen, outlen) \ michael@0: ((at)->alloc((a), (klen), (outlen))) michael@0: michael@0: #define auth_init(a, key) \ michael@0: (((a)->type)->init((a)->state, (key), ((a)->key_len))) michael@0: michael@0: #define auth_compute(a, buf, len, res) \ michael@0: (((a)->type)->compute((a)->state, (buf), (len), (a)->out_len, (res))) michael@0: michael@0: #define auth_update(a, buf, len) \ michael@0: (((a)->type)->update((a)->state, (buf), (len))) michael@0: michael@0: #define auth_start(a)(((a)->type)->start((a)->state)) michael@0: michael@0: #define auth_dealloc(c) (((c)->type)->dealloc(c)) michael@0: michael@0: /* functions to get information about a particular auth_t */ michael@0: michael@0: int michael@0: auth_get_key_length(const struct auth_t *a); michael@0: michael@0: int michael@0: auth_get_tag_length(const struct auth_t *a); michael@0: michael@0: int michael@0: auth_get_prefix_length(const struct auth_t *a); michael@0: michael@0: /* michael@0: * auth_test_case_t is a (list of) key/message/tag values that are michael@0: * known to be correct for a particular cipher. this data can be used michael@0: * to test an implementation in an on-the-fly self test of the michael@0: * correcness of the implementation. (see the auth_type_self_test() michael@0: * function below) michael@0: */ michael@0: michael@0: typedef struct auth_test_case_t { michael@0: int key_length_octets; /* octets in key */ michael@0: uint8_t *key; /* key */ michael@0: int data_length_octets; /* octets in data */ michael@0: uint8_t *data; /* data */ michael@0: int tag_length_octets; /* octets in tag */ michael@0: uint8_t *tag; /* tag */ michael@0: struct auth_test_case_t *next_test_case; /* pointer to next testcase */ michael@0: } auth_test_case_t; michael@0: michael@0: /* auth_type_t */ michael@0: michael@0: typedef struct auth_type_t { michael@0: auth_alloc_func alloc; michael@0: auth_dealloc_func dealloc; michael@0: auth_init_func init; michael@0: auth_compute_func compute; michael@0: auth_update_func update; michael@0: auth_start_func start; michael@0: char *description; michael@0: int ref_count; michael@0: auth_test_case_t *test_data; michael@0: debug_module_t *debug; michael@0: auth_type_id_t id; michael@0: } auth_type_t; michael@0: michael@0: typedef struct auth_t { michael@0: auth_type_t *type; michael@0: void *state; michael@0: int out_len; /* length of output tag in octets */ michael@0: int key_len; /* length of key in octets */ michael@0: int prefix_len; /* length of keystream prefix */ michael@0: } auth_t; michael@0: michael@0: /* michael@0: * auth_type_self_test() tests an auth_type against test cases michael@0: * provided in an array of values of key/message/tag that is known to michael@0: * be good michael@0: */ michael@0: michael@0: err_status_t michael@0: auth_type_self_test(const auth_type_t *at); michael@0: michael@0: /* michael@0: * auth_type_test() tests an auth_type against external test cases michael@0: * provided in an array of values of key/message/tag that is known to michael@0: * be good michael@0: */ michael@0: michael@0: err_status_t michael@0: auth_type_test(const auth_type_t *at, const auth_test_case_t *test_data); michael@0: michael@0: /* michael@0: * auth_type_get_ref_count(at) returns the reference count (the number michael@0: * of instantiations) of the auth_type_t at michael@0: */ michael@0: michael@0: int michael@0: auth_type_get_ref_count(const auth_type_t *at); michael@0: michael@0: #endif /* AUTH_H */