netwerk/srtp/src/crypto/hash/null_auth.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 * null_auth.c
michael@0 3 *
michael@0 4 * implements the do-nothing auth algorithm
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 *
michael@0 13 * Copyright (c) 2001-2006, Cisco Systems, Inc.
michael@0 14 * All rights reserved.
michael@0 15 *
michael@0 16 * Redistribution and use in source and binary forms, with or without
michael@0 17 * modification, are permitted provided that the following conditions
michael@0 18 * are met:
michael@0 19 *
michael@0 20 * Redistributions of source code must retain the above copyright
michael@0 21 * notice, this list of conditions and the following disclaimer.
michael@0 22 *
michael@0 23 * Redistributions in binary form must reproduce the above
michael@0 24 * copyright notice, this list of conditions and the following
michael@0 25 * disclaimer in the documentation and/or other materials provided
michael@0 26 * with the distribution.
michael@0 27 *
michael@0 28 * Neither the name of the Cisco Systems, Inc. nor the names of its
michael@0 29 * contributors may be used to endorse or promote products derived
michael@0 30 * from this software without specific prior written permission.
michael@0 31 *
michael@0 32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
michael@0 35 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
michael@0 36 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
michael@0 37 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
michael@0 38 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
michael@0 39 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
michael@0 40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
michael@0 41 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
michael@0 42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
michael@0 43 * OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 44 *
michael@0 45 */
michael@0 46
michael@0 47
michael@0 48 #include "null_auth.h"
michael@0 49 #include "alloc.h"
michael@0 50
michael@0 51 /* null_auth uses the auth debug module */
michael@0 52
michael@0 53 extern debug_module_t mod_auth;
michael@0 54
michael@0 55 err_status_t
michael@0 56 null_auth_alloc(auth_t **a, int key_len, int out_len) {
michael@0 57 extern auth_type_t null_auth;
michael@0 58 uint8_t *pointer;
michael@0 59
michael@0 60 debug_print(mod_auth, "allocating auth func with key length %d", key_len);
michael@0 61 debug_print(mod_auth, " tag length %d", out_len);
michael@0 62
michael@0 63 /* allocate memory for auth and null_auth_ctx_t structures */
michael@0 64 pointer = (uint8_t*)crypto_alloc(sizeof(null_auth_ctx_t) + sizeof(auth_t));
michael@0 65 if (pointer == NULL)
michael@0 66 return err_status_alloc_fail;
michael@0 67
michael@0 68 /* set pointers */
michael@0 69 *a = (auth_t *)pointer;
michael@0 70 (*a)->type = &null_auth;
michael@0 71 (*a)->state = pointer + sizeof (auth_t);
michael@0 72 (*a)->out_len = out_len;
michael@0 73 (*a)->prefix_len = out_len;
michael@0 74 (*a)->key_len = key_len;
michael@0 75
michael@0 76 /* increment global count of all null_auth uses */
michael@0 77 null_auth.ref_count++;
michael@0 78
michael@0 79 return err_status_ok;
michael@0 80 }
michael@0 81
michael@0 82 err_status_t
michael@0 83 null_auth_dealloc(auth_t *a) {
michael@0 84 extern auth_type_t null_auth;
michael@0 85
michael@0 86 /* zeroize entire state*/
michael@0 87 octet_string_set_to_zero((uint8_t *)a,
michael@0 88 sizeof(null_auth_ctx_t) + sizeof(auth_t));
michael@0 89
michael@0 90 /* free memory */
michael@0 91 crypto_free(a);
michael@0 92
michael@0 93 /* decrement global count of all null_auth uses */
michael@0 94 null_auth.ref_count--;
michael@0 95
michael@0 96 return err_status_ok;
michael@0 97 }
michael@0 98
michael@0 99 err_status_t
michael@0 100 null_auth_init(null_auth_ctx_t *state, const uint8_t *key, int key_len) {
michael@0 101
michael@0 102 /* accept any length of key, and do nothing */
michael@0 103
michael@0 104 return err_status_ok;
michael@0 105 }
michael@0 106
michael@0 107 err_status_t
michael@0 108 null_auth_compute(null_auth_ctx_t *state, uint8_t *message,
michael@0 109 int msg_octets, int tag_len, uint8_t *result) {
michael@0 110
michael@0 111 return err_status_ok;
michael@0 112 }
michael@0 113
michael@0 114 err_status_t
michael@0 115 null_auth_update(null_auth_ctx_t *state, uint8_t *message,
michael@0 116 int msg_octets) {
michael@0 117
michael@0 118 return err_status_ok;
michael@0 119 }
michael@0 120
michael@0 121 err_status_t
michael@0 122 null_auth_start(null_auth_ctx_t *state) {
michael@0 123 return err_status_ok;
michael@0 124 }
michael@0 125
michael@0 126 /*
michael@0 127 * auth_type_t - defines description, test case, and null_auth
michael@0 128 * metaobject
michael@0 129 */
michael@0 130
michael@0 131 /* begin test case 0 */
michael@0 132
michael@0 133 auth_test_case_t
michael@0 134 null_auth_test_case_0 = {
michael@0 135 0, /* octets in key */
michael@0 136 NULL, /* key */
michael@0 137 0, /* octets in data */
michael@0 138 NULL, /* data */
michael@0 139 0, /* octets in tag */
michael@0 140 NULL, /* tag */
michael@0 141 NULL /* pointer to next testcase */
michael@0 142 };
michael@0 143
michael@0 144 /* end test case 0 */
michael@0 145
michael@0 146 char null_auth_description[] = "null authentication function";
michael@0 147
michael@0 148 auth_type_t
michael@0 149 null_auth = {
michael@0 150 (auth_alloc_func) null_auth_alloc,
michael@0 151 (auth_dealloc_func) null_auth_dealloc,
michael@0 152 (auth_init_func) null_auth_init,
michael@0 153 (auth_compute_func) null_auth_compute,
michael@0 154 (auth_update_func) null_auth_update,
michael@0 155 (auth_start_func) null_auth_start,
michael@0 156 (char *) null_auth_description,
michael@0 157 (int) 0, /* instance count */
michael@0 158 (auth_test_case_t *) &null_auth_test_case_0,
michael@0 159 (debug_module_t *) NULL,
michael@0 160 (auth_type_id_t) NULL_AUTH
michael@0 161 };
michael@0 162

mercurial