1*9d12795fSRobert Mustacchi /* 2*9d12795fSRobert Mustacchi * This file and its contents are supplied under the terms of the 3*9d12795fSRobert Mustacchi * Common Development and Distribution License ("CDDL"), version 1.0. 4*9d12795fSRobert Mustacchi * You may only use this file in accordance with the terms of version 5*9d12795fSRobert Mustacchi * 1.0 of the CDDL. 6*9d12795fSRobert Mustacchi * 7*9d12795fSRobert Mustacchi * A full copy of the text of the CDDL should have accompanied this 8*9d12795fSRobert Mustacchi * source. A copy of the CDDL is also available via the Internet at 9*9d12795fSRobert Mustacchi * http://www.illumos.org/license/CDDL. 10*9d12795fSRobert Mustacchi */ 11*9d12795fSRobert Mustacchi 12*9d12795fSRobert Mustacchi /* 13*9d12795fSRobert Mustacchi * Copyright (c) 2015, Joyent, Inc. 14*9d12795fSRobert Mustacchi */ 15*9d12795fSRobert Mustacchi 16*9d12795fSRobert Mustacchi /* 17*9d12795fSRobert Mustacchi * Test chacha20 key stream with known TVs. 18*9d12795fSRobert Mustacchi * 19*9d12795fSRobert Mustacchi * Based on data from: 20*9d12795fSRobert Mustacchi * https://tools.ietf.org/html/draft-strombergson-chacha-test-vectors-01 21*9d12795fSRobert Mustacchi */ 22*9d12795fSRobert Mustacchi 23*9d12795fSRobert Mustacchi #include <strings.h> 24*9d12795fSRobert Mustacchi #include <chacha.h> 25*9d12795fSRobert Mustacchi #include <assert.h> 26*9d12795fSRobert Mustacchi 27*9d12795fSRobert Mustacchi /* Test Vector 1 */ 28*9d12795fSRobert Mustacchi 29*9d12795fSRobert Mustacchi static uint8_t cha_key1[16] = { 30*9d12795fSRobert Mustacchi 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 31*9d12795fSRobert Mustacchi 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 32*9d12795fSRobert Mustacchi }; 33*9d12795fSRobert Mustacchi static uint8_t cha_iv1[8] = { 34*9d12795fSRobert Mustacchi 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 35*9d12795fSRobert Mustacchi }; 36*9d12795fSRobert Mustacchi static uint8_t cha_fbl1[] = { 37*9d12795fSRobert Mustacchi 0x89, 0x67, 0x09, 0x52, 0x60, 0x83, 0x64, 0xfd, 38*9d12795fSRobert Mustacchi 0x00, 0xb2, 0xf9, 0x09, 0x36, 0xf0, 0x31, 0xc8, 39*9d12795fSRobert Mustacchi 0xe7, 0x56, 0xe1, 0x5d, 0xba, 0x04, 0xb8, 0x49, 40*9d12795fSRobert Mustacchi 0x3d, 0x00, 0x42, 0x92, 0x59, 0xb2, 0x0f, 0x46, 41*9d12795fSRobert Mustacchi 0xcc, 0x04, 0xf1, 0x11, 0x24, 0x6b, 0x6c, 0x2c, 42*9d12795fSRobert Mustacchi 0xe0, 0x66, 0xbe, 0x3b, 0xfb, 0x32, 0xd9, 0xaa, 43*9d12795fSRobert Mustacchi 0x0f, 0xdd, 0xfb, 0xc1, 0x21, 0x23, 0xd4, 0xb9, 44*9d12795fSRobert Mustacchi 0xe4, 0x4f, 0x34, 0xdc, 0xa0, 0x5a, 0x10, 0x3f 45*9d12795fSRobert Mustacchi }; 46*9d12795fSRobert Mustacchi static uint8_t cha_sbl1[] = { 47*9d12795fSRobert Mustacchi 0x6c, 0xd1, 0x35, 0xc2, 0x87, 0x8c, 0x83, 0x2b, 48*9d12795fSRobert Mustacchi 0x58, 0x96, 0xb1, 0x34, 0xf6, 0x14, 0x2a, 0x9d, 49*9d12795fSRobert Mustacchi 0x4d, 0x8d, 0x0d, 0x8f, 0x10, 0x26, 0xd2, 0x0a, 50*9d12795fSRobert Mustacchi 0x0a, 0x81, 0x51, 0x2c, 0xbc, 0xe6, 0xe9, 0x75, 51*9d12795fSRobert Mustacchi 0x8a, 0x71, 0x43, 0xd0, 0x21, 0x97, 0x80, 0x22, 52*9d12795fSRobert Mustacchi 0xa3, 0x84, 0x14, 0x1a, 0x80, 0xce, 0xa3, 0x06, 53*9d12795fSRobert Mustacchi 0x2f, 0x41, 0xf6, 0x7a, 0x75, 0x2e, 0x66, 0xad, 54*9d12795fSRobert Mustacchi 0x34, 0x11, 0x98, 0x4c, 0x78, 0x7e, 0x30, 0xad 55*9d12795fSRobert Mustacchi }; 56*9d12795fSRobert Mustacchi 57*9d12795fSRobert Mustacchi /* Test Vector 2 */ 58*9d12795fSRobert Mustacchi static uint8_t cha_key2[16] = { 59*9d12795fSRobert Mustacchi 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60*9d12795fSRobert Mustacchi 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 61*9d12795fSRobert Mustacchi }; 62*9d12795fSRobert Mustacchi static uint8_t cha_iv2[8] = { 63*9d12795fSRobert Mustacchi 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 64*9d12795fSRobert Mustacchi }; 65*9d12795fSRobert Mustacchi 66*9d12795fSRobert Mustacchi static uint8_t cha_fbl2[] = { 67*9d12795fSRobert Mustacchi 0xae, 0x56, 0x06, 0x0d, 0x04, 0xf5, 0xb5, 0x97, 68*9d12795fSRobert Mustacchi 0x89, 0x7f, 0xf2, 0xaf, 0x13, 0x88, 0xdb, 0xce, 69*9d12795fSRobert Mustacchi 0xff, 0x5a, 0x2a, 0x49, 0x20, 0x33, 0x5d, 0xc1, 70*9d12795fSRobert Mustacchi 0x7a, 0x3c, 0xb1, 0xb1, 0xb1, 0x0f, 0xbe, 0x70, 71*9d12795fSRobert Mustacchi 0xec, 0xe8, 0xf4, 0x86, 0x4d, 0x8c, 0x7c, 0xdf, 72*9d12795fSRobert Mustacchi 0x00, 0x76, 0x45, 0x3a, 0x82, 0x91, 0xc7, 0xdb, 73*9d12795fSRobert Mustacchi 0xeb, 0x3a, 0xa9, 0xc9, 0xd1, 0x0e, 0x8c, 0xa3, 74*9d12795fSRobert Mustacchi 0x6b, 0xe4, 0x44, 0x93, 0x76, 0xed, 0x7c, 0x42 75*9d12795fSRobert Mustacchi }; 76*9d12795fSRobert Mustacchi 77*9d12795fSRobert Mustacchi static uint8_t cha_sbl2[] = { 78*9d12795fSRobert Mustacchi 0xfc, 0x3d, 0x47, 0x1c, 0x34, 0xa3, 0x6f, 0xbb, 79*9d12795fSRobert Mustacchi 0xf6, 0x16, 0xbc, 0x0a, 0x0e, 0x7c, 0x52, 0x30, 80*9d12795fSRobert Mustacchi 0x30, 0xd9, 0x44, 0xf4, 0x3e, 0xc3, 0xe7, 0x8d, 81*9d12795fSRobert Mustacchi 0xd6, 0xa1, 0x24, 0x66, 0x54, 0x7c, 0xb4, 0xf7, 82*9d12795fSRobert Mustacchi 0xb3, 0xce, 0xbd, 0x0a, 0x50, 0x05, 0xe7, 0x62, 83*9d12795fSRobert Mustacchi 0xe5, 0x62, 0xd1, 0x37, 0x5b, 0x7a, 0xc4, 0x45, 84*9d12795fSRobert Mustacchi 0x93, 0xa9, 0x91, 0xb8, 0x5d, 0x1a, 0x60, 0xfb, 85*9d12795fSRobert Mustacchi 0xa2, 0x03, 0x5d, 0xfa, 0xa2, 0xa6, 0x42, 0xd5 86*9d12795fSRobert Mustacchi }; 87*9d12795fSRobert Mustacchi 88*9d12795fSRobert Mustacchi /* Test Vector 3 */ 89*9d12795fSRobert Mustacchi static uint8_t cha_key3[] = { 90*9d12795fSRobert Mustacchi 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 91*9d12795fSRobert Mustacchi 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 92*9d12795fSRobert Mustacchi }; 93*9d12795fSRobert Mustacchi static uint8_t cha_iv3[] = { 94*9d12795fSRobert Mustacchi 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 95*9d12795fSRobert Mustacchi }; 96*9d12795fSRobert Mustacchi 97*9d12795fSRobert Mustacchi static uint8_t cha_fbl3[] = { 98*9d12795fSRobert Mustacchi 0x16, 0x63, 0x87, 0x9e, 0xb3, 0xf2, 0xc9, 0x94, 99*9d12795fSRobert Mustacchi 0x9e, 0x23, 0x88, 0xca, 0xa3, 0x43, 0xd3, 0x61, 100*9d12795fSRobert Mustacchi 0xbb, 0x13, 0x27, 0x71, 0x24, 0x5a, 0xe6, 0xd0, 101*9d12795fSRobert Mustacchi 0x27, 0xca, 0x9c, 0xb0, 0x10, 0xdc, 0x1f, 0xa7, 102*9d12795fSRobert Mustacchi 0x17, 0x8d, 0xc4, 0x1f, 0x82, 0x78, 0xbc, 0x1f, 103*9d12795fSRobert Mustacchi 0x64, 0xb3, 0xf1, 0x27, 0x69, 0xa2, 0x40, 0x97, 104*9d12795fSRobert Mustacchi 0xf4, 0x0d, 0x63, 0xa8, 0x63, 0x66, 0xbd, 0xb3, 105*9d12795fSRobert Mustacchi 0x6a, 0xc0, 0x8a, 0xbe, 0x60, 0xc0, 0x7f, 0xe8 106*9d12795fSRobert Mustacchi }; 107*9d12795fSRobert Mustacchi 108*9d12795fSRobert Mustacchi static uint8_t cha_sbl3[] = { 109*9d12795fSRobert Mustacchi 0xb0, 0x57, 0x37, 0x5c, 0x89, 0x14, 0x44, 0x08, 110*9d12795fSRobert Mustacchi 0xcc, 0x74, 0x46, 0x24, 0xf6, 0x9f, 0x7f, 0x4c, 111*9d12795fSRobert Mustacchi 0xcb, 0xd9, 0x33, 0x66, 0xc9, 0x2f, 0xc4, 0xdf, 112*9d12795fSRobert Mustacchi 0xca, 0xda, 0x65, 0xf1, 0xb9, 0x59, 0xd8, 0xc6, 113*9d12795fSRobert Mustacchi 0x4d, 0xfc, 0x50, 0xde, 0x71, 0x1f, 0xb4, 0x64, 114*9d12795fSRobert Mustacchi 0x16, 0xc2, 0x55, 0x3c, 0xc6, 0x0f, 0x21, 0xbb, 115*9d12795fSRobert Mustacchi 0xfd, 0x00, 0x64, 0x91, 0xcb, 0x17, 0x88, 0x8b, 116*9d12795fSRobert Mustacchi 0x4f, 0xb3, 0x52, 0x1c, 0x4f, 0xdd, 0x87, 0x45 117*9d12795fSRobert Mustacchi }; 118*9d12795fSRobert Mustacchi 119*9d12795fSRobert Mustacchi /* Test Vector 4 */ 120*9d12795fSRobert Mustacchi static uint8_t cha_key4[] = { 121*9d12795fSRobert Mustacchi 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 122*9d12795fSRobert Mustacchi 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 123*9d12795fSRobert Mustacchi }; 124*9d12795fSRobert Mustacchi 125*9d12795fSRobert Mustacchi static uint8_t cha_iv4[] = { 126*9d12795fSRobert Mustacchi 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 127*9d12795fSRobert Mustacchi }; 128*9d12795fSRobert Mustacchi 129*9d12795fSRobert Mustacchi static uint8_t cha_fbl4[] = { 130*9d12795fSRobert Mustacchi 0x99, 0x29, 0x47, 0xc3, 0x96, 0x61, 0x26, 0xa0, 131*9d12795fSRobert Mustacchi 0xe6, 0x60, 0xa3, 0xe9, 0x5d, 0xb0, 0x48, 0xde, 132*9d12795fSRobert Mustacchi 0x09, 0x1f, 0xb9, 0xe0, 0x18, 0x5b, 0x1e, 0x41, 133*9d12795fSRobert Mustacchi 0xe4, 0x10, 0x15, 0xbb, 0x7e, 0xe5, 0x01, 0x50, 134*9d12795fSRobert Mustacchi 0x39, 0x9e, 0x47, 0x60, 0xb2, 0x62, 0xf9, 0xd5, 135*9d12795fSRobert Mustacchi 0x3f, 0x26, 0xd8, 0xdd, 0x19, 0xe5, 0x6f, 0x5c, 136*9d12795fSRobert Mustacchi 0x50, 0x6a, 0xe0, 0xc3, 0x61, 0x9f, 0xa6, 0x7f, 137*9d12795fSRobert Mustacchi 0xb0, 0xc4, 0x08, 0x10, 0x6d, 0x02, 0x03, 0xee 138*9d12795fSRobert Mustacchi }; 139*9d12795fSRobert Mustacchi 140*9d12795fSRobert Mustacchi static uint8_t cha_sbl4[] = { 141*9d12795fSRobert Mustacchi 0x40, 0xea, 0x3c, 0xfa, 0x61, 0xfa, 0x32, 0xa2, 142*9d12795fSRobert Mustacchi 0xfd, 0xa8, 0xd1, 0x23, 0x8a, 0x21, 0x35, 0xd9, 143*9d12795fSRobert Mustacchi 0xd4, 0x17, 0x87, 0x75, 0x24, 0x0f, 0x99, 0x00, 144*9d12795fSRobert Mustacchi 0x70, 0x64, 0xa6, 0xa7, 0xf0, 0xc7, 0x31, 0xb6, 145*9d12795fSRobert Mustacchi 0x7c, 0x22, 0x7c, 0x52, 0xef, 0x79, 0x6b, 0x6b, 146*9d12795fSRobert Mustacchi 0xed, 0x9f, 0x90, 0x59, 0xba, 0x06, 0x14, 0xbc, 147*9d12795fSRobert Mustacchi 0xf6, 0xdd, 0x6e, 0x38, 0x91, 0x7f, 0x3b, 0x15, 148*9d12795fSRobert Mustacchi 0x0e, 0x57, 0x63, 0x75, 0xbe, 0x50, 0xed, 0x67 149*9d12795fSRobert Mustacchi }; 150*9d12795fSRobert Mustacchi 151*9d12795fSRobert Mustacchi /* Test Vector 5 */ 152*9d12795fSRobert Mustacchi static uint8_t cha_key5[] = { 153*9d12795fSRobert Mustacchi 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 154*9d12795fSRobert Mustacchi 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 155*9d12795fSRobert Mustacchi }; 156*9d12795fSRobert Mustacchi static uint8_t cha_iv5[] = { 157*9d12795fSRobert Mustacchi 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 158*9d12795fSRobert Mustacchi }; 159*9d12795fSRobert Mustacchi 160*9d12795fSRobert Mustacchi static uint8_t cha_fbl5[] = { 161*9d12795fSRobert Mustacchi 0x35, 0x7d, 0x7d, 0x94, 0xf9, 0x66, 0x77, 0x8f, 162*9d12795fSRobert Mustacchi 0x58, 0x15, 0xa2, 0x05, 0x1d, 0xcb, 0x04, 0x13, 163*9d12795fSRobert Mustacchi 0x3b, 0x26, 0xb0, 0xea, 0xd9, 0xf5, 0x7d, 0xd0, 164*9d12795fSRobert Mustacchi 0x99, 0x27, 0x83, 0x7b, 0xc3, 0x06, 0x7e, 0x4b, 165*9d12795fSRobert Mustacchi 0x6b, 0xf2, 0x99, 0xad, 0x81, 0xf7, 0xf5, 0x0c, 166*9d12795fSRobert Mustacchi 0x8d, 0xa8, 0x3c, 0x78, 0x10, 0xbf, 0xc1, 0x7b, 167*9d12795fSRobert Mustacchi 0xb6, 0xf4, 0x81, 0x3a, 0xb6, 0xc3, 0x26, 0x95, 168*9d12795fSRobert Mustacchi 0x70, 0x45, 0xfd, 0x3f, 0xd5, 0xe1, 0x99, 0x15 169*9d12795fSRobert Mustacchi }; 170*9d12795fSRobert Mustacchi 171*9d12795fSRobert Mustacchi static uint8_t cha_sbl5[] = { 172*9d12795fSRobert Mustacchi 0xec, 0x74, 0x4a, 0x6b, 0x9b, 0xf8, 0xcb, 0xdc, 173*9d12795fSRobert Mustacchi 0xb3, 0x6d, 0x8b, 0x6a, 0x54, 0x99, 0xc6, 0x8a, 174*9d12795fSRobert Mustacchi 0x08, 0xef, 0x7b, 0xe6, 0xcc, 0x1e, 0x93, 0xf2, 175*9d12795fSRobert Mustacchi 0xf5, 0xbc, 0xd2, 0xca, 0xd4, 0xe4, 0x7c, 0x18, 176*9d12795fSRobert Mustacchi 0xa3, 0xe5, 0xd9, 0x4b, 0x56, 0x66, 0x38, 0x2c, 177*9d12795fSRobert Mustacchi 0x6d, 0x13, 0x0d, 0x82, 0x2d, 0xd5, 0x6a, 0xac, 178*9d12795fSRobert Mustacchi 0xb0, 0xf8, 0x19, 0x52, 0x78, 0xe7, 0xb2, 0x92, 179*9d12795fSRobert Mustacchi 0x49, 0x5f, 0x09, 0x86, 0x8d, 0xdf, 0x12, 0xcc 180*9d12795fSRobert Mustacchi }; 181*9d12795fSRobert Mustacchi 182*9d12795fSRobert Mustacchi /* Test Vector 6 */ 183*9d12795fSRobert Mustacchi 184*9d12795fSRobert Mustacchi static uint8_t cha_key6[] = { 185*9d12795fSRobert Mustacchi 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 186*9d12795fSRobert Mustacchi 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa 187*9d12795fSRobert Mustacchi }; 188*9d12795fSRobert Mustacchi static uint8_t cha_iv6[] = { 189*9d12795fSRobert Mustacchi 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa 190*9d12795fSRobert Mustacchi }; 191*9d12795fSRobert Mustacchi 192*9d12795fSRobert Mustacchi static uint8_t cha_fbl6[] = { 193*9d12795fSRobert Mustacchi 0xfc, 0x79, 0xac, 0xbd, 0x58, 0x52, 0x61, 0x03, 194*9d12795fSRobert Mustacchi 0x86, 0x27, 0x76, 0xaa, 0xb2, 0x0f, 0x3b, 0x7d, 195*9d12795fSRobert Mustacchi 0x8d, 0x31, 0x49, 0xb2, 0xfa, 0xb6, 0x57, 0x66, 196*9d12795fSRobert Mustacchi 0x29, 0x93, 0x16, 0xb6, 0xe5, 0xb1, 0x66, 0x84, 197*9d12795fSRobert Mustacchi 0xde, 0x5d, 0xe5, 0x48, 0xc1, 0xb7, 0xd0, 0x83, 198*9d12795fSRobert Mustacchi 0xef, 0xd9, 0xe3, 0x05, 0x23, 0x19, 0xe0, 0xc6, 199*9d12795fSRobert Mustacchi 0x25, 0x41, 0x41, 0xda, 0x04, 0xa6, 0x58, 0x6d, 200*9d12795fSRobert Mustacchi 0xf8, 0x00, 0xf6, 0x4d, 0x46, 0xb0, 0x1c, 0x87 201*9d12795fSRobert Mustacchi }; 202*9d12795fSRobert Mustacchi 203*9d12795fSRobert Mustacchi static uint8_t cha_sbl6[] = { 204*9d12795fSRobert Mustacchi 0x1f, 0x05, 0xbc, 0x67, 0xe0, 0x76, 0x28, 0xeb, 205*9d12795fSRobert Mustacchi 0xe6, 0xf6, 0x86, 0x5a, 0x21, 0x77, 0xe0, 0xb6, 206*9d12795fSRobert Mustacchi 0x6a, 0x55, 0x8a, 0xa7, 0xcc, 0x1e, 0x8f, 0xf1, 207*9d12795fSRobert Mustacchi 0xa9, 0x8d, 0x27, 0xf7, 0x07, 0x1f, 0x83, 0x35, 208*9d12795fSRobert Mustacchi 0xef, 0xce, 0x45, 0x37, 0xbb, 0x0e, 0xf7, 0xb5, 209*9d12795fSRobert Mustacchi 0x73, 0xb3, 0x2f, 0x32, 0x76, 0x5f, 0x29, 0x00, 210*9d12795fSRobert Mustacchi 0x7d, 0xa5, 0x3b, 0xba, 0x62, 0xe7, 0xa4, 0x4d, 211*9d12795fSRobert Mustacchi 0x00, 0x6f, 0x41, 0xeb, 0x28, 0xfe, 0x15, 0xd6 212*9d12795fSRobert Mustacchi }; 213*9d12795fSRobert Mustacchi 214*9d12795fSRobert Mustacchi /* Test Vector 7 */ 215*9d12795fSRobert Mustacchi static uint8_t cha_key7[] = { 216*9d12795fSRobert Mustacchi 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 217*9d12795fSRobert Mustacchi 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff 218*9d12795fSRobert Mustacchi }; 219*9d12795fSRobert Mustacchi static uint8_t cha_iv7[] = { 220*9d12795fSRobert Mustacchi 0x0f, 0x1e, 0x2d, 0x3c, 0x4b, 0x5a, 0x69, 0x78 221*9d12795fSRobert Mustacchi }; 222*9d12795fSRobert Mustacchi 223*9d12795fSRobert Mustacchi static uint8_t cha_fbl7[] = { 224*9d12795fSRobert Mustacchi 0xd1, 0xab, 0xf6, 0x30, 0x46, 0x7e, 0xb4, 0xf6, 225*9d12795fSRobert Mustacchi 0x7f, 0x1c, 0xfb, 0x47, 0xcd, 0x62, 0x6a, 0xae, 226*9d12795fSRobert Mustacchi 0x8a, 0xfe, 0xdb, 0xbe, 0x4f, 0xf8, 0xfc, 0x5f, 227*9d12795fSRobert Mustacchi 0xe9, 0xcf, 0xae, 0x30, 0x7e, 0x74, 0xed, 0x45, 228*9d12795fSRobert Mustacchi 0x1f, 0x14, 0x04, 0x42, 0x5a, 0xd2, 0xb5, 0x45, 229*9d12795fSRobert Mustacchi 0x69, 0xd5, 0xf1, 0x81, 0x48, 0x93, 0x99, 0x71, 230*9d12795fSRobert Mustacchi 0xab, 0xb8, 0xfa, 0xfc, 0x88, 0xce, 0x4a, 0xc7, 231*9d12795fSRobert Mustacchi 0xfe, 0x1c, 0x3d, 0x1f, 0x7a, 0x1e, 0xb7, 0xca 232*9d12795fSRobert Mustacchi }; 233*9d12795fSRobert Mustacchi 234*9d12795fSRobert Mustacchi static uint8_t cha_sbl7[] = { 235*9d12795fSRobert Mustacchi 0xe7, 0x6c, 0xa8, 0x7b, 0x61, 0xa9, 0x71, 0x35, 236*9d12795fSRobert Mustacchi 0x41, 0x49, 0x77, 0x60, 0xdd, 0x9a, 0xe0, 0x59, 237*9d12795fSRobert Mustacchi 0x35, 0x0c, 0xad, 0x0d, 0xce, 0xdf, 0xaa, 0x80, 238*9d12795fSRobert Mustacchi 0xa8, 0x83, 0x11, 0x9a, 0x1a, 0x6f, 0x98, 0x7f, 239*9d12795fSRobert Mustacchi 0xd1, 0xce, 0x91, 0xfd, 0x8e, 0xe0, 0x82, 0x80, 240*9d12795fSRobert Mustacchi 0x34, 0xb4, 0x11, 0x20, 0x0a, 0x97, 0x45, 0xa2, 241*9d12795fSRobert Mustacchi 0x85, 0x55, 0x44, 0x75, 0xd1, 0x2a, 0xfc, 0x04, 242*9d12795fSRobert Mustacchi 0x88, 0x7f, 0xef, 0x35, 0x16, 0xd1, 0x2a, 0x2c 243*9d12795fSRobert Mustacchi }; 244*9d12795fSRobert Mustacchi 245*9d12795fSRobert Mustacchi /* Test Vector 8 */ 246*9d12795fSRobert Mustacchi static uint8_t cha_key8[] = { 247*9d12795fSRobert Mustacchi 0xc4, 0x6e, 0xc1, 0xb1, 0x8c, 0xe8, 0xa8, 0x78, 248*9d12795fSRobert Mustacchi 0x72, 0x5a, 0x37, 0xe7, 0x80, 0xdf, 0xb7, 0x35 249*9d12795fSRobert Mustacchi }; 250*9d12795fSRobert Mustacchi static uint8_t cha_iv8[] = { 251*9d12795fSRobert Mustacchi 0x1a, 0xda, 0x31, 0xd5, 0xcf, 0x68, 0x82, 0x21 252*9d12795fSRobert Mustacchi }; 253*9d12795fSRobert Mustacchi 254*9d12795fSRobert Mustacchi static uint8_t cha_fbl8[] = { 255*9d12795fSRobert Mustacchi 0x82, 0x6a, 0xbd, 0xd8, 0x44, 0x60, 0xe2, 0xe9, 256*9d12795fSRobert Mustacchi 0x34, 0x9f, 0x0e, 0xf4, 0xaf, 0x5b, 0x17, 0x9b, 257*9d12795fSRobert Mustacchi 0x42, 0x6e, 0x4b, 0x2d, 0x10, 0x9a, 0x9c, 0x5b, 258*9d12795fSRobert Mustacchi 0xb4, 0x40, 0x00, 0xae, 0x51, 0xbe, 0xa9, 0x0a, 259*9d12795fSRobert Mustacchi 0x49, 0x6b, 0xee, 0xef, 0x62, 0xa7, 0x68, 0x50, 260*9d12795fSRobert Mustacchi 0xff, 0x3f, 0x04, 0x02, 0xc4, 0xdd, 0xc9, 0x9f, 261*9d12795fSRobert Mustacchi 0x6d, 0xb0, 0x7f, 0x15, 0x1c, 0x1c, 0x0d, 0xfa, 262*9d12795fSRobert Mustacchi 0xc2, 0xe5, 0x65, 0x65, 0xd6, 0x28, 0x96, 0x25 263*9d12795fSRobert Mustacchi }; 264*9d12795fSRobert Mustacchi 265*9d12795fSRobert Mustacchi static uint8_t cha_sbl8[] = { 266*9d12795fSRobert Mustacchi 0x5b, 0x23, 0x13, 0x2e, 0x7b, 0x46, 0x9c, 0x7b, 267*9d12795fSRobert Mustacchi 0xfb, 0x88, 0xfa, 0x95, 0xd4, 0x4c, 0xa5, 0xae, 268*9d12795fSRobert Mustacchi 0x3e, 0x45, 0xe8, 0x48, 0xa4, 0x10, 0x8e, 0x98, 269*9d12795fSRobert Mustacchi 0xba, 0xd7, 0xa9, 0xeb, 0x15, 0x51, 0x27, 0x84, 270*9d12795fSRobert Mustacchi 0xa6, 0xa9, 0xe6, 0xe5, 0x91, 0xdc, 0xe6, 0x74, 271*9d12795fSRobert Mustacchi 0x12, 0x0a, 0xca, 0xf9, 0x04, 0x0f, 0xf5, 0x0f, 272*9d12795fSRobert Mustacchi 0xf3, 0xac, 0x30, 0xcc, 0xfb, 0x5e, 0x14, 0x20, 273*9d12795fSRobert Mustacchi 0x4f, 0x5e, 0x42, 0x68, 0xb9, 0x0a, 0x88, 0x04 274*9d12795fSRobert Mustacchi }; 275*9d12795fSRobert Mustacchi 276*9d12795fSRobert Mustacchi static void 277*9d12795fSRobert Mustacchi chacha_test(uint8_t *key, uint8_t keylen, uint8_t *iv, uint8_t *bl0, 278*9d12795fSRobert Mustacchi uint8_t *bl1) 279*9d12795fSRobert Mustacchi { 280*9d12795fSRobert Mustacchi uint8_t res0[64], res1[64]; 281*9d12795fSRobert Mustacchi chacha_ctx_t ctx; 282*9d12795fSRobert Mustacchi int ret; 283*9d12795fSRobert Mustacchi 284*9d12795fSRobert Mustacchi bzero(&ctx, sizeof (ctx)); 285*9d12795fSRobert Mustacchi bzero(res0, sizeof (res0)); 286*9d12795fSRobert Mustacchi bzero(res1, sizeof (res1)); 287*9d12795fSRobert Mustacchi chacha_keysetup(&ctx, key, keylen * 8, 0); 288*9d12795fSRobert Mustacchi chacha_ivsetup(&ctx, iv); 289*9d12795fSRobert Mustacchi chacha_encrypt_bytes(&ctx, res0, res0, sizeof (res0)); 290*9d12795fSRobert Mustacchi chacha_encrypt_bytes(&ctx, res1, res1, sizeof (res1)); 291*9d12795fSRobert Mustacchi ret = bcmp(res0, bl0, sizeof (res0)); 292*9d12795fSRobert Mustacchi assert(ret == 0); 293*9d12795fSRobert Mustacchi ret = bcmp(res1, bl1, sizeof (res0)); 294*9d12795fSRobert Mustacchi assert(ret == 0); 295*9d12795fSRobert Mustacchi } 296*9d12795fSRobert Mustacchi 297*9d12795fSRobert Mustacchi int 298*9d12795fSRobert Mustacchi main(void) 299*9d12795fSRobert Mustacchi { 300*9d12795fSRobert Mustacchi chacha_test(cha_key1, sizeof (cha_key1), cha_iv1, cha_fbl1, cha_sbl1); 301*9d12795fSRobert Mustacchi chacha_test(cha_key2, sizeof (cha_key2), cha_iv2, cha_fbl2, cha_sbl2); 302*9d12795fSRobert Mustacchi chacha_test(cha_key3, sizeof (cha_key3), cha_iv3, cha_fbl3, cha_sbl3); 303*9d12795fSRobert Mustacchi chacha_test(cha_key4, sizeof (cha_key4), cha_iv4, cha_fbl4, cha_sbl4); 304*9d12795fSRobert Mustacchi chacha_test(cha_key5, sizeof (cha_key5), cha_iv5, cha_fbl5, cha_sbl5); 305*9d12795fSRobert Mustacchi chacha_test(cha_key6, sizeof (cha_key6), cha_iv6, cha_fbl6, cha_sbl6); 306*9d12795fSRobert Mustacchi chacha_test(cha_key7, sizeof (cha_key7), cha_iv7, cha_fbl7, cha_sbl7); 307*9d12795fSRobert Mustacchi chacha_test(cha_key8, sizeof (cha_key8), cha_iv8, cha_fbl8, cha_sbl8); 308*9d12795fSRobert Mustacchi return (0); 309*9d12795fSRobert Mustacchi } 310