Remove regress sys/crypto tests, obsoleted by ATF ones

These algorithms are used in ATF tests/net/ipsec

Today it's better to use rumpkernel to verify this code instead of
reinventing testsuites linking with selected kernel private source files.
This commit is contained in:
kamil 2017-05-14 03:42:42 +00:00
parent 1df0208250
commit f48b8fbc38
11 changed files with 1 additions and 755 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.12 2005/12/14 23:56:45 rpaulo Exp $
# $NetBSD: Makefile,v 1.13 2017/05/14 03:42:42 kamil Exp $
.include <bsd.own.mk>
@ -9,9 +9,6 @@ SUBDIR+= arch/${MACHINE}
.if exists(arch/${MACHINE_ARCH}/Makefile)
SUBDIR+= arch/${MACHINE_ARCH}
.endif
.if ${MKCRYPTO} != "no"
SUBDIR+= crypto
.endif
SUBDIR := ${SUBDIR:O:u}

View File

@ -1,12 +0,0 @@
# $NetBSD: Makefile,v 1.4 2017/05/14 03:36:36 kamil Exp $
# $KAME: Makefile,v 1.4 2000/11/01 14:55:39 itojun Exp $
SUBDIR= blowfish cast128 rijndael
.if ${MACHINE_ARCH} == "i386"
SUBDIR+= des_asm blowfish_asm
.endif
TARGETS+= benchmark
.PHONY: benchmark
.include <bsd.subdir.mk>

View File

@ -1,20 +0,0 @@
# $NetBSD: Makefile.inc,v 1.8 2011/05/14 16:26:23 christos Exp $
# $KAME: Makefile.inc,v 1.3 2000/11/08 05:58:24 itojun Exp $
.if !target(regress)
.include <bsd.own.mk>
SYSDIR= ${NETBSDSRCDIR}/sys
WARNS?= 4
regress:
@./${PROG}
BENCHROUNDS?= 10000
benchmark:
@time ./${PROG} ${BENCHROUNDS}
.endif
# do not install regression test programs
proginstall::

View File

@ -1,15 +0,0 @@
# $NetBSD: Makefile,v 1.5 2002/09/18 05:41:51 lukem Exp $
# $KAME: Makefile,v 1.5 2000/11/08 05:58:24 itojun Exp $
NOMAN= # defined
PROG= bftest
SRCS= bftest.c bf_enc.c bf_skey.c
.include "../Makefile.inc"
.include <bsd.own.mk>
CPPFLAGS+= -I${SYSDIR}
.PATH: ${SYSDIR}/crypto/blowfish
.include <bsd.prog.mk>

View File

@ -1,209 +0,0 @@
/* $NetBSD: bftest.c,v 1.6 2011/05/14 16:26:23 christos Exp $ */
/* $KAME: bftest.c,v 1.3 2000/11/08 05:58:24 itojun Exp $ */
/*
* Copyright (C) 2000 WIDE Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <sys/cdefs.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <crypto/blowfish/blowfish.h>
static const char *bf_key[2]={
"abcdefghijklmnopqrstuvwxyz",
"Who is John Galt?"
};
/* big endian */
static const char *bf_plain[2] = {
"424c4f5746495348", "fedcba9876543210"
};
static const char *bf_cipher[2] = {
"324ed0fef413a203", "cc91732b8022f684"
};
static void hex2bin(u_int8_t *, const char *);
static const char *pt(u_int8_t *);
int main(int, char **);
static void
hex2bin(p, s)
u_int8_t *p;
const char *s;
{
int i;
u_int v;
for (i = 0; i < 8; i++) {
sscanf(s, "%02x", &v);
*p++ = v & 0xff;
s += 2;
}
}
static const char *
pt(p)
u_int8_t *p;
{
static char bufs[10][20];
static int bnum = 0;
char *ret;
int i;
ret = bufs[bnum++];
bnum %= 10;
for (i = 0; i < 8; i++)
snprintf(&ret[i * 2], 3, "%02x", p[i]);
ret[8 * 2] = '\0';
return(ret);
}
int
main(argc, argv)
int argc;
char **argv;
{
int n, error = 0;
BF_KEY key;
BF_LONG data[2], plain[2], cipher[2];
int rounds;
if (argc > 1)
rounds = atoi(argv[1]);
else
rounds = 1;
printf("testing blowfish in raw ecb mode\n");
again:
for (n = 0; n < 2; n++) {
BF_set_key(&key, strlen(bf_key[n]),
(const unsigned char *)bf_key[n]);
hex2bin((u_int8_t *)plain, bf_plain[n]);
hex2bin((u_int8_t *)cipher, bf_cipher[n]);
memcpy(data, plain, 8);
data[0] = (BF_LONG)ntohl(data[0]);
data[1] = (BF_LONG)ntohl(data[1]);
BF_encrypt(data, &key);
data[0] = (BF_LONG)htonl(data[0]);
data[1] = (BF_LONG)htonl(data[1]);
if (memcmp(data, cipher, 8) != 0) {
printf("BF_encrypt error encrypting\n");
printf("got : %s", pt((u_int8_t *)data));
printf("\n");
printf("expected: %s", pt((u_int8_t *)cipher));
error = 1;
printf("\n");
}
data[0] = (BF_LONG)ntohl(data[0]);
data[1] = (BF_LONG)ntohl(data[1]);
BF_decrypt(data, &key);
data[0] = (BF_LONG)htonl(data[0]);
data[1] = (BF_LONG)htonl(data[1]);
if (memcmp(data, plain, 8) != 0) {
printf("BF_encrypt error decrypting\n");
printf("got : %s", pt((u_int8_t *)data));
printf("\n");
printf("expected: %s", pt((u_int8_t *)plain));
printf("\n");
error = 1;
}
}
if (--rounds > 0)
goto again;
exit(error);
}

View File

@ -1,16 +0,0 @@
# $NetBSD: Makefile,v 1.3 2002/09/18 05:41:51 lukem Exp $
# $KAME: Makefile,v 1.5 2000/11/08 05:58:24 itojun Exp $
NOMAN= # defined
PROG= bftest
SRCS= bftest.c bf_enc.S bf_skey.c
.include "../Makefile.inc"
.include <bsd.own.mk>
CPPFLAGS+= -I${SYSDIR} -I${SYSDIR}/arch
.PATH: ${.CURDIR}/../blowfish ${SYSDIR}/crypto/blowfish \
${SYSDIR}/crypto/blowfish/arch/${MACHINE_ARCH}
.include <bsd.prog.mk>

View File

@ -1,15 +0,0 @@
# $NetBSD: Makefile,v 1.5 2002/09/18 05:41:51 lukem Exp $
# $KAME: Makefile,v 1.4 2000/11/08 05:58:25 itojun Exp $
NOMAN= # defined
PROG= casttest
SRCS= casttest.c cast128.c
.include "../Makefile.inc"
.include <bsd.own.mk>
CPPFLAGS+= -I${SYSDIR}
.PATH: ${SYSDIR}/crypto/cast128
.include <bsd.prog.mk>

View File

@ -1,205 +0,0 @@
/* $NetBSD: casttest.c,v 1.6 2005/02/06 06:05:19 perry Exp $ */
/* $KAME: casttest.c,v 1.5 2001/11/28 03:14:03 itojun Exp $ */
/*
* Copyright (C) 2000 WIDE Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <sys/cdefs.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <crypto/cast128/cast128.h>
static unsigned char k[16]={
0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A
};
static unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
static int k_len[3]={16,10,5};
static unsigned char c[3][8]={
{0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2},
{0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B},
{0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E},
};
static unsigned char out[80];
#if 0
static unsigned char in_a[16]={
0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
static unsigned char in_b[16]={
0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
static unsigned char c_a[16]={
0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6,
0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92};
static unsigned char c_b[16]={
0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71,
0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E};
#endif
int main(int, char **);
int test1(int);
int
main(argc, argv)
int argc;
char **argv;
{
int error;
int rounds;
if (argc > 1)
rounds = atoi(argv[1]);
else
rounds = 1;
error = test1(rounds);
if (!error)
printf("ecb cast5 ok\n");
exit(error);
}
int
test1(rounds)
int rounds;
{
cast128_key subkey;
int i, z, error = 0;
again:
for (z = 0; z < 3; z++) {
#if 0
if (k_len[z] != 16)
continue;
#endif
cast128_setkey(&subkey, k, k_len[z]);
subkey.rounds = (k_len[z] * 8 <= 80) ? 12 : 16;
cast128_encrypt(&subkey, in, out);
if (memcmp(out, c[z], 8) != 0) {
printf("ecb cast error encrypting for keysize %d\n",
k_len[z] * 8);
printf("got :");
for (i = 0; i < 8; i++)
printf("%02X ", out[i]);
printf("\n");
printf("expected:");
for (i = 0; i < 8; i++)
printf("%02X ", c[z][i]);
error = 20;
printf("\n");
}
cast128_decrypt(&subkey, out, out);
if (memcmp(out, in, 8) != 0) {
printf("ecb cast error decrypting for keysize %d\n",
k_len[z] * 8);
printf("got :");
for (i = 0; i < 8; i++)
printf("%02X ", out[i]);
printf("\n");
printf("expected:");
for (i = 0; i < 8; i++)
printf("%02X ", in[i]);
printf("\n");
error = 3;
}
}
if (--rounds > 0)
goto again;
return error;
}

View File

@ -1,18 +0,0 @@
# $NetBSD: Makefile,v 1.4 2016/08/14 19:05:24 joerg Exp $
# $KAME: Makefile,v 1.5 2000/11/08 05:58:25 itojun Exp $
NOMAN= # defined
PROG= destest
SRCS= destest.c des_ecb.c des_enc.S des_setkey.c
NOPIE= yes
.include "../Makefile.inc"
.include <bsd.own.mk>
CPPFLAGS+= -I${SYSDIR} -I${SYSDIR}/arch
.PATH: ${.CURDIR}/../des ${SYSDIR}/crypto/des \
${SYSDIR}/crypto/des/arch/${MACHINE_ARCH}
.include <bsd.prog.mk>

View File

@ -1,17 +0,0 @@
# $NetBSD: Makefile,v 1.6 2002/09/18 05:41:52 lukem Exp $
# $KAME: Makefile,v 1.4 2000/11/08 05:58:26 itojun Exp $
NOMAN= # defined
PROG= rijndaeltest
SRCS= rijndaeltest.c rijndael-alg-fst.c rijndael-api-fst.c
.include "../Makefile.inc"
.include <bsd.own.mk>
CPPFLAGS+= -I${SYSDIR} "-Dpanic(x)=abort()"
.PATH: ${SYSDIR}/crypto/rijndael
BENCHROUNDS= 100
.include <bsd.prog.mk>

View File

@ -1,224 +0,0 @@
/* $NetBSD: rijndaeltest.c,v 1.8 2011/05/14 16:26:23 christos Exp $ */
/* $KAME: rijndaeltest.c,v 1.7 2001/05/27 01:56:45 itojun Exp $ */
/*
* Copyright (C) 2000 WIDE Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <err.h>
#include <crypto/rijndael/rijndael.h>
#include <crypto/rijndael/rijndael-api-fst.h>
/* decrypt test */
struct {
const char *key;
const char *ct;
const char *pt;
} dvector[] = {
{
"00000000000000000000000000000000",
"00000000000000000000000000000000",
"44416AC2D1F53C583303917E6BE9EBE0",
},
{
"DE11FF0A429E1CD3DE016DAC294F771187463793E21C29525A3B282CDCAD6270",
"E1268BA8A1473DEDE6CA64DDF2C8B805",
"4DE0C6DF7CB1697284604D60271BC59A",
},
{
NULL, NULL, NULL,
},
};
/* encrypt test */
struct {
const char *key;
const char *pt;
const char *ct;
} evector[] = {
{
"00000000000000000000000000000000",
"00000000000000000000000000000000",
"C34C052CC0DA8D73451AFE5F03BE297F",
},
{
"982D617A0F737342E99123A5A573D266F4961915B32DCA4118AD5CF1DCB6ED00",
"6F8606BBA6CC03A5D0A64FE21E277B60",
"1F6763DF807A7E70960D4CD3118E601A",
},
{
NULL, NULL, NULL,
},
};
static void hex2key(u_int8_t *, size_t, const char *);
int main(int, char **);
static void
hex2key(p, l, s)
u_int8_t *p;
size_t l;
const char *s;
{
size_t i;
u_int v;
for (i = 0; i < l && *s; i++) {
sscanf(s, "%02x", &v);
*p++ = v & 0xff;
s += 2;
}
if (*s) {
errx(1, "hex2key overrun");
/*NOTREACHED*/
}
}
int
main(argc, argv)
int argc;
char **argv;
{
int i, j;
keyInstance k;
cipherInstance c;
int error;
const char *test;
u_int8_t key[32], input[16], output[16], answer[16];
int nrounds, rounds;
if (argc > 1)
nrounds = atoi(argv[1]);
else
nrounds = 1;
error = 0;
rounds = nrounds;
again1:
test = "decrypt test";
for (i = 0; dvector[i].key; i++) {
hex2key(key, sizeof(key), dvector[i].key);
hex2key(input, sizeof(input), dvector[i].ct);
memset(output, 0, sizeof(output));
hex2key(answer, sizeof(answer), dvector[i].pt);
/* LINTED const cast */
if (rijndael_makeKey(&k, DIR_DECRYPT,
strlen(dvector[i].key) * 4, (char *)key) < 0) {
printf("makeKey failed for %s %d\n", test, i);
error++;
continue;
}
if (rijndael_cipherInit(&c, MODE_ECB, NULL) < 0) {
printf("cipherInit failed for %s %d\n", test, i);
error++;
continue;
}
for (j = 0; j < 10000; j++) {
if (rijndael_blockDecrypt(&c, &k, input,
sizeof(input) * 8, output) < 0) {
printf("blockDecrypt failed for %s %d/%d\n",
test, i, j);
error++;
goto next1;
}
memcpy(input, output, sizeof(input));
}
if (memcmp(output, answer, sizeof(output)) != 0) {
printf("result mismatch for %s %d\n", test, i);
error++;
}
if (nrounds == 1)
printf("%s %d successful\n", test, i);
next1:;
}
if (--rounds)
goto again1;
rounds = nrounds;
again2:
test = "encrypt test";
for (i = 0; evector[i].key; i++) {
hex2key(key, sizeof(key), evector[i].key);
hex2key(input, sizeof(input), evector[i].pt);
memset(output, 0, sizeof(output));
hex2key(answer, sizeof(answer), evector[i].ct);
/* LINTED const cast */
if (rijndael_makeKey(&k, DIR_ENCRYPT,
strlen(evector[i].key) * 4, (char *)key) < 0) {
printf("makeKey failed for %s %d\n", test, i);
error++;
continue;
}
if (rijndael_cipherInit(&c, MODE_ECB, NULL) < 0) {
printf("cipherInit failed for %s %d\n", test, i);
error++;
continue;
}
for (j = 0; j < 10000; j++) {
if (rijndael_blockEncrypt(&c, &k, input,
sizeof(input) * 8, output) < 0) {
printf("blockEncrypt failed for %s %d/%d\n",
test, i, j);
error++;
goto next2;
}
memcpy(input, output, sizeof(input));
}
if (memcmp(output, answer, sizeof(output)) != 0) {
printf("result mismatch for %s %d\n", test, i);
error++;
continue;
}
if (nrounds == 1)
printf("%s %d successful\n", test, i);
next2:;
}
if (--rounds)
goto again2;
exit(error);
}