~ubuntu-branches/ubuntu/lucid/loop-aes-utils/lucid-security

« back to all changes in this revision

Viewing changes to tests/helpers/test_byteswap.c

  • Committer: Bazaar Package Importer
  • Author(s): Max Vozeler
  • Date: 2009-07-06 02:08:18 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090706020818-11pxao7bhgjenfv9
Tags: 2.15.1~rc1-2
Disable ncurses (--without-ncurses), not used in
mount/. Fixes FTBFS (closes: #535676).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This testing program makes sure the byteswap functions work
 
3
 *
 
4
 * Copyright (C) 2000 by Theodore Ts'o.
 
5
 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
 
6
 *
 
7
 * This file may be redistributed under the terms of the GNU Public
 
8
 * License.
 
9
 */
 
10
#include <stdio.h>
 
11
#include <string.h>
 
12
#include <unistd.h>
 
13
#include <fcntl.h>
 
14
#include <time.h>
 
15
#include <sys/stat.h>
 
16
#include <sys/types.h>
 
17
#include <errno.h>
 
18
#include <inttypes.h>
 
19
 
 
20
#include "bitops.h"
 
21
 
 
22
uint16_t ary16[] = {
 
23
        0x0001, 0x0100,
 
24
        0x1234, 0x3412,
 
25
        0xff00, 0x00ff,
 
26
        0x4000, 0x0040,
 
27
        0xfeff, 0xfffe,
 
28
        0x0000, 0x0000
 
29
        };
 
30
 
 
31
uint32_t ary32[] = {
 
32
        0x00000001, 0x01000000,
 
33
        0x80000000, 0x00000080,
 
34
        0x12345678, 0x78563412,
 
35
        0xffff0000, 0x0000ffff,
 
36
        0x00ff0000, 0x0000ff00,
 
37
        0xff000000, 0x000000ff,
 
38
        0x00000000, 0x00000000
 
39
        };
 
40
 
 
41
uint64_t ary64[] = {
 
42
        0x0000000000000001, 0x0100000000000000,
 
43
        0x8000000000000000, 0x0000000000000080,
 
44
        0x1234567812345678, 0x7856341278563412,
 
45
        0xffffffff00000000, 0x00000000ffffffff,
 
46
        0x00ff000000000000, 0x000000000000ff00,
 
47
        0xff00000000000000, 0x00000000000000ff,
 
48
        0x0000000000000000, 0x0000000000000000
 
49
        };
 
50
 
 
51
int main(int argc, char **argv)
 
52
{
 
53
        int     i;
 
54
        int     errors = 0;
 
55
 
 
56
        printf("Testing swab16\n");
 
57
        i=0;
 
58
        do {
 
59
                printf("swab16(0x%04"PRIx16") = 0x%04"PRIx16"\n",
 
60
                                ary16[i], swab16(ary16[i]));
 
61
                if (swab16(ary16[i]) != ary16[i+1]) {
 
62
                        printf("Error!!!   %04"PRIx16" != %04"PRIx16"\n",
 
63
                               swab16(ary16[i]), ary16[i+1]);
 
64
                        errors++;
 
65
                }
 
66
                if (swab16(ary16[i+1]) != ary16[i]) {
 
67
                        printf("Error!!!   %04"PRIx16" != %04"PRIx16"\n",
 
68
                               swab16(ary16[i+1]), ary16[i]);
 
69
                        errors++;
 
70
                }
 
71
                i += 2;
 
72
        } while (ary16[i] != 0);
 
73
 
 
74
        printf("Testing swab32\n");
 
75
        i = 0;
 
76
        do {
 
77
                printf("swab32(0x%08"PRIx32") = 0x%08"PRIx32"\n",
 
78
                                ary32[i], swab32(ary32[i]));
 
79
                if (swab32(ary32[i]) != ary32[i+1]) {
 
80
                        printf("Error!!!   %04"PRIx32" != %04"PRIx32"\n",
 
81
                                swab32(ary32[i]), ary32[i+1]);
 
82
                        errors++;
 
83
                }
 
84
                if (swab32(ary32[i+1]) != ary32[i]) {
 
85
                        printf("Error!!!   %04"PRIx32" != %04"PRIx32"\n",
 
86
                               swab32(ary32[i+1]), ary32[i]);
 
87
                        errors++;
 
88
                }
 
89
                i += 2;
 
90
        } while (ary32[i] != 0);
 
91
 
 
92
        printf("Testing swab64\n");
 
93
        i = 0;
 
94
        do {
 
95
                printf("swab64(0x%016"PRIx64") = 0x%016"PRIx64"\n",
 
96
                                ary64[i], swab64(ary64[i]));
 
97
                if (swab64(ary64[i]) != ary64[i+1]) {
 
98
                        printf("Error!!!   %016"PRIx64" != %016"PRIx64"\n",
 
99
                                swab64(ary64[i]), ary64[i+1]);
 
100
                        errors++;
 
101
                }
 
102
                if (swab64(ary64[i+1]) != ary64[i]) {
 
103
                        printf("Error!!!   %016"PRIx64" != %016"PRIx64"\n",
 
104
                               swab64(ary64[i+1]), ary64[i]);
 
105
                        errors++;
 
106
                }
 
107
                i += 2;
 
108
        } while (ary64[i] != 0);
 
109
 
 
110
        if (!errors)
 
111
                printf("No errors found in the byteswap implementation\n");
 
112
 
 
113
        return errors;
 
114
}