4
* a test driver for crypto/math datatypes
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 <string.h> /* for strlen() */
49
#include "datatypes.h"
55
test_hex_string_funcs(void);
58
print_string(char *s);
67
* this program includes various and sundry tests for fundamental
68
* datatypes. it's a grab-bag of throwaway code, retained only in
69
* case of future problems
75
"The Moving Finger writes; and, having writ,\n"
76
"Moves on: nor all thy Piety nor Wit\n"
77
"Shall lure it back to cancel half a Line,\n"
78
"Nor all thy Tears wash out a Word of it.";
79
char *s = "incomplet";
85
test_hex_string_funcs();
87
for (j=0; j < 128; j++) {
89
/* x.v32[0] = (1 << j); */
91
printf("%s\n", v128_bit_string(&x));
92
v128_clear_bit(&x, j);
93
printf("%s\n", v128_bit_string(&x));
97
printf("----------------------------------------------\n");
99
for (i=0; i < 128; i++) {
102
printf("%s\n", v128_bit_string(&x));
104
printf("----------------------------------------------\n");
105
v128_set_to_zero(&x);
107
for (i=0; i < 128; i++) {
108
printf("%s\n", v128_bit_string(&x));
109
v128_right_shift(&x, 1);
111
printf("----------------------------------------------\n");
112
v128_set_to_zero(&x);
113
v128_set_bit(&x, 127);
114
for (i=0; i < 128; i++) {
115
printf("%s\n", v128_bit_string(&x));
116
v128_left_shift(&x, 1);
118
printf("----------------------------------------------\n");
119
for (i=0; i < 128; i++) {
120
v128_set_to_zero(&x);
121
v128_set_bit(&x, 127);
122
v128_left_shift(&x, i);
123
printf("%s\n", v128_bit_string(&x));
125
printf("----------------------------------------------\n");
126
v128_set_to_zero(&x);
127
for (i=0; i < 128; i+=2) {
130
printf("bit_string: { %s }\n", v128_bit_string(&x));
131
printf("get_bit: { ");
132
for (i=0; i < 128; i++) {
133
if (v128_get_bit(&x, i) == 1)
146
/* byte_order() prints out byte ordering of datatypes */
157
for (i=0; i < sizeof(b); i++)
159
for (i=0; i < sizeof(c); i++)
161
for (i=0; i < sizeof(d); i++)
164
printf("v128_t:\t%s\n", v128_hex_string(&e));
165
printf("v64_t:\t%s\n", v64_hex_string(&d));
166
printf("v32_t:\t%s\n", v32_hex_string(c));
167
printf("v16_t:\t%s\n", v16_hex_string(b));
169
c.value = 0x01020304;
170
printf("v32_t:\t%s\n", v32_hex_string(c));
172
printf("v16_t:\t%s\n", v16_hex_string(b));
174
printf("uint16_t ordering:\n");
176
c.value = 0x00010002;
177
printf("v32_t:\t%x%x\n", c.v16[0], c.v16[1]);
180
printf("byte ordering of crypto/math datatypes:\n");
181
for (i=0; i < sizeof(e); i++)
183
printf("v128_t: %s\n", v128_hex_string(&e));
188
test_hex_string_funcs(void) {
189
char hex1[] = "abadcafe";
190
char hex2[] = "0123456789abcdefqqqqq";
194
len = hex_string_to_octet_string(raw, hex1, strlen(hex1));
195
printf("computed length: %d\tstring: %s\n", len,
196
octet_string_hex_string(raw, len/2));
197
printf("expected length: %u\tstring: %s\n", (unsigned)strlen(hex1), hex1);
199
len = hex_string_to_octet_string(raw, hex2, strlen(hex2));
200
printf("computed length: %d\tstring: %s\n", len,
201
octet_string_hex_string(raw, len/2));
202
printf("expected length: %d\tstring: %s\n", 16, "0123456789abcdef");
207
print_string(char *s) {
210
printf("strlen(s) = %u\n", (unsigned)strlen(s));
212
for (i=0; i < strlen(s); i++) {
213
printf("0x%x, ", s[i]);
214
if (((i+1) % 8) == 0)
222
uint32_t x = 0x11223344;
223
uint64_t y = 0x1122334455667788LL;
225
printf("before: %0x\nafter: %0x\n", x, be32_to_cpu(x));
226
printf("before: %0llx\nafter: %0llx\n", (unsigned long long)y,
227
(unsigned long long)be64_to_cpu(y));
231
printf("1234: %0llx\n", (unsigned long long)y);
232
printf("as octet string: %s\n",
233
octet_string_hex_string((uint8_t *) &y, 8));
235
printf("bswapped octet string: %s\n",
236
octet_string_hex_string((uint8_t *) &y, 8));