aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Horman <nhorman@tuxdriver.com>2008-06-03 06:00:16 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2008-07-10 08:35:16 -0400
commitd729de23e86bbbb28adf6c3ded3651ea4ad8c539 (patch)
tree846b5998d403435621335ab44389d333c63196ff
parent5cdcc22f25b0766fe16d5dd8e3b2efc91fa4da6e (diff)
[CRYPTO] tcrypt: Add self test for des3_ebe cipher operating in cbc mode
Patch to add checking of DES3 test vectors using CBC mode. FIPS-140-2 compliance mandates that any supported mode of operation must include a self test. This satisfies that requirement for cbc(des3_ede). The included test vector was generated by me using openssl. Key/IV was generated with the following command: openssl enc -des_ede_cbc -P input and output values were generated by repeating the string "Too many secrets" a few times over, truncating it to 128 bytes, and encrypting it with openssl using the aformentioned key. Tested successfully by myself Signed-off-by: Neil Horman <nhorman@tuxdriver.com> Acked-by: Adrian-Ken Rueegsegger <rueegsegger@swiss-it.ch> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--crypto/tcrypt.c16
-rw-r--r--crypto/tcrypt.h93
2 files changed, 106 insertions, 3 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index e99cb4bc5463..ffc1ec6d279e 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -1220,6 +1220,14 @@ static void do_test(void)
1220 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template, 1220 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1221 DES3_EDE_DEC_TEST_VECTORS); 1221 DES3_EDE_DEC_TEST_VECTORS);
1222 1222
1223 test_cipher("cbc(des3_ede)", ENCRYPT,
1224 des3_ede_cbc_enc_tv_template,
1225 DES3_EDE_CBC_ENC_TEST_VECTORS);
1226
1227 test_cipher("cbc(des3_ede)", DECRYPT,
1228 des3_ede_cbc_dec_tv_template,
1229 DES3_EDE_CBC_DEC_TEST_VECTORS);
1230
1223 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); 1231 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1224 1232
1225 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS); 1233 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
@@ -1430,6 +1438,14 @@ static void do_test(void)
1430 DES3_EDE_ENC_TEST_VECTORS); 1438 DES3_EDE_ENC_TEST_VECTORS);
1431 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template, 1439 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1432 DES3_EDE_DEC_TEST_VECTORS); 1440 DES3_EDE_DEC_TEST_VECTORS);
1441
1442 test_cipher("cbc(des3_ede)", ENCRYPT,
1443 des3_ede_cbc_enc_tv_template,
1444 DES3_EDE_CBC_ENC_TEST_VECTORS);
1445
1446 test_cipher("cbc(des3_ede)", DECRYPT,
1447 des3_ede_cbc_dec_tv_template,
1448 DES3_EDE_CBC_DEC_TEST_VECTORS);
1433 break; 1449 break;
1434 1450
1435 case 5: 1451 case 5:
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h
index 20bd5fef0c08..801e0c288862 100644
--- a/crypto/tcrypt.h
+++ b/crypto/tcrypt.h
@@ -1863,6 +1863,8 @@ static struct hash_testvec hmac_sha512_tv_template[] = {
1863#define DES_CBC_DEC_TEST_VECTORS 4 1863#define DES_CBC_DEC_TEST_VECTORS 4
1864#define DES3_EDE_ENC_TEST_VECTORS 3 1864#define DES3_EDE_ENC_TEST_VECTORS 3
1865#define DES3_EDE_DEC_TEST_VECTORS 3 1865#define DES3_EDE_DEC_TEST_VECTORS 3
1866#define DES3_EDE_CBC_ENC_TEST_VECTORS 1
1867#define DES3_EDE_CBC_DEC_TEST_VECTORS 1
1866 1868
1867static struct cipher_testvec des_enc_tv_template[] = { 1869static struct cipher_testvec des_enc_tv_template[] = {
1868 { /* From Applied Cryptography */ 1870 { /* From Applied Cryptography */
@@ -2101,9 +2103,6 @@ static struct cipher_testvec des_cbc_dec_tv_template[] = {
2101 }, 2103 },
2102}; 2104};
2103 2105
2104/*
2105 * We really need some more test vectors, especially for DES3 CBC.
2106 */
2107static struct cipher_testvec des3_ede_enc_tv_template[] = { 2106static struct cipher_testvec des3_ede_enc_tv_template[] = {
2108 { /* These are from openssl */ 2107 { /* These are from openssl */
2109 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef" 2108 .key = "\x01\x23\x45\x67\x89\xab\xcd\xef"
@@ -2166,6 +2165,94 @@ static struct cipher_testvec des3_ede_dec_tv_template[] = {
2166 }, 2165 },
2167}; 2166};
2168 2167
2168static struct cipher_testvec des3_ede_cbc_enc_tv_template[] = {
2169 { /* Generated from openssl */
2170 .key = "\xE9\xC0\xFF\x2E\x76\x0B\x64\x24"
2171 "\x44\x4D\x99\x5A\x12\xD6\x40\xC0"
2172 "\xEA\xC2\x84\xE8\x14\x95\xDB\xE8",
2173 .klen = 24,
2174 .iv = "\x7D\x33\x88\x93\x0F\x93\xB2\x42",
2175 .input = "\x6f\x54\x20\x6f\x61\x4d\x79\x6e"
2176 "\x53\x20\x63\x65\x65\x72\x73\x74"
2177 "\x54\x20\x6f\x6f\x4d\x20\x6e\x61"
2178 "\x20\x79\x65\x53\x72\x63\x74\x65"
2179 "\x20\x73\x6f\x54\x20\x6f\x61\x4d"
2180 "\x79\x6e\x53\x20\x63\x65\x65\x72"
2181 "\x73\x74\x54\x20\x6f\x6f\x4d\x20"
2182 "\x6e\x61\x20\x79\x65\x53\x72\x63"
2183 "\x74\x65\x20\x73\x6f\x54\x20\x6f"
2184 "\x61\x4d\x79\x6e\x53\x20\x63\x65"
2185 "\x65\x72\x73\x74\x54\x20\x6f\x6f"
2186 "\x4d\x20\x6e\x61\x20\x79\x65\x53"
2187 "\x72\x63\x74\x65\x20\x73\x6f\x54"
2188 "\x20\x6f\x61\x4d\x79\x6e\x53\x20"
2189 "\x63\x65\x65\x72\x73\x74\x54\x20"
2190 "\x6f\x6f\x4d\x20\x6e\x61\x0a\x79",
2191 .ilen = 128,
2192 .result = "\x0e\x2d\xb6\x97\x3c\x56\x33\xf4"
2193 "\x67\x17\x21\xc7\x6e\x8a\xd5\x49"
2194 "\x74\xb3\x49\x05\xc5\x1c\xd0\xed"
2195 "\x12\x56\x5c\x53\x96\xb6\x00\x7d"
2196 "\x90\x48\xfc\xf5\x8d\x29\x39\xcc"
2197 "\x8a\xd5\x35\x18\x36\x23\x4e\xd7"
2198 "\x76\xd1\xda\x0c\x94\x67\xbb\x04"
2199 "\x8b\xf2\x03\x6c\xa8\xcf\xb6\xea"
2200 "\x22\x64\x47\xaa\x8f\x75\x13\xbf"
2201 "\x9f\xc2\xc3\xf0\xc9\x56\xc5\x7a"
2202 "\x71\x63\x2e\x89\x7b\x1e\x12\xca"
2203 "\xe2\x5f\xaf\xd8\xa4\xf8\xc9\x7a"
2204 "\xd6\xf9\x21\x31\x62\x44\x45\xa6"
2205 "\xd6\xbc\x5a\xd3\x2d\x54\x43\xcc"
2206 "\x9d\xde\xa5\x70\xe9\x42\x45\x8a"
2207 "\x6b\xfa\xb1\x91\x13\xb0\xd9\x19",
2208 .rlen = 128,
2209 },
2210};
2211
2212static struct cipher_testvec des3_ede_cbc_dec_tv_template[] = {
2213 { /* Generated from openssl */
2214 .key = "\xE9\xC0\xFF\x2E\x76\x0B\x64\x24"
2215 "\x44\x4D\x99\x5A\x12\xD6\x40\xC0"
2216 "\xEA\xC2\x84\xE8\x14\x95\xDB\xE8",
2217 .klen = 24,
2218 .iv = "\x7D\x33\x88\x93\x0F\x93\xB2\x42",
2219 .input = "\x0e\x2d\xb6\x97\x3c\x56\x33\xf4"
2220 "\x67\x17\x21\xc7\x6e\x8a\xd5\x49"
2221 "\x74\xb3\x49\x05\xc5\x1c\xd0\xed"
2222 "\x12\x56\x5c\x53\x96\xb6\x00\x7d"
2223 "\x90\x48\xfc\xf5\x8d\x29\x39\xcc"
2224 "\x8a\xd5\x35\x18\x36\x23\x4e\xd7"
2225 "\x76\xd1\xda\x0c\x94\x67\xbb\x04"
2226 "\x8b\xf2\x03\x6c\xa8\xcf\xb6\xea"
2227 "\x22\x64\x47\xaa\x8f\x75\x13\xbf"
2228 "\x9f\xc2\xc3\xf0\xc9\x56\xc5\x7a"
2229 "\x71\x63\x2e\x89\x7b\x1e\x12\xca"
2230 "\xe2\x5f\xaf\xd8\xa4\xf8\xc9\x7a"
2231 "\xd6\xf9\x21\x31\x62\x44\x45\xa6"
2232 "\xd6\xbc\x5a\xd3\x2d\x54\x43\xcc"
2233 "\x9d\xde\xa5\x70\xe9\x42\x45\x8a"
2234 "\x6b\xfa\xb1\x91\x13\xb0\xd9\x19",
2235 .ilen = 128,
2236 .result = "\x6f\x54\x20\x6f\x61\x4d\x79\x6e"
2237 "\x53\x20\x63\x65\x65\x72\x73\x74"
2238 "\x54\x20\x6f\x6f\x4d\x20\x6e\x61"
2239 "\x20\x79\x65\x53\x72\x63\x74\x65"
2240 "\x20\x73\x6f\x54\x20\x6f\x61\x4d"
2241 "\x79\x6e\x53\x20\x63\x65\x65\x72"
2242 "\x73\x74\x54\x20\x6f\x6f\x4d\x20"
2243 "\x6e\x61\x20\x79\x65\x53\x72\x63"
2244 "\x74\x65\x20\x73\x6f\x54\x20\x6f"
2245 "\x61\x4d\x79\x6e\x53\x20\x63\x65"
2246 "\x65\x72\x73\x74\x54\x20\x6f\x6f"
2247 "\x4d\x20\x6e\x61\x20\x79\x65\x53"
2248 "\x72\x63\x74\x65\x20\x73\x6f\x54"
2249 "\x20\x6f\x61\x4d\x79\x6e\x53\x20"
2250 "\x63\x65\x65\x72\x73\x74\x54\x20"
2251 "\x6f\x6f\x4d\x20\x6e\x61\x0a\x79",
2252 .rlen = 128,
2253 },
2254};
2255
2169/* 2256/*
2170 * Blowfish test vectors. 2257 * Blowfish test vectors.
2171 */ 2258 */