chiark / gitweb /
Version bump.
[storin] / storin-tests.c
CommitLineData
e6e0e332
MW
1/* -*-c-*-
2 *
6b2d9d76 3 * $Id: storin-tests.c,v 1.2 2000/07/02 15:21:20 mdw Exp $
e6e0e332
MW
4 *
5 * Generate test vectors for Storin
6 *
7 * (c) 2000 Mark Wooding
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * Copyright (c) 2000 Mark Wooding
13 * All rights reserved.
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions are
17 * met:
18 *
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 *
22 * 2, Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 *
26 * 3. The name of the authors may not be used to endorse or promote
27 * products derived from this software without specific prior written
28 * permission.
29 *
30 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
31 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
6b2d9d76 33 * NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
e6e0e332
MW
34 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
35 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
39 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
41 *
42 * Instead of accepting the above terms, you may redistribute and/or modify
43 * this software under the terms of either the GNU General Public License,
44 * or the GNU Library General Public License, published by the Free
45 * Software Foundation; either version 2 of the License, or (at your
46 * option) any later version.
47 */
48
49/*----- Revision history --------------------------------------------------*
50 *
51 * $Log: storin-tests.c,v $
6b2d9d76
MW
52 * Revision 1.2 2000/07/02 15:21:20 mdw
53 * Fix licence text.
54 *
e6e0e332
MW
55 * Revision 1.1 2000/05/21 11:28:30 mdw
56 * Initial check-in.
57 *
58 */
59
60/*----- Header files ------------------------------------------------------*/
61
62#include <stdio.h>
63#include <stdlib.h>
64
65#include "bits.h"
66#include "fibrand.h"
67#include "storin.h"
68
69/*----- Main code ---------------------------------------------------------*/
70
71int main(void)
72{
73 uint24 k[8], p[4], c[4], pp[4];
74 storin_ctx s;
75 fibrand r;
76 unsigned i, j, ii;
77
78 fibrand_lcseed(&r, 0);
79
80 fputs("\
81# Test vectors for Storin [generated]\n\
82#\n\
83# In each entry, the key comes first, followed by the plaintext and\n\
84# ciphertext.\n\
85\n\
86storin {\
87", stdout);
88
89 for (i = 1; i < 8; i++) {
90
91 /* --- Initial plaintext value --- */
92
93 for (j = 0; j < i; j++)
94 k[j] = j + 1;
95 for (j = 0; j < 4; j++)
96 p[j] = i + j + 1;
97 storin_init24(&s, k, i);
98 storin_eblk24(&s, p, c);
99 storin_dblk24(&s, c, pp);
100 fputs("\n ", stdout); for (j = 0; j < i; j++) printf("%06x", k[j]);
101 fputs("\n ", stdout); for (j = 0; j < 4; j++) printf("%06x", p[j]);
102 fputc(' ', stdout); for (j = 0; j < 4; j++) printf("%06x", c[j]);
103 fputs(";\n", stdout);
104 for (j = 0; j < 4; j++) {
105 if (p[j] != pp[j]) {
106 fputs("*** decryption failure\n", stderr);
107 exit(EXIT_FAILURE);
108 }
109 }
110
111 /* --- Random tests --- */
112
113 for (ii = 1; ii < 16; ii++) {
114 for (j = 0; j < i; j++)
115 k[j] = U24(fibrand_step(&r));
116 for (j = 0; j < 4; j++)
117 p[j] = U24(fibrand_step(&r));
118 storin_init24(&s, k, i);
119 storin_eblk24(&s, p, c);
120 fputs("\n ", stdout); for (j = 0; j < i; j++) printf("%06x", k[j]);
121 fputs("\n ", stdout); for (j = 0; j < 4; j++) printf("%06x", p[j]);
122 fputc(' ', stdout); for (j = 0; j < 4; j++) printf("%06x", c[j]);
123 fputs(";\n", stdout);
124 }
125 }
126
127 fputs("}\n", stdout);
128 return (0);
129}
130
131/*----- That's all, folks -------------------------------------------------*/