| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: bftest.c,v 1.5 2005/02/06 06:05:19 perry Exp $ */ | | 1 | /* $NetBSD: bftest.c,v 1.6 2011/05/14 16:26:23 christos Exp $ */ |
2 | /* $KAME: bftest.c,v 1.3 2000/11/08 05:58:24 itojun Exp $ */ | | 2 | /* $KAME: bftest.c,v 1.3 2000/11/08 05:58:24 itojun Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * Copyright (C) 2000 WIDE Project. | | 5 | * Copyright (C) 2000 WIDE Project. |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -87,27 +87,27 @@ | | | @@ -87,27 +87,27 @@ |
87 | * [including the GNU Public Licence.] | | 87 | * [including the GNU Public Licence.] |
88 | */ | | 88 | */ |
89 | | | 89 | |
90 | #include <sys/cdefs.h> | | 90 | #include <sys/cdefs.h> |
91 | #include <sys/types.h> | | 91 | #include <sys/types.h> |
92 | | | 92 | |
93 | #include <stdio.h> | | 93 | #include <stdio.h> |
94 | #include <string.h> | | 94 | #include <string.h> |
95 | #include <stdlib.h> | | 95 | #include <stdlib.h> |
96 | #include <unistd.h> | | 96 | #include <unistd.h> |
97 | | | 97 | |
98 | #include <crypto/blowfish/blowfish.h> | | 98 | #include <crypto/blowfish/blowfish.h> |
99 | | | 99 | |
100 | static char *bf_key[2]={ | | 100 | static const char *bf_key[2]={ |
101 | "abcdefghijklmnopqrstuvwxyz", | | 101 | "abcdefghijklmnopqrstuvwxyz", |
102 | "Who is John Galt?" | | 102 | "Who is John Galt?" |
103 | }; | | 103 | }; |
104 | | | 104 | |
105 | /* big endian */ | | 105 | /* big endian */ |
106 | static const char *bf_plain[2] = { | | 106 | static const char *bf_plain[2] = { |
107 | "424c4f5746495348", "fedcba9876543210" | | 107 | "424c4f5746495348", "fedcba9876543210" |
108 | }; | | 108 | }; |
109 | | | 109 | |
110 | static const char *bf_cipher[2] = { | | 110 | static const char *bf_cipher[2] = { |
111 | "324ed0fef413a203", "cc91732b8022f684" | | 111 | "324ed0fef413a203", "cc91732b8022f684" |
112 | }; | | 112 | }; |
113 | | | 113 | |
| @@ -155,27 +155,28 @@ main(argc, argv) | | | @@ -155,27 +155,28 @@ main(argc, argv) |
155 | int n, error = 0; | | 155 | int n, error = 0; |
156 | BF_KEY key; | | 156 | BF_KEY key; |
157 | BF_LONG data[2], plain[2], cipher[2]; | | 157 | BF_LONG data[2], plain[2], cipher[2]; |
158 | int rounds; | | 158 | int rounds; |
159 | | | 159 | |
160 | if (argc > 1) | | 160 | if (argc > 1) |
161 | rounds = atoi(argv[1]); | | 161 | rounds = atoi(argv[1]); |
162 | else | | 162 | else |
163 | rounds = 1; | | 163 | rounds = 1; |
164 | | | 164 | |
165 | printf("testing blowfish in raw ecb mode\n"); | | 165 | printf("testing blowfish in raw ecb mode\n"); |
166 | again: | | 166 | again: |
167 | for (n = 0; n < 2; n++) { | | 167 | for (n = 0; n < 2; n++) { |
168 | BF_set_key(&key, strlen(bf_key[n]), (unsigned char *)bf_key[n]); | | 168 | BF_set_key(&key, strlen(bf_key[n]), |
| | | 169 | (const unsigned char *)bf_key[n]); |
169 | | | 170 | |
170 | hex2bin((u_int8_t *)plain, bf_plain[n]); | | 171 | hex2bin((u_int8_t *)plain, bf_plain[n]); |
171 | hex2bin((u_int8_t *)cipher, bf_cipher[n]); | | 172 | hex2bin((u_int8_t *)cipher, bf_cipher[n]); |
172 | | | 173 | |
173 | memcpy(data, plain, 8); | | 174 | memcpy(data, plain, 8); |
174 | | | 175 | |
175 | data[0] = (BF_LONG)ntohl(data[0]); | | 176 | data[0] = (BF_LONG)ntohl(data[0]); |
176 | data[1] = (BF_LONG)ntohl(data[1]); | | 177 | data[1] = (BF_LONG)ntohl(data[1]); |
177 | BF_encrypt(data, &key); | | 178 | BF_encrypt(data, &key); |
178 | data[0] = (BF_LONG)htonl(data[0]); | | 179 | data[0] = (BF_LONG)htonl(data[0]); |
179 | data[1] = (BF_LONG)htonl(data[1]); | | 180 | data[1] = (BF_LONG)htonl(data[1]); |
180 | if (memcmp(data, cipher, 8) != 0) { | | 181 | if (memcmp(data, cipher, 8) != 0) { |
181 | printf("BF_encrypt error encrypting\n"); | | 182 | printf("BF_encrypt error encrypting\n"); |