sync calling sequence with kernel code. sync with kame

This commit is contained in:
itojun 2000-11-05 03:15:57 +00:00
parent 6ccf8e332e
commit 76a9ffd207

View File

@ -1,5 +1,5 @@
/* $NetBSD: bftest.c,v 1.1.1.1 2000/11/01 15:33:25 itojun Exp $ */ /* $NetBSD: bftest.c,v 1.2 2000/11/05 03:15:57 itojun Exp $ */
/* $KAME: bftest.c,v 1.1 2000/11/01 14:03:37 itojun Exp $ */ /* $KAME: bftest.c,v 1.2 2000/11/05 02:54:35 itojun Exp $ */
/* /*
* Copyright (C) 2000 WIDE Project. * Copyright (C) 2000 WIDE Project.
@ -102,57 +102,92 @@ static char *bf_key[2]={
}; };
/* big endian */ /* big endian */
static BF_LONG bf_plain[2][2]={ static const char *bf_plain[2] = {
{0x424c4f57L,0x46495348L}, "424c4f5746495348", "fedcba9876543210"
{0xfedcba98L,0x76543210L}
}; };
static BF_LONG bf_cipher[2][2]={ static const char *bf_cipher[2] = {
{0x324ed0feL,0xf413a203L}, "324ed0fef413a203", "cc91732b8022f684"
{0xcc91732bL,0x8022f684L}
}; };
static void hex2bin __P((u_int8_t *, const char *));
static const char *pt __P((u_int8_t *));
int main __P((int, char **)); int main __P((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 int
main(argc, argv) main(argc, argv)
int argc; int argc;
char **argv; char **argv;
{ {
int i, n, error = 0; int n, error = 0;
BF_KEY key; BF_KEY key;
BF_LONG data[2]; BF_LONG data[2], plain[2], cipher[2];
printf("testing blowfish in raw ecb mode\n"); printf("testing blowfish in raw ecb mode\n");
for (n = 0; n < 2; n++) { for (n = 0; n < 2; n++) {
BF_set_key(&key, strlen(bf_key[n]), (unsigned char *)bf_key[n]); BF_set_key(&key, strlen(bf_key[n]), (unsigned char *)bf_key[n]);
data[0] = bf_plain[n][0]; hex2bin((u_int8_t *)plain, bf_plain[n]);
data[1] = bf_plain[n][1]; 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, BF_ENCRYPT); BF_encrypt(data, &key, BF_ENCRYPT);
if (memcmp(&(bf_cipher[n][0]), &(data[0]), 8) != 0) { 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("BF_encrypt error encrypting\n");
printf("got :"); printf("got : %s", pt((u_int8_t *)data));
for (i = 0; i < 2; i++)
printf("%08lX ", (unsigned long)data[i]);
printf("\n"); printf("\n");
printf("expected:"); printf("expected: %s", pt((u_int8_t *)cipher));
for (i = 0; i < 2; i++)
printf("%08lX ", (unsigned long)bf_cipher[n][i]);
error = 1; error = 1;
printf("\n"); printf("\n");
} }
BF_encrypt(&(data[0]), &key, BF_DECRYPT); data[0] = (BF_LONG)ntohl(data[0]);
if (memcmp(&(bf_plain[n][0]), &(data[0]), 8) != 0) { data[1] = (BF_LONG)ntohl(data[1]);
BF_encrypt(data, &key, BF_DECRYPT);
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("BF_encrypt error decrypting\n");
printf("got :"); printf("got : %s", pt((u_int8_t *)data));
for (i = 0; i < 2; i++)
printf("%08lX ", (unsigned long)data[i]);
printf("\n"); printf("\n");
printf("expected:"); printf("expected: %s", pt((u_int8_t *)plain));
for (i = 0; i < 2; i++)
printf("%08lX ", (unsigned long)bf_plain[n][i]);
printf("\n"); printf("\n");
error = 1; error = 1;
} }