145818ee1SMatthew Ahrens /*
245818ee1SMatthew Ahrens * CDDL HEADER START
345818ee1SMatthew Ahrens *
445818ee1SMatthew Ahrens * The contents of this file are subject to the terms of the
545818ee1SMatthew Ahrens * Common Development and Distribution License (the "License").
645818ee1SMatthew Ahrens * You may not use this file except in compliance with the License.
745818ee1SMatthew Ahrens *
845818ee1SMatthew Ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
945818ee1SMatthew Ahrens * or http://opensource.org/licenses/CDDL-1.0.
1045818ee1SMatthew Ahrens * See the License for the specific language governing permissions
1145818ee1SMatthew Ahrens * and limitations under the License.
1245818ee1SMatthew Ahrens *
1345818ee1SMatthew Ahrens * When distributing Covered Code, include this CDDL HEADER in each
1445818ee1SMatthew Ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1545818ee1SMatthew Ahrens * If applicable, add the following below this CDDL HEADER, with the
1645818ee1SMatthew Ahrens * fields enclosed by brackets "[]" replaced with your own identifying
1745818ee1SMatthew Ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
1845818ee1SMatthew Ahrens *
1945818ee1SMatthew Ahrens * CDDL HEADER END
2045818ee1SMatthew Ahrens */
2145818ee1SMatthew Ahrens
2245818ee1SMatthew Ahrens /*
2345818ee1SMatthew Ahrens * Copyright 2013 Saso Kiselkov. All rights reserved.
2445818ee1SMatthew Ahrens */
2545818ee1SMatthew Ahrens
2645818ee1SMatthew Ahrens /*
2745818ee1SMatthew Ahrens * This is just to keep the compiler happy about sys/time.h not declaring
2845818ee1SMatthew Ahrens * gettimeofday due to -D_KERNEL (we can do this since we're actually
2945818ee1SMatthew Ahrens * running in userspace, but we need -D_KERNEL for the remaining Skein code).
3045818ee1SMatthew Ahrens */
3145818ee1SMatthew Ahrens #ifdef _KERNEL
3245818ee1SMatthew Ahrens #undef _KERNEL
3345818ee1SMatthew Ahrens #endif
3445818ee1SMatthew Ahrens
3545818ee1SMatthew Ahrens #include <sys/skein.h>
3645818ee1SMatthew Ahrens #include <stdlib.h>
3745818ee1SMatthew Ahrens #include <strings.h>
3845818ee1SMatthew Ahrens #include <stdio.h>
3945818ee1SMatthew Ahrens #include <sys/time.h>
4045818ee1SMatthew Ahrens #include <note.h>
4145818ee1SMatthew Ahrens
4245818ee1SMatthew Ahrens /*
4345818ee1SMatthew Ahrens * Skein test suite using values from the Skein V1.3 specification found at:
4445818ee1SMatthew Ahrens * http://www.skein-hash.info/sites/default/files/skein1.3.pdf
4545818ee1SMatthew Ahrens */
4645818ee1SMatthew Ahrens
4745818ee1SMatthew Ahrens /*
4845818ee1SMatthew Ahrens * Test messages from the Skein spec, Appendix C.
4945818ee1SMatthew Ahrens */
5045818ee1SMatthew Ahrens const uint8_t test_msg0[] = {
5145818ee1SMatthew Ahrens 0xFF
5245818ee1SMatthew Ahrens };
5345818ee1SMatthew Ahrens
5445818ee1SMatthew Ahrens const uint8_t test_msg1[] = {
5545818ee1SMatthew Ahrens 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
5645818ee1SMatthew Ahrens 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0,
5745818ee1SMatthew Ahrens 0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8,
5845818ee1SMatthew Ahrens 0xE7, 0xE6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1, 0xE0
5945818ee1SMatthew Ahrens };
6045818ee1SMatthew Ahrens
6145818ee1SMatthew Ahrens const uint8_t test_msg2[] = {
6245818ee1SMatthew Ahrens 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
6345818ee1SMatthew Ahrens 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0,
6445818ee1SMatthew Ahrens 0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8,
6545818ee1SMatthew Ahrens 0xE7, 0xE6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1, 0xE0,
6645818ee1SMatthew Ahrens 0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8,
6745818ee1SMatthew Ahrens 0xD7, 0xD6, 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xD0,
6845818ee1SMatthew Ahrens 0xCF, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC8,
6945818ee1SMatthew Ahrens 0xC7, 0xC6, 0xC5, 0xC4, 0xC3, 0xC2, 0xC1, 0xC0
7045818ee1SMatthew Ahrens };
7145818ee1SMatthew Ahrens
7245818ee1SMatthew Ahrens const uint8_t test_msg3[] = {
7345818ee1SMatthew Ahrens 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
7445818ee1SMatthew Ahrens 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0,
7545818ee1SMatthew Ahrens 0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8,
7645818ee1SMatthew Ahrens 0xE7, 0xE6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1, 0xE0,
7745818ee1SMatthew Ahrens 0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8,
7845818ee1SMatthew Ahrens 0xD7, 0xD6, 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xD0,
7945818ee1SMatthew Ahrens 0xCF, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC8,
8045818ee1SMatthew Ahrens 0xC7, 0xC6, 0xC5, 0xC4, 0xC3, 0xC2, 0xC1, 0xC0,
8145818ee1SMatthew Ahrens 0xBF, 0xBE, 0xBD, 0xBC, 0xBB, 0xBA, 0xB9, 0xB8,
8245818ee1SMatthew Ahrens 0xB7, 0xB6, 0xB5, 0xB4, 0xB3, 0xB2, 0xB1, 0xB0,
8345818ee1SMatthew Ahrens 0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8,
8445818ee1SMatthew Ahrens 0xA7, 0xA6, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1, 0xA0,
8545818ee1SMatthew Ahrens 0x9F, 0x9E, 0x9D, 0x9C, 0x9B, 0x9A, 0x99, 0x98,
8645818ee1SMatthew Ahrens 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91, 0x90,
8745818ee1SMatthew Ahrens 0x8F, 0x8E, 0x8D, 0x8C, 0x8B, 0x8A, 0x89, 0x88,
8845818ee1SMatthew Ahrens 0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80
8945818ee1SMatthew Ahrens };
9045818ee1SMatthew Ahrens
9145818ee1SMatthew Ahrens const uint8_t test_msg4[] = {
9245818ee1SMatthew Ahrens 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
9345818ee1SMatthew Ahrens 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0,
9445818ee1SMatthew Ahrens 0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8,
9545818ee1SMatthew Ahrens 0xE7, 0xE6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1, 0xE0,
9645818ee1SMatthew Ahrens 0xDF, 0xDE, 0xDD, 0xDC, 0xDB, 0xDA, 0xD9, 0xD8,
9745818ee1SMatthew Ahrens 0xD7, 0xD6, 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xD0,
9845818ee1SMatthew Ahrens 0xCF, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC8,
9945818ee1SMatthew Ahrens 0xC7, 0xC6, 0xC5, 0xC4, 0xC3, 0xC2, 0xC1, 0xC0,
10045818ee1SMatthew Ahrens 0xBF, 0xBE, 0xBD, 0xBC, 0xBB, 0xBA, 0xB9, 0xB8,
10145818ee1SMatthew Ahrens 0xB7, 0xB6, 0xB5, 0xB4, 0xB3, 0xB2, 0xB1, 0xB0,
10245818ee1SMatthew Ahrens 0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8,
10345818ee1SMatthew Ahrens 0xA7, 0xA6, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1, 0xA0,
10445818ee1SMatthew Ahrens 0x9F, 0x9E, 0x9D, 0x9C, 0x9B, 0x9A, 0x99, 0x98,
10545818ee1SMatthew Ahrens 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91, 0x90,
10645818ee1SMatthew Ahrens 0x8F, 0x8E, 0x8D, 0x8C, 0x8B, 0x8A, 0x89, 0x88,
10745818ee1SMatthew Ahrens 0x87, 0x86, 0x85, 0x84, 0x83, 0x82, 0x81, 0x80,
10845818ee1SMatthew Ahrens 0x7F, 0x7E, 0x7D, 0x7C, 0x7B, 0x7A, 0x79, 0x78,
10945818ee1SMatthew Ahrens 0x77, 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x70,
11045818ee1SMatthew Ahrens 0x6F, 0x6E, 0x6D, 0x6C, 0x6B, 0x6A, 0x69, 0x68,
11145818ee1SMatthew Ahrens 0x67, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x60,
11245818ee1SMatthew Ahrens 0x5F, 0x5E, 0x5D, 0x5C, 0x5B, 0x5A, 0x59, 0x58,
11345818ee1SMatthew Ahrens 0x57, 0x56, 0x55, 0x54, 0x53, 0x52, 0x51, 0x50,
11445818ee1SMatthew Ahrens 0x4F, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A, 0x49, 0x48,
11545818ee1SMatthew Ahrens 0x47, 0x46, 0x45, 0x44, 0x43, 0x42, 0x41, 0x40,
11645818ee1SMatthew Ahrens 0x3F, 0x3E, 0x3D, 0x3C, 0x3B, 0x3A, 0x39, 0x38,
11745818ee1SMatthew Ahrens 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30,
11845818ee1SMatthew Ahrens 0x2F, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, 0x28,
11945818ee1SMatthew Ahrens 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20,
12045818ee1SMatthew Ahrens 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18,
12145818ee1SMatthew Ahrens 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10,
12245818ee1SMatthew Ahrens 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08,
12345818ee1SMatthew Ahrens 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00
12445818ee1SMatthew Ahrens };
12545818ee1SMatthew Ahrens
12645818ee1SMatthew Ahrens /*
12745818ee1SMatthew Ahrens * Test digests from the Skein spec, Appendix C.
12845818ee1SMatthew Ahrens */
12945818ee1SMatthew Ahrens const uint8_t skein_256_test_digests[][32] = {
13045818ee1SMatthew Ahrens {
13145818ee1SMatthew Ahrens /* for test_msg0 */
13245818ee1SMatthew Ahrens 0x0B, 0x98, 0xDC, 0xD1, 0x98, 0xEA, 0x0E, 0x50,
13345818ee1SMatthew Ahrens 0xA7, 0xA2, 0x44, 0xC4, 0x44, 0xE2, 0x5C, 0x23,
13445818ee1SMatthew Ahrens 0xDA, 0x30, 0xC1, 0x0F, 0xC9, 0xA1, 0xF2, 0x70,
13545818ee1SMatthew Ahrens 0xA6, 0x63, 0x7F, 0x1F, 0x34, 0xE6, 0x7E, 0xD2
13645818ee1SMatthew Ahrens },
13745818ee1SMatthew Ahrens {
13845818ee1SMatthew Ahrens /* for test_msg1 */
13945818ee1SMatthew Ahrens 0x8D, 0x0F, 0xA4, 0xEF, 0x77, 0x7F, 0xD7, 0x59,
14045818ee1SMatthew Ahrens 0xDF, 0xD4, 0x04, 0x4E, 0x6F, 0x6A, 0x5A, 0xC3,
14145818ee1SMatthew Ahrens 0xC7, 0x74, 0xAE, 0xC9, 0x43, 0xDC, 0xFC, 0x07,
14245818ee1SMatthew Ahrens 0x92, 0x7B, 0x72, 0x3B, 0x5D, 0xBF, 0x40, 0x8B
14345818ee1SMatthew Ahrens },
14445818ee1SMatthew Ahrens {
14545818ee1SMatthew Ahrens /* for test_msg2 */
14645818ee1SMatthew Ahrens 0xDF, 0x28, 0xE9, 0x16, 0x63, 0x0D, 0x0B, 0x44,
14745818ee1SMatthew Ahrens 0xC4, 0xA8, 0x49, 0xDC, 0x9A, 0x02, 0xF0, 0x7A,
14845818ee1SMatthew Ahrens 0x07, 0xCB, 0x30, 0xF7, 0x32, 0x31, 0x82, 0x56,
14945818ee1SMatthew Ahrens 0xB1, 0x5D, 0x86, 0x5A, 0xC4, 0xAE, 0x16, 0x2F
15045818ee1SMatthew Ahrens }
15145818ee1SMatthew Ahrens /* no test digests for test_msg3 and test_msg4 */
15245818ee1SMatthew Ahrens };
15345818ee1SMatthew Ahrens
15445818ee1SMatthew Ahrens const uint8_t skein_512_test_digests[][64] = {
15545818ee1SMatthew Ahrens {
15645818ee1SMatthew Ahrens /* for test_msg0 */
15745818ee1SMatthew Ahrens 0x71, 0xB7, 0xBC, 0xE6, 0xFE, 0x64, 0x52, 0x22,
15845818ee1SMatthew Ahrens 0x7B, 0x9C, 0xED, 0x60, 0x14, 0x24, 0x9E, 0x5B,
15945818ee1SMatthew Ahrens 0xF9, 0xA9, 0x75, 0x4C, 0x3A, 0xD6, 0x18, 0xCC,
16045818ee1SMatthew Ahrens 0xC4, 0xE0, 0xAA, 0xE1, 0x6B, 0x31, 0x6C, 0xC8,
16145818ee1SMatthew Ahrens 0xCA, 0x69, 0x8D, 0x86, 0x43, 0x07, 0xED, 0x3E,
16245818ee1SMatthew Ahrens 0x80, 0xB6, 0xEF, 0x15, 0x70, 0x81, 0x2A, 0xC5,
16345818ee1SMatthew Ahrens 0x27, 0x2D, 0xC4, 0x09, 0xB5, 0xA0, 0x12, 0xDF,
16445818ee1SMatthew Ahrens 0x2A, 0x57, 0x91, 0x02, 0xF3, 0x40, 0x61, 0x7A
16545818ee1SMatthew Ahrens },
16645818ee1SMatthew Ahrens {
16745818ee1SMatthew Ahrens /* no test vector for test_msg1 */
168*0c3cd038SMatthew Ahrens 0
16945818ee1SMatthew Ahrens },
17045818ee1SMatthew Ahrens {
17145818ee1SMatthew Ahrens /* for test_msg2 */
17245818ee1SMatthew Ahrens 0x45, 0x86, 0x3B, 0xA3, 0xBE, 0x0C, 0x4D, 0xFC,
17345818ee1SMatthew Ahrens 0x27, 0xE7, 0x5D, 0x35, 0x84, 0x96, 0xF4, 0xAC,
17445818ee1SMatthew Ahrens 0x9A, 0x73, 0x6A, 0x50, 0x5D, 0x93, 0x13, 0xB4,
17545818ee1SMatthew Ahrens 0x2B, 0x2F, 0x5E, 0xAD, 0xA7, 0x9F, 0xC1, 0x7F,
17645818ee1SMatthew Ahrens 0x63, 0x86, 0x1E, 0x94, 0x7A, 0xFB, 0x1D, 0x05,
17745818ee1SMatthew Ahrens 0x6A, 0xA1, 0x99, 0x57, 0x5A, 0xD3, 0xF8, 0xC9,
17845818ee1SMatthew Ahrens 0xA3, 0xCC, 0x17, 0x80, 0xB5, 0xE5, 0xFA, 0x4C,
17945818ee1SMatthew Ahrens 0xAE, 0x05, 0x0E, 0x98, 0x98, 0x76, 0x62, 0x5B
18045818ee1SMatthew Ahrens },
18145818ee1SMatthew Ahrens {
18245818ee1SMatthew Ahrens /* for test_msg3 */
18345818ee1SMatthew Ahrens 0x91, 0xCC, 0xA5, 0x10, 0xC2, 0x63, 0xC4, 0xDD,
18445818ee1SMatthew Ahrens 0xD0, 0x10, 0x53, 0x0A, 0x33, 0x07, 0x33, 0x09,
18545818ee1SMatthew Ahrens 0x62, 0x86, 0x31, 0xF3, 0x08, 0x74, 0x7E, 0x1B,
18645818ee1SMatthew Ahrens 0xCB, 0xAA, 0x90, 0xE4, 0x51, 0xCA, 0xB9, 0x2E,
18745818ee1SMatthew Ahrens 0x51, 0x88, 0x08, 0x7A, 0xF4, 0x18, 0x87, 0x73,
18845818ee1SMatthew Ahrens 0xA3, 0x32, 0x30, 0x3E, 0x66, 0x67, 0xA7, 0xA2,
18945818ee1SMatthew Ahrens 0x10, 0x85, 0x6F, 0x74, 0x21, 0x39, 0x00, 0x00,
19045818ee1SMatthew Ahrens 0x71, 0xF4, 0x8E, 0x8B, 0xA2, 0xA5, 0xAD, 0xB7
19145818ee1SMatthew Ahrens }
19245818ee1SMatthew Ahrens /* no test digests for test_msg4 */
19345818ee1SMatthew Ahrens };
19445818ee1SMatthew Ahrens
19545818ee1SMatthew Ahrens const uint8_t skein_1024_test_digests[][128] = {
19645818ee1SMatthew Ahrens {
19745818ee1SMatthew Ahrens /* for test_msg0 */
19845818ee1SMatthew Ahrens 0xE6, 0x2C, 0x05, 0x80, 0x2E, 0xA0, 0x15, 0x24,
19945818ee1SMatthew Ahrens 0x07, 0xCD, 0xD8, 0x78, 0x7F, 0xDA, 0x9E, 0x35,
20045818ee1SMatthew Ahrens 0x70, 0x3D, 0xE8, 0x62, 0xA4, 0xFB, 0xC1, 0x19,
20145818ee1SMatthew Ahrens 0xCF, 0xF8, 0x59, 0x0A, 0xFE, 0x79, 0x25, 0x0B,
20245818ee1SMatthew Ahrens 0xCC, 0xC8, 0xB3, 0xFA, 0xF1, 0xBD, 0x24, 0x22,
20345818ee1SMatthew Ahrens 0xAB, 0x5C, 0x0D, 0x26, 0x3F, 0xB2, 0xF8, 0xAF,
20445818ee1SMatthew Ahrens 0xB3, 0xF7, 0x96, 0xF0, 0x48, 0x00, 0x03, 0x81,
20545818ee1SMatthew Ahrens 0x53, 0x1B, 0x6F, 0x00, 0xD8, 0x51, 0x61, 0xBC,
20645818ee1SMatthew Ahrens 0x0F, 0xFF, 0x4B, 0xEF, 0x24, 0x86, 0xB1, 0xEB,
20745818ee1SMatthew Ahrens 0xCD, 0x37, 0x73, 0xFA, 0xBF, 0x50, 0xAD, 0x4A,
20845818ee1SMatthew Ahrens 0xD5, 0x63, 0x9A, 0xF9, 0x04, 0x0E, 0x3F, 0x29,
20945818ee1SMatthew Ahrens 0xC6, 0xC9, 0x31, 0x30, 0x1B, 0xF7, 0x98, 0x32,
21045818ee1SMatthew Ahrens 0xE9, 0xDA, 0x09, 0x85, 0x7E, 0x83, 0x1E, 0x82,
21145818ee1SMatthew Ahrens 0xEF, 0x8B, 0x46, 0x91, 0xC2, 0x35, 0x65, 0x65,
21245818ee1SMatthew Ahrens 0x15, 0xD4, 0x37, 0xD2, 0xBD, 0xA3, 0x3B, 0xCE,
21345818ee1SMatthew Ahrens 0xC0, 0x01, 0xC6, 0x7F, 0xFD, 0xE1, 0x5B, 0xA8
21445818ee1SMatthew Ahrens },
21545818ee1SMatthew Ahrens {
21645818ee1SMatthew Ahrens /* no test vector for test_msg1 */
217*0c3cd038SMatthew Ahrens 0
21845818ee1SMatthew Ahrens },
21945818ee1SMatthew Ahrens {
22045818ee1SMatthew Ahrens /* no test vector for test_msg2 */
221*0c3cd038SMatthew Ahrens 0
22245818ee1SMatthew Ahrens },
22345818ee1SMatthew Ahrens {
22445818ee1SMatthew Ahrens /* for test_msg3 */
22545818ee1SMatthew Ahrens 0x1F, 0x3E, 0x02, 0xC4, 0x6F, 0xB8, 0x0A, 0x3F,
22645818ee1SMatthew Ahrens 0xCD, 0x2D, 0xFB, 0xBC, 0x7C, 0x17, 0x38, 0x00,
22745818ee1SMatthew Ahrens 0xB4, 0x0C, 0x60, 0xC2, 0x35, 0x4A, 0xF5, 0x51,
22845818ee1SMatthew Ahrens 0x18, 0x9E, 0xBF, 0x43, 0x3C, 0x3D, 0x85, 0xF9,
22945818ee1SMatthew Ahrens 0xFF, 0x18, 0x03, 0xE6, 0xD9, 0x20, 0x49, 0x31,
23045818ee1SMatthew Ahrens 0x79, 0xED, 0x7A, 0xE7, 0xFC, 0xE6, 0x9C, 0x35,
23145818ee1SMatthew Ahrens 0x81, 0xA5, 0xA2, 0xF8, 0x2D, 0x3E, 0x0C, 0x7A,
23245818ee1SMatthew Ahrens 0x29, 0x55, 0x74, 0xD0, 0xCD, 0x7D, 0x21, 0x7C,
23345818ee1SMatthew Ahrens 0x48, 0x4D, 0x2F, 0x63, 0x13, 0xD5, 0x9A, 0x77,
23445818ee1SMatthew Ahrens 0x18, 0xEA, 0xD0, 0x7D, 0x07, 0x29, 0xC2, 0x48,
23545818ee1SMatthew Ahrens 0x51, 0xD7, 0xE7, 0xD2, 0x49, 0x1B, 0x90, 0x2D,
23645818ee1SMatthew Ahrens 0x48, 0x91, 0x94, 0xE6, 0xB7, 0xD3, 0x69, 0xDB,
23745818ee1SMatthew Ahrens 0x0A, 0xB7, 0xAA, 0x10, 0x6F, 0x0E, 0xE0, 0xA3,
23845818ee1SMatthew Ahrens 0x9A, 0x42, 0xEF, 0xC5, 0x4F, 0x18, 0xD9, 0x37,
23945818ee1SMatthew Ahrens 0x76, 0x08, 0x09, 0x85, 0xF9, 0x07, 0x57, 0x4F,
24045818ee1SMatthew Ahrens 0x99, 0x5E, 0xC6, 0xA3, 0x71, 0x53, 0xA5, 0x78
24145818ee1SMatthew Ahrens },
24245818ee1SMatthew Ahrens {
24345818ee1SMatthew Ahrens /* for test_msg4 */
24445818ee1SMatthew Ahrens 0x84, 0x2A, 0x53, 0xC9, 0x9C, 0x12, 0xB0, 0xCF,
24545818ee1SMatthew Ahrens 0x80, 0xCF, 0x69, 0x49, 0x1B, 0xE5, 0xE2, 0xF7,
24645818ee1SMatthew Ahrens 0x51, 0x5D, 0xE8, 0x73, 0x3B, 0x6E, 0xA9, 0x42,
24745818ee1SMatthew Ahrens 0x2D, 0xFD, 0x67, 0x66, 0x65, 0xB5, 0xFA, 0x42,
24845818ee1SMatthew Ahrens 0xFF, 0xB3, 0xA9, 0xC4, 0x8C, 0x21, 0x77, 0x77,
24945818ee1SMatthew Ahrens 0x95, 0x08, 0x48, 0xCE, 0xCD, 0xB4, 0x8F, 0x64,
25045818ee1SMatthew Ahrens 0x0F, 0x81, 0xFB, 0x92, 0xBE, 0xF6, 0xF8, 0x8F,
25145818ee1SMatthew Ahrens 0x7A, 0x85, 0xC1, 0xF7, 0xCD, 0x14, 0x46, 0xC9,
25245818ee1SMatthew Ahrens 0x16, 0x1C, 0x0A, 0xFE, 0x8F, 0x25, 0xAE, 0x44,
25345818ee1SMatthew Ahrens 0x4F, 0x40, 0xD3, 0x68, 0x00, 0x81, 0xC3, 0x5A,
25445818ee1SMatthew Ahrens 0xA4, 0x3F, 0x64, 0x0F, 0xD5, 0xFA, 0x3C, 0x3C,
25545818ee1SMatthew Ahrens 0x03, 0x0B, 0xCC, 0x06, 0xAB, 0xAC, 0x01, 0xD0,
25645818ee1SMatthew Ahrens 0x98, 0xBC, 0xC9, 0x84, 0xEB, 0xD8, 0x32, 0x27,
25745818ee1SMatthew Ahrens 0x12, 0x92, 0x1E, 0x00, 0xB1, 0xBA, 0x07, 0xD6,
25845818ee1SMatthew Ahrens 0xD0, 0x1F, 0x26, 0x90, 0x70, 0x50, 0x25, 0x5E,
25945818ee1SMatthew Ahrens 0xF2, 0xC8, 0xE2, 0x4F, 0x71, 0x6C, 0x52, 0xA5
26045818ee1SMatthew Ahrens }
26145818ee1SMatthew Ahrens };
26245818ee1SMatthew Ahrens
26345818ee1SMatthew Ahrens int
main(int argc,char * argv[])26445818ee1SMatthew Ahrens main(int argc, char *argv[])
26545818ee1SMatthew Ahrens {
26645818ee1SMatthew Ahrens boolean_t failed = B_FALSE;
26745818ee1SMatthew Ahrens uint64_t cpu_mhz = 0;
26845818ee1SMatthew Ahrens
26945818ee1SMatthew Ahrens if (argc == 2)
27045818ee1SMatthew Ahrens cpu_mhz = atoi(argv[1]);
27145818ee1SMatthew Ahrens
27245818ee1SMatthew Ahrens #define SKEIN_ALGO_TEST(_m, mode, diglen, testdigest) \
27345818ee1SMatthew Ahrens do { \
27445818ee1SMatthew Ahrens Skein ## mode ## _Ctxt_t ctx; \
27545818ee1SMatthew Ahrens uint8_t digest[diglen / 8]; \
27645818ee1SMatthew Ahrens (void) Skein ## mode ## _Init(&ctx, diglen); \
27745818ee1SMatthew Ahrens (void) Skein ## mode ## _Update(&ctx, _m, sizeof (_m)); \
27845818ee1SMatthew Ahrens (void) Skein ## mode ## _Final(&ctx, digest); \
27945818ee1SMatthew Ahrens (void) printf("Skein" #mode "/" #diglen \
28045818ee1SMatthew Ahrens "\tMessage: " #_m "\tResult: "); \
28145818ee1SMatthew Ahrens if (bcmp(digest, testdigest, diglen / 8) == 0) { \
28245818ee1SMatthew Ahrens (void) printf("OK\n"); \
28345818ee1SMatthew Ahrens } else { \
28445818ee1SMatthew Ahrens (void) printf("FAILED!\n"); \
28545818ee1SMatthew Ahrens failed = B_TRUE; \
28645818ee1SMatthew Ahrens } \
28745818ee1SMatthew Ahrens NOTE(CONSTCOND) \
28845818ee1SMatthew Ahrens } while (0)
28945818ee1SMatthew Ahrens
29045818ee1SMatthew Ahrens #define SKEIN_PERF_TEST(mode, diglen) \
29145818ee1SMatthew Ahrens do { \
29245818ee1SMatthew Ahrens Skein ## mode ## _Ctxt_t ctx; \
29345818ee1SMatthew Ahrens uint8_t digest[diglen / 8]; \
29445818ee1SMatthew Ahrens uint8_t block[131072]; \
29545818ee1SMatthew Ahrens uint64_t delta; \
29645818ee1SMatthew Ahrens double cpb = 0; \
29745818ee1SMatthew Ahrens int i; \
29845818ee1SMatthew Ahrens struct timeval start, end; \
29945818ee1SMatthew Ahrens bzero(block, sizeof (block)); \
30045818ee1SMatthew Ahrens (void) gettimeofday(&start, NULL); \
30145818ee1SMatthew Ahrens (void) Skein ## mode ## _Init(&ctx, diglen); \
30245818ee1SMatthew Ahrens for (i = 0; i < 8192; i++) { \
30345818ee1SMatthew Ahrens (void) Skein ## mode ## _Update(&ctx, block, \
30445818ee1SMatthew Ahrens sizeof (block)); \
30545818ee1SMatthew Ahrens } \
30645818ee1SMatthew Ahrens (void) Skein ## mode ## _Final(&ctx, digest); \
30745818ee1SMatthew Ahrens (void) gettimeofday(&end, NULL); \
30845818ee1SMatthew Ahrens delta = (end.tv_sec * 1000000llu + end.tv_usec) - \
30945818ee1SMatthew Ahrens (start.tv_sec * 1000000llu + start.tv_usec); \
31045818ee1SMatthew Ahrens if (cpu_mhz != 0) { \
31145818ee1SMatthew Ahrens cpb = (cpu_mhz * 1e6 * ((double)delta / \
31245818ee1SMatthew Ahrens 1000000)) / (8192 * 128 * 1024); \
31345818ee1SMatthew Ahrens } \
31445818ee1SMatthew Ahrens (void) printf("Skein" #mode "/" #diglen "\t%llu us " \
31545818ee1SMatthew Ahrens "(%.02f CPB)\n", (u_longlong_t)delta, cpb); \
31645818ee1SMatthew Ahrens NOTE(CONSTCOND) \
31745818ee1SMatthew Ahrens } while (0)
31845818ee1SMatthew Ahrens
31945818ee1SMatthew Ahrens (void) printf("Running algorithm correctness tests:\n");
32045818ee1SMatthew Ahrens SKEIN_ALGO_TEST(test_msg0, _256, 256, skein_256_test_digests[0]);
32145818ee1SMatthew Ahrens SKEIN_ALGO_TEST(test_msg1, _256, 256, skein_256_test_digests[1]);
32245818ee1SMatthew Ahrens SKEIN_ALGO_TEST(test_msg2, _256, 256, skein_256_test_digests[2]);
32345818ee1SMatthew Ahrens SKEIN_ALGO_TEST(test_msg0, _512, 512, skein_512_test_digests[0]);
32445818ee1SMatthew Ahrens SKEIN_ALGO_TEST(test_msg2, _512, 512, skein_512_test_digests[2]);
32545818ee1SMatthew Ahrens SKEIN_ALGO_TEST(test_msg3, _512, 512, skein_512_test_digests[3]);
32645818ee1SMatthew Ahrens SKEIN_ALGO_TEST(test_msg0, 1024, 1024, skein_1024_test_digests[0]);
32745818ee1SMatthew Ahrens SKEIN_ALGO_TEST(test_msg3, 1024, 1024, skein_1024_test_digests[3]);
32845818ee1SMatthew Ahrens SKEIN_ALGO_TEST(test_msg4, 1024, 1024, skein_1024_test_digests[4]);
32945818ee1SMatthew Ahrens if (failed)
33045818ee1SMatthew Ahrens return (1);
33145818ee1SMatthew Ahrens
33245818ee1SMatthew Ahrens (void) printf("Running performance tests (hashing 1024 MiB of "
33345818ee1SMatthew Ahrens "data):\n");
33445818ee1SMatthew Ahrens SKEIN_PERF_TEST(_256, 256);
33545818ee1SMatthew Ahrens SKEIN_PERF_TEST(_512, 512);
33645818ee1SMatthew Ahrens SKEIN_PERF_TEST(1024, 1024);
33745818ee1SMatthew Ahrens
33845818ee1SMatthew Ahrens return (0);
33945818ee1SMatthew Ahrens }
340