4
* a driver for auth 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.
47
#include <stdio.h> /* for printf() */
48
#include <stdlib.h> /* for xalloc() */
49
#include <unistd.h> /* for getopt() */
52
#include "null_auth.h"
54
#define PRINT_DEBUG_DATA 0
56
extern auth_type_t tmmhv2;
58
const uint16_t msg0[9] = {
59
0x6015, 0xf141, 0x5ba1, 0x29a0, 0xf604, 0xd1c, 0x2d9, 0xaa8a, 0x7931
62
/* key1 is for TAG_WORDS = 2 */
64
const uint16_t key1[47] = {
65
0xe627, 0x6a01, 0x5ea7, 0xf27a, 0xc536, 0x2192, 0x11be, 0xea35,
66
0xdb9d, 0x63d6, 0xfa8a, 0xfc45, 0xe08b, 0xd216, 0xced2, 0x7853,
67
0x1a82, 0x22f5, 0x90fb, 0x1c29, 0x708e, 0xd06f, 0x82c3, 0xbee6,
68
0x4f21, 0x6f33, 0x65c0, 0xd211, 0xc25e, 0x9138, 0x4fa3, 0x7c1f,
69
0x61ac, 0x3489, 0x2976, 0x8c19, 0x8252, 0xddbf, 0xcad3, 0xc28f,
70
0x68d6, 0x58dd, 0x504f, 0x2bbf, 0x0278, 0x70b7, 0xcfca
74
auth_bits_per_second(auth_t *h, int msg_len);
78
usage(char *prog_name) {
79
printf("usage: %s [ -t | -v ]\n", prog_name);
83
#define MAX_MSG_LEN 2048
86
main (int argc, char *argv[]) {
91
unsigned do_timing_test = 0;
92
unsigned do_validation = 0;
94
/* process input arguments */
96
c = getopt(argc, argv, "tv");
111
printf("auth driver\nDavid A. McGrew\nCisco Systems, Inc.\n");
113
if (!do_validation && !do_timing_test)
117
printf("running self-test for %s...", tmmhv2.description);
118
status = tmmhv2_add_big_test();
120
printf("tmmhv2_add_big_test failed with error code %d\n", status);
123
status = auth_type_self_test(&tmmhv2);
125
printf("failed with error code %d\n", status);
131
if (do_timing_test) {
133
/* tmmhv2 timing test */
134
status = auth_type_alloc(&tmmhv2, &a, 94, 4);
136
fprintf(stderr, "can't allocate tmmhv2\n");
139
status = auth_init(a, (uint8_t *)key1);
141
printf("error initializaing auth function\n");
145
printf("timing %s (tag length %d)\n",
146
tmmhv2.description, auth_get_tag_length(a));
147
for (i=8; i <= MAX_MSG_LEN; i *= 2)
148
printf("msg len: %d\tgigabits per second: %f\n",
149
i, auth_bits_per_second(a, i) / 1E9);
151
status = auth_dealloc(a);
153
printf("error deallocating auth function\n");
162
#define NUM_TRIALS 100000
167
auth_bits_per_second(auth_t *a, int msg_len_octets) {
171
int msg_len = (msg_len_octets + 1)/2;
172
uint16_t *msg_string;
174
/* create random message */
175
msg_string = (uint16_t *) crypto_alloc(msg_len_octets);
176
if (msg_string == NULL)
177
return 0.0; /* indicate failure */
178
for (i=0; i < msg_len; i++)
179
msg_string[i] = (uint16_t) random();
181
/* allocate temporary storage for authentication tag */
182
result = crypto_alloc(auth_get_tag_length(a));
183
if (result == NULL) {
185
return 0.0; /* indicate failure */
189
for (i=0; i < NUM_TRIALS; i++) {
190
auth_compute(a, (uint8_t *)msg_string, msg_len_octets, (uint8_t *)result);
192
timer = clock() - timer;
197
return (double) NUM_TRIALS * 8 * msg_len_octets * CLOCKS_PER_SEC / timer;