Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * auth.h |
michael@0 | 3 | * |
michael@0 | 4 | * common interface to authentication functions |
michael@0 | 5 | * |
michael@0 | 6 | * David A. McGrew |
michael@0 | 7 | * Cisco Systems, Inc. |
michael@0 | 8 | */ |
michael@0 | 9 | |
michael@0 | 10 | /* |
michael@0 | 11 | * |
michael@0 | 12 | * Copyright (c) 2001-2006, Cisco Systems, Inc. |
michael@0 | 13 | * All rights reserved. |
michael@0 | 14 | * |
michael@0 | 15 | * Redistribution and use in source and binary forms, with or without |
michael@0 | 16 | * modification, are permitted provided that the following conditions |
michael@0 | 17 | * are met: |
michael@0 | 18 | * |
michael@0 | 19 | * Redistributions of source code must retain the above copyright |
michael@0 | 20 | * notice, this list of conditions and the following disclaimer. |
michael@0 | 21 | * |
michael@0 | 22 | * Redistributions in binary form must reproduce the above |
michael@0 | 23 | * copyright notice, this list of conditions and the following |
michael@0 | 24 | * disclaimer in the documentation and/or other materials provided |
michael@0 | 25 | * with the distribution. |
michael@0 | 26 | * |
michael@0 | 27 | * Neither the name of the Cisco Systems, Inc. nor the names of its |
michael@0 | 28 | * contributors may be used to endorse or promote products derived |
michael@0 | 29 | * from this software without specific prior written permission. |
michael@0 | 30 | * |
michael@0 | 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
michael@0 | 34 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
michael@0 | 35 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
michael@0 | 36 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
michael@0 | 37 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
michael@0 | 38 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
michael@0 | 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
michael@0 | 40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
michael@0 | 41 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
michael@0 | 42 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 43 | * |
michael@0 | 44 | */ |
michael@0 | 45 | |
michael@0 | 46 | #ifndef AUTH_H |
michael@0 | 47 | #define AUTH_H |
michael@0 | 48 | |
michael@0 | 49 | #include "datatypes.h" |
michael@0 | 50 | #include "err.h" /* error codes */ |
michael@0 | 51 | #include "crypto.h" /* for auth_type_id_t */ |
michael@0 | 52 | #include "crypto_types.h" /* for values of auth_type_id_t */ |
michael@0 | 53 | |
michael@0 | 54 | typedef struct auth_type_t *auth_type_pointer; |
michael@0 | 55 | typedef struct auth_t *auth_pointer_t; |
michael@0 | 56 | |
michael@0 | 57 | typedef err_status_t (*auth_alloc_func) |
michael@0 | 58 | (auth_pointer_t *ap, int key_len, int out_len); |
michael@0 | 59 | |
michael@0 | 60 | typedef err_status_t (*auth_init_func) |
michael@0 | 61 | (void *state, const uint8_t *key, int key_len); |
michael@0 | 62 | |
michael@0 | 63 | typedef err_status_t (*auth_dealloc_func)(auth_pointer_t ap); |
michael@0 | 64 | |
michael@0 | 65 | typedef err_status_t (*auth_compute_func) |
michael@0 | 66 | (void *state, uint8_t *buffer, int octets_to_auth, |
michael@0 | 67 | int tag_len, uint8_t *tag); |
michael@0 | 68 | |
michael@0 | 69 | typedef err_status_t (*auth_update_func) |
michael@0 | 70 | (void *state, uint8_t *buffer, int octets_to_auth); |
michael@0 | 71 | |
michael@0 | 72 | typedef err_status_t (*auth_start_func)(void *state); |
michael@0 | 73 | |
michael@0 | 74 | /* some syntactic sugar on these function types */ |
michael@0 | 75 | |
michael@0 | 76 | #define auth_type_alloc(at, a, klen, outlen) \ |
michael@0 | 77 | ((at)->alloc((a), (klen), (outlen))) |
michael@0 | 78 | |
michael@0 | 79 | #define auth_init(a, key) \ |
michael@0 | 80 | (((a)->type)->init((a)->state, (key), ((a)->key_len))) |
michael@0 | 81 | |
michael@0 | 82 | #define auth_compute(a, buf, len, res) \ |
michael@0 | 83 | (((a)->type)->compute((a)->state, (buf), (len), (a)->out_len, (res))) |
michael@0 | 84 | |
michael@0 | 85 | #define auth_update(a, buf, len) \ |
michael@0 | 86 | (((a)->type)->update((a)->state, (buf), (len))) |
michael@0 | 87 | |
michael@0 | 88 | #define auth_start(a)(((a)->type)->start((a)->state)) |
michael@0 | 89 | |
michael@0 | 90 | #define auth_dealloc(c) (((c)->type)->dealloc(c)) |
michael@0 | 91 | |
michael@0 | 92 | /* functions to get information about a particular auth_t */ |
michael@0 | 93 | |
michael@0 | 94 | int |
michael@0 | 95 | auth_get_key_length(const struct auth_t *a); |
michael@0 | 96 | |
michael@0 | 97 | int |
michael@0 | 98 | auth_get_tag_length(const struct auth_t *a); |
michael@0 | 99 | |
michael@0 | 100 | int |
michael@0 | 101 | auth_get_prefix_length(const struct auth_t *a); |
michael@0 | 102 | |
michael@0 | 103 | /* |
michael@0 | 104 | * auth_test_case_t is a (list of) key/message/tag values that are |
michael@0 | 105 | * known to be correct for a particular cipher. this data can be used |
michael@0 | 106 | * to test an implementation in an on-the-fly self test of the |
michael@0 | 107 | * correcness of the implementation. (see the auth_type_self_test() |
michael@0 | 108 | * function below) |
michael@0 | 109 | */ |
michael@0 | 110 | |
michael@0 | 111 | typedef struct auth_test_case_t { |
michael@0 | 112 | int key_length_octets; /* octets in key */ |
michael@0 | 113 | uint8_t *key; /* key */ |
michael@0 | 114 | int data_length_octets; /* octets in data */ |
michael@0 | 115 | uint8_t *data; /* data */ |
michael@0 | 116 | int tag_length_octets; /* octets in tag */ |
michael@0 | 117 | uint8_t *tag; /* tag */ |
michael@0 | 118 | struct auth_test_case_t *next_test_case; /* pointer to next testcase */ |
michael@0 | 119 | } auth_test_case_t; |
michael@0 | 120 | |
michael@0 | 121 | /* auth_type_t */ |
michael@0 | 122 | |
michael@0 | 123 | typedef struct auth_type_t { |
michael@0 | 124 | auth_alloc_func alloc; |
michael@0 | 125 | auth_dealloc_func dealloc; |
michael@0 | 126 | auth_init_func init; |
michael@0 | 127 | auth_compute_func compute; |
michael@0 | 128 | auth_update_func update; |
michael@0 | 129 | auth_start_func start; |
michael@0 | 130 | char *description; |
michael@0 | 131 | int ref_count; |
michael@0 | 132 | auth_test_case_t *test_data; |
michael@0 | 133 | debug_module_t *debug; |
michael@0 | 134 | auth_type_id_t id; |
michael@0 | 135 | } auth_type_t; |
michael@0 | 136 | |
michael@0 | 137 | typedef struct auth_t { |
michael@0 | 138 | auth_type_t *type; |
michael@0 | 139 | void *state; |
michael@0 | 140 | int out_len; /* length of output tag in octets */ |
michael@0 | 141 | int key_len; /* length of key in octets */ |
michael@0 | 142 | int prefix_len; /* length of keystream prefix */ |
michael@0 | 143 | } auth_t; |
michael@0 | 144 | |
michael@0 | 145 | /* |
michael@0 | 146 | * auth_type_self_test() tests an auth_type against test cases |
michael@0 | 147 | * provided in an array of values of key/message/tag that is known to |
michael@0 | 148 | * be good |
michael@0 | 149 | */ |
michael@0 | 150 | |
michael@0 | 151 | err_status_t |
michael@0 | 152 | auth_type_self_test(const auth_type_t *at); |
michael@0 | 153 | |
michael@0 | 154 | /* |
michael@0 | 155 | * auth_type_test() tests an auth_type against external test cases |
michael@0 | 156 | * provided in an array of values of key/message/tag that is known to |
michael@0 | 157 | * be good |
michael@0 | 158 | */ |
michael@0 | 159 | |
michael@0 | 160 | err_status_t |
michael@0 | 161 | auth_type_test(const auth_type_t *at, const auth_test_case_t *test_data); |
michael@0 | 162 | |
michael@0 | 163 | /* |
michael@0 | 164 | * auth_type_get_ref_count(at) returns the reference count (the number |
michael@0 | 165 | * of instantiations) of the auth_type_t at |
michael@0 | 166 | */ |
michael@0 | 167 | |
michael@0 | 168 | int |
michael@0 | 169 | auth_type_get_ref_count(const auth_type_t *at); |
michael@0 | 170 | |
michael@0 | 171 | #endif /* AUTH_H */ |