xref: /freebsd/crypto/openssl/test/evp_xof_test.c (revision e7be843b4a162e68651d3911f0357ed464915629)
1*e7be843bSPierre Pronchery /*
2*e7be843bSPierre Pronchery  * Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
3*e7be843bSPierre Pronchery  *
4*e7be843bSPierre Pronchery  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*e7be843bSPierre Pronchery  * this file except in compliance with the License.  You can obtain a copy
6*e7be843bSPierre Pronchery  * in the file LICENSE in the source distribution or at
7*e7be843bSPierre Pronchery  * https://www.openssl.org/source/license.html
8*e7be843bSPierre Pronchery  */
9*e7be843bSPierre Pronchery 
10*e7be843bSPierre Pronchery #include <openssl/evp.h>
11*e7be843bSPierre Pronchery #include <openssl/rand.h>
12*e7be843bSPierre Pronchery #include <openssl/core_names.h>
13*e7be843bSPierre Pronchery #include "testutil.h"
14*e7be843bSPierre Pronchery #include "internal/nelem.h"
15*e7be843bSPierre Pronchery 
16*e7be843bSPierre Pronchery static const unsigned char shake256_input[] = {
17*e7be843bSPierre Pronchery     0x8d, 0x80, 0x01, 0xe2, 0xc0, 0x96, 0xf1, 0xb8,
18*e7be843bSPierre Pronchery     0x8e, 0x7c, 0x92, 0x24, 0xa0, 0x86, 0xef, 0xd4,
19*e7be843bSPierre Pronchery     0x79, 0x7f, 0xbf, 0x74, 0xa8, 0x03, 0x3a, 0x2d,
20*e7be843bSPierre Pronchery     0x42, 0x2a, 0x2b, 0x6b, 0x8f, 0x67, 0x47, 0xe4
21*e7be843bSPierre Pronchery };
22*e7be843bSPierre Pronchery 
23*e7be843bSPierre Pronchery /*
24*e7be843bSPierre Pronchery  * This KAT output is 250 bytes, which is more than
25*e7be843bSPierre Pronchery  * the SHAKE256 block size (136 bytes).
26*e7be843bSPierre Pronchery  */
27*e7be843bSPierre Pronchery static const unsigned char shake256_output[] = {
28*e7be843bSPierre Pronchery     0x2e, 0x97, 0x5f, 0x6a, 0x8a, 0x14, 0xf0, 0x70,
29*e7be843bSPierre Pronchery     0x4d, 0x51, 0xb1, 0x36, 0x67, 0xd8, 0x19, 0x5c,
30*e7be843bSPierre Pronchery     0x21, 0x9f, 0x71, 0xe6, 0x34, 0x56, 0x96, 0xc4,
31*e7be843bSPierre Pronchery     0x9f, 0xa4, 0xb9, 0xd0, 0x8e, 0x92, 0x25, 0xd3,
32*e7be843bSPierre Pronchery     0xd3, 0x93, 0x93, 0x42, 0x51, 0x52, 0xc9, 0x7e,
33*e7be843bSPierre Pronchery     0x71, 0xdd, 0x24, 0x60, 0x1c, 0x11, 0xab, 0xcf,
34*e7be843bSPierre Pronchery     0xa0, 0xf1, 0x2f, 0x53, 0xc6, 0x80, 0xbd, 0x3a,
35*e7be843bSPierre Pronchery     0xe7, 0x57, 0xb8, 0x13, 0x4a, 0x9c, 0x10, 0xd4,
36*e7be843bSPierre Pronchery     0x29, 0x61, 0x58, 0x69, 0x21, 0x7f, 0xdd, 0x58,
37*e7be843bSPierre Pronchery     0x85, 0xc4, 0xdb, 0x17, 0x49, 0x85, 0x70, 0x3a,
38*e7be843bSPierre Pronchery     0x6d, 0x6d, 0xe9, 0x4a, 0x66, 0x7e, 0xac, 0x30,
39*e7be843bSPierre Pronchery     0x23, 0x44, 0x3a, 0x83, 0x37, 0xae, 0x1b, 0xc6,
40*e7be843bSPierre Pronchery     0x01, 0xb7, 0x6d, 0x7d, 0x38, 0xec, 0x3c, 0x34,
41*e7be843bSPierre Pronchery     0x46, 0x31, 0x05, 0xf0, 0xd3, 0x94, 0x9d, 0x78,
42*e7be843bSPierre Pronchery     0xe5, 0x62, 0xa0, 0x39, 0xe4, 0x46, 0x95, 0x48,
43*e7be843bSPierre Pronchery     0xb6, 0x09, 0x39, 0x5d, 0xe5, 0xa4, 0xfd, 0x43,
44*e7be843bSPierre Pronchery     0xc4, 0x6c, 0xa9, 0xfd, 0x6e, 0xe2, 0x9a, 0xda,
45*e7be843bSPierre Pronchery     0x5e, 0xfc, 0x07, 0xd8, 0x4d, 0x55, 0x32, 0x49,
46*e7be843bSPierre Pronchery     0x45, 0x0d, 0xab, 0x4a, 0x49, 0xc4, 0x83, 0xde,
47*e7be843bSPierre Pronchery     0xd2, 0x50, 0xc9, 0x33, 0x8f, 0x85, 0xcd, 0x93,
48*e7be843bSPierre Pronchery     0x7a, 0xe6, 0x6b, 0xb4, 0x36, 0xf3, 0xb4, 0x02,
49*e7be843bSPierre Pronchery     0x6e, 0x85, 0x9f, 0xda, 0x1c, 0xa5, 0x71, 0x43,
50*e7be843bSPierre Pronchery     0x2f, 0x3b, 0xfc, 0x09, 0xe7, 0xc0, 0x3c, 0xa4,
51*e7be843bSPierre Pronchery     0xd1, 0x83, 0xb7, 0x41, 0x11, 0x1c, 0xa0, 0x48,
52*e7be843bSPierre Pronchery     0x3d, 0x0e, 0xda, 0xbc, 0x03, 0xfe, 0xb2, 0x3b,
53*e7be843bSPierre Pronchery     0x17, 0xee, 0x48, 0xe8, 0x44, 0xba, 0x24, 0x08,
54*e7be843bSPierre Pronchery     0xd9, 0xdc, 0xfd, 0x01, 0x39, 0xd2, 0xe8, 0xc7,
55*e7be843bSPierre Pronchery     0x31, 0x01, 0x25, 0xae, 0xe8, 0x01, 0xc6, 0x1a,
56*e7be843bSPierre Pronchery     0xb7, 0x90, 0x0d, 0x1e, 0xfc, 0x47, 0xc0, 0x78,
57*e7be843bSPierre Pronchery     0x28, 0x17, 0x66, 0xf3, 0x61, 0xc5, 0xe6, 0x11,
58*e7be843bSPierre Pronchery     0x13, 0x46, 0x23, 0x5e, 0x1d, 0xc3, 0x83, 0x25,
59*e7be843bSPierre Pronchery     0x66, 0x6c
60*e7be843bSPierre Pronchery };
61*e7be843bSPierre Pronchery 
62*e7be843bSPierre Pronchery static const unsigned char shake256_largemsg_input[] = {
63*e7be843bSPierre Pronchery     0xb2, 0xd2, 0x38, 0x65, 0xaf, 0x8f, 0x25, 0x6e,
64*e7be843bSPierre Pronchery     0x64, 0x40, 0xe2, 0x0d, 0x49, 0x8e, 0x3e, 0x64,
65*e7be843bSPierre Pronchery     0x46, 0xd2, 0x03, 0xa4, 0x19, 0xe3, 0x7b, 0x80,
66*e7be843bSPierre Pronchery     0xf7, 0x2b, 0x32, 0xe2, 0x76, 0x01, 0xfe, 0xdd,
67*e7be843bSPierre Pronchery     0xaa, 0x33, 0x3d, 0xe4, 0x8e, 0xe1, 0x5e, 0x39,
68*e7be843bSPierre Pronchery     0xa6, 0x92, 0xa3, 0xa7, 0xe3, 0x81, 0x24, 0x74,
69*e7be843bSPierre Pronchery     0xc7, 0x38, 0x18, 0x92, 0xc9, 0x60, 0x50, 0x15,
70*e7be843bSPierre Pronchery     0xfb, 0xd8, 0x04, 0xea, 0xea, 0x04, 0xd2, 0xc5,
71*e7be843bSPierre Pronchery     0xc6, 0x68, 0x04, 0x5b, 0xc3, 0x75, 0x12, 0xd2,
72*e7be843bSPierre Pronchery     0xbe, 0xa2, 0x67, 0x75, 0x24, 0xbf, 0x68, 0xad,
73*e7be843bSPierre Pronchery     0x10, 0x86, 0xb3, 0x2c, 0xb3, 0x74, 0xa4, 0x6c,
74*e7be843bSPierre Pronchery     0xf9, 0xd7, 0x1e, 0x58, 0x69, 0x27, 0x88, 0x49,
75*e7be843bSPierre Pronchery     0x4e, 0x99, 0x15, 0x33, 0x14, 0xf2, 0x49, 0x21,
76*e7be843bSPierre Pronchery     0xf4, 0x99, 0xb9, 0xde, 0xd4, 0xf1, 0x12, 0xf5,
77*e7be843bSPierre Pronchery     0x68, 0xe5, 0x5c, 0xdc, 0x9e, 0xc5, 0x80, 0x6d,
78*e7be843bSPierre Pronchery     0x39, 0x50, 0x08, 0x95, 0xbb, 0x12, 0x27, 0x50,
79*e7be843bSPierre Pronchery     0x89, 0xf0, 0xf9, 0xd5, 0x4a, 0x01, 0x0b, 0x0d,
80*e7be843bSPierre Pronchery     0x90, 0x9f, 0x1e, 0x4a, 0xba, 0xbe, 0x28, 0x36,
81*e7be843bSPierre Pronchery     0x19, 0x7d, 0x9c, 0x0a, 0x51, 0xfb, 0xeb, 0x00,
82*e7be843bSPierre Pronchery     0x02, 0x6c, 0x4b, 0x0a, 0xa8, 0x6c, 0xb7, 0xc4,
83*e7be843bSPierre Pronchery     0xc0, 0x92, 0x37, 0xa7, 0x2d, 0x49, 0x61, 0x80,
84*e7be843bSPierre Pronchery     0xd9, 0xdb, 0x20, 0x21, 0x9f, 0xcf, 0xb4, 0x57,
85*e7be843bSPierre Pronchery     0x69, 0x75, 0xfa, 0x1c, 0x95, 0xbf, 0xee, 0x0d,
86*e7be843bSPierre Pronchery     0x9e, 0x52, 0x6e, 0x1e, 0xf8, 0xdd, 0x41, 0x8c,
87*e7be843bSPierre Pronchery     0x3b, 0xaa, 0x57, 0x13, 0x84, 0x73, 0x52, 0x62,
88*e7be843bSPierre Pronchery     0x18, 0x76, 0x46, 0xcc, 0x4b, 0xcb, 0xbd, 0x40,
89*e7be843bSPierre Pronchery     0xa1, 0xf6, 0xff, 0x7b, 0x32, 0xb9, 0x90, 0x7c,
90*e7be843bSPierre Pronchery     0x53, 0x2c, 0xf9, 0x38, 0x72, 0x0f, 0xcb, 0x90,
91*e7be843bSPierre Pronchery     0x42, 0x5e, 0xe2, 0x80, 0x19, 0x26, 0xe7, 0x99,
92*e7be843bSPierre Pronchery     0x96, 0x98, 0x18, 0xb1, 0x86, 0x5b, 0x4c, 0xd9,
93*e7be843bSPierre Pronchery     0x08, 0x27, 0x31, 0x8f, 0xf0, 0x90, 0xd9, 0x35,
94*e7be843bSPierre Pronchery     0x6a, 0x1f, 0x75, 0xc2, 0xe0, 0xa7, 0x60, 0xb8,
95*e7be843bSPierre Pronchery     0x1d, 0xd6, 0x5f, 0x56, 0xb2, 0x0b, 0x27, 0x0e,
96*e7be843bSPierre Pronchery     0x98, 0x67, 0x1f, 0x39, 0x18, 0x27, 0x68, 0x0a,
97*e7be843bSPierre Pronchery     0xe8, 0x31, 0x1b, 0xc0, 0x97, 0xec, 0xd1, 0x20,
98*e7be843bSPierre Pronchery     0x2a, 0x55, 0x69, 0x23, 0x08, 0x50, 0x05, 0xec,
99*e7be843bSPierre Pronchery     0x13, 0x3b, 0x56, 0xfc, 0x18, 0xc9, 0x1a, 0xa9,
100*e7be843bSPierre Pronchery     0x69, 0x0e, 0xe2, 0xcc, 0xc8, 0xd6, 0x19, 0xbb,
101*e7be843bSPierre Pronchery     0x87, 0x3b, 0x42, 0x77, 0xee, 0x77, 0x81, 0x26,
102*e7be843bSPierre Pronchery     0xdd, 0xf6, 0x5d, 0xc3, 0xb2, 0xb0, 0xc4, 0x14,
103*e7be843bSPierre Pronchery     0x6d, 0xb5, 0x4f, 0xdc, 0x13, 0x09, 0xc8, 0x53,
104*e7be843bSPierre Pronchery     0x50, 0xb3, 0xea, 0xd3, 0x5f, 0x11, 0x67, 0xd4,
105*e7be843bSPierre Pronchery     0x2f, 0x6e, 0x30, 0x1a, 0xbe, 0xd6, 0xf0, 0x2d,
106*e7be843bSPierre Pronchery     0xc9, 0x29, 0xd9, 0x0a, 0xa8, 0x6f, 0xa4, 0x18,
107*e7be843bSPierre Pronchery     0x74, 0x6b, 0xd3, 0x5d, 0x6a, 0x73, 0x3a, 0xf2,
108*e7be843bSPierre Pronchery     0x94, 0x7f, 0xbd, 0xb4, 0xa6, 0x7f, 0x5b, 0x3d,
109*e7be843bSPierre Pronchery     0x26, 0xf2, 0x6c, 0x13, 0xcf, 0xb4, 0x26, 0x1e,
110*e7be843bSPierre Pronchery     0x38, 0x17, 0x66, 0x60, 0xb1, 0x36, 0xae, 0xe0,
111*e7be843bSPierre Pronchery     0x6d, 0x86, 0x69, 0xe7, 0xe7, 0xae, 0x77, 0x6f,
112*e7be843bSPierre Pronchery     0x7e, 0x99, 0xe5, 0xd9, 0x62, 0xc9, 0xfc, 0xde,
113*e7be843bSPierre Pronchery     0xb4, 0xee, 0x7e, 0xc8, 0xe9, 0xb7, 0x2c, 0xe2,
114*e7be843bSPierre Pronchery     0x70, 0xe8, 0x8b, 0x2d, 0x94, 0xad, 0xe8, 0x54,
115*e7be843bSPierre Pronchery     0xa3, 0x2d, 0x9a, 0xe2, 0x50, 0x63, 0x87, 0xb3,
116*e7be843bSPierre Pronchery     0x56, 0x29, 0xea, 0xa8, 0x5e, 0x96, 0x53, 0x9f,
117*e7be843bSPierre Pronchery     0x23, 0x8a, 0xef, 0xa3, 0xd4, 0x87, 0x09, 0x5f,
118*e7be843bSPierre Pronchery     0xba, 0xc3, 0xd1, 0xd9, 0x1a, 0x7b, 0x5c, 0x5d,
119*e7be843bSPierre Pronchery     0x5d, 0x89, 0xed, 0xb6, 0x6e, 0x39, 0x73, 0xa5,
120*e7be843bSPierre Pronchery     0x64, 0x59, 0x52, 0x8b, 0x61, 0x8f, 0x66, 0x69,
121*e7be843bSPierre Pronchery     0xb9, 0xf0, 0x45, 0x0a, 0x57, 0xcd, 0xc5, 0x7f,
122*e7be843bSPierre Pronchery     0x5d, 0xd0, 0xbf, 0xcc, 0x0b, 0x48, 0x12, 0xe1,
123*e7be843bSPierre Pronchery     0xe2, 0xc2, 0xea, 0xcc, 0x09, 0xd9, 0x42, 0x2c,
124*e7be843bSPierre Pronchery     0xef, 0x4f, 0xa7, 0xe9, 0x32, 0x5c, 0x3f, 0x22,
125*e7be843bSPierre Pronchery     0xc0, 0x45, 0x0b, 0x67, 0x3c, 0x31, 0x69, 0x29,
126*e7be843bSPierre Pronchery     0xa3, 0x39, 0xdd, 0x6e, 0x2f, 0xbe, 0x10, 0xc9,
127*e7be843bSPierre Pronchery     0x7b, 0xff, 0x19, 0x8a, 0xe9, 0xea, 0xfc, 0x32,
128*e7be843bSPierre Pronchery     0x41, 0x33, 0x70, 0x2a, 0x9a, 0xa4, 0xe6, 0xb4,
129*e7be843bSPierre Pronchery     0x7e, 0xb4, 0xc6, 0x21, 0x49, 0x5a, 0xfc, 0x45,
130*e7be843bSPierre Pronchery     0xd2, 0x23, 0xb3, 0x28, 0x4d, 0x83, 0x60, 0xfe,
131*e7be843bSPierre Pronchery     0x70, 0x68, 0x03, 0x59, 0xd5, 0x15, 0xaa, 0x9e,
132*e7be843bSPierre Pronchery     0xa0, 0x2e, 0x36, 0xb5, 0x61, 0x0f, 0x61, 0x05,
133*e7be843bSPierre Pronchery     0x3c, 0x62, 0x00, 0xa0, 0x47, 0xf1, 0x86, 0xba,
134*e7be843bSPierre Pronchery     0x33, 0xb8, 0xca, 0x60, 0x2f, 0x3f, 0x0a, 0x67,
135*e7be843bSPierre Pronchery     0x09, 0x27, 0x2f, 0xa2, 0x96, 0x02, 0x52, 0x58,
136*e7be843bSPierre Pronchery     0x55, 0x68, 0x80, 0xf4, 0x4f, 0x47, 0xba, 0xff,
137*e7be843bSPierre Pronchery     0x41, 0x7a, 0x40, 0x4c, 0xfd, 0x9d, 0x10, 0x72,
138*e7be843bSPierre Pronchery     0x0e, 0x20, 0xa9, 0x7f, 0x9b, 0x9b, 0x14, 0xeb,
139*e7be843bSPierre Pronchery     0x8e, 0x61, 0x25, 0xcb, 0xf4, 0x58, 0xff, 0x47,
140*e7be843bSPierre Pronchery     0xa7, 0x08, 0xd6, 0x4e, 0x2b, 0xf1, 0xf9, 0x89,
141*e7be843bSPierre Pronchery     0xd7, 0x22, 0x0f, 0x8d, 0x35, 0x07, 0xa0, 0x54,
142*e7be843bSPierre Pronchery     0xab, 0x83, 0xd8, 0xee, 0x5a, 0x3e, 0x88, 0x74,
143*e7be843bSPierre Pronchery     0x46, 0x41, 0x6e, 0x3e, 0xb7, 0xc0, 0xb6, 0x55,
144*e7be843bSPierre Pronchery     0xe0, 0x36, 0xc0, 0x2b, 0xbf, 0xb8, 0x24, 0x8a,
145*e7be843bSPierre Pronchery     0x44, 0x82, 0xf4, 0xcb, 0xb5, 0xd7, 0x41, 0x48,
146*e7be843bSPierre Pronchery     0x51, 0x08, 0xe0, 0x14, 0x34, 0xd2, 0x6d, 0xe9,
147*e7be843bSPierre Pronchery     0x7a, 0xec, 0x91, 0x61, 0xa7, 0xe1, 0x81, 0x69,
148*e7be843bSPierre Pronchery     0x47, 0x1c, 0xc7, 0xf3
149*e7be843bSPierre Pronchery };
150*e7be843bSPierre Pronchery 
151*e7be843bSPierre Pronchery static const unsigned char shake256_largemsg_output[] = {
152*e7be843bSPierre Pronchery     0x64, 0xea, 0x24, 0x6a, 0xab, 0x80, 0x37, 0x9e,
153*e7be843bSPierre Pronchery     0x08, 0xe2, 0x19, 0x9e, 0x09, 0x69, 0xe2, 0xee,
154*e7be843bSPierre Pronchery     0x1a, 0x5d, 0xd1, 0x68, 0x68, 0xec, 0x8d, 0x42,
155*e7be843bSPierre Pronchery     0xd0, 0xf8, 0xb8, 0x44, 0x74, 0x54, 0x87, 0x3e,
156*e7be843bSPierre Pronchery };
157*e7be843bSPierre Pronchery 
shake_setup(const char * name)158*e7be843bSPierre Pronchery static EVP_MD_CTX *shake_setup(const char *name)
159*e7be843bSPierre Pronchery {
160*e7be843bSPierre Pronchery     EVP_MD_CTX *ctx = NULL;
161*e7be843bSPierre Pronchery     EVP_MD *md = NULL;
162*e7be843bSPierre Pronchery 
163*e7be843bSPierre Pronchery     if (!TEST_ptr(md = EVP_MD_fetch(NULL, name, NULL)))
164*e7be843bSPierre Pronchery         return NULL;
165*e7be843bSPierre Pronchery 
166*e7be843bSPierre Pronchery     if (!TEST_ptr(ctx = EVP_MD_CTX_new()))
167*e7be843bSPierre Pronchery         goto err;
168*e7be843bSPierre Pronchery     if (!TEST_true(EVP_DigestInit_ex2(ctx, md, NULL)))
169*e7be843bSPierre Pronchery         goto err;
170*e7be843bSPierre Pronchery     EVP_MD_free(md);
171*e7be843bSPierre Pronchery     return ctx;
172*e7be843bSPierre Pronchery err:
173*e7be843bSPierre Pronchery     EVP_MD_free(md);
174*e7be843bSPierre Pronchery     EVP_MD_CTX_free(ctx);
175*e7be843bSPierre Pronchery     return NULL;
176*e7be843bSPierre Pronchery }
177*e7be843bSPierre Pronchery 
shake_kat_test(void)178*e7be843bSPierre Pronchery static int shake_kat_test(void)
179*e7be843bSPierre Pronchery {
180*e7be843bSPierre Pronchery     int ret = 0;
181*e7be843bSPierre Pronchery     EVP_MD_CTX *ctx = NULL;
182*e7be843bSPierre Pronchery     unsigned char out[sizeof(shake256_output)];
183*e7be843bSPierre Pronchery 
184*e7be843bSPierre Pronchery     if (!TEST_ptr(ctx = shake_setup("SHAKE256")))
185*e7be843bSPierre Pronchery         return 0;
186*e7be843bSPierre Pronchery     if (!TEST_true(EVP_DigestUpdate(ctx, shake256_input,
187*e7be843bSPierre Pronchery                                     sizeof(shake256_input)))
188*e7be843bSPierre Pronchery         || !TEST_true(EVP_DigestFinalXOF(ctx, out, sizeof(out)))
189*e7be843bSPierre Pronchery         || !TEST_mem_eq(out, sizeof(out),
190*e7be843bSPierre Pronchery                         shake256_output,sizeof(shake256_output))
191*e7be843bSPierre Pronchery         /* Test that a second call to EVP_DigestFinalXOF fails */
192*e7be843bSPierre Pronchery         || !TEST_false(EVP_DigestFinalXOF(ctx, out, sizeof(out)))
193*e7be843bSPierre Pronchery         /* Test that a call to EVP_DigestSqueeze fails */
194*e7be843bSPierre Pronchery         || !TEST_false(EVP_DigestSqueeze(ctx, out, sizeof(out))))
195*e7be843bSPierre Pronchery         goto err;
196*e7be843bSPierre Pronchery     ret = 1;
197*e7be843bSPierre Pronchery err:
198*e7be843bSPierre Pronchery     EVP_MD_CTX_free(ctx);
199*e7be843bSPierre Pronchery     return ret;
200*e7be843bSPierre Pronchery }
201*e7be843bSPierre Pronchery 
shake_kat_digestfinal_test(void)202*e7be843bSPierre Pronchery static int shake_kat_digestfinal_test(void)
203*e7be843bSPierre Pronchery {
204*e7be843bSPierre Pronchery     int ret = 0;
205*e7be843bSPierre Pronchery     unsigned int digest_length = 0;
206*e7be843bSPierre Pronchery     EVP_MD_CTX *ctx = NULL;
207*e7be843bSPierre Pronchery     unsigned char out[sizeof(shake256_output)];
208*e7be843bSPierre Pronchery 
209*e7be843bSPierre Pronchery     /* Test that EVP_DigestFinal without setting XOFLEN fails */
210*e7be843bSPierre Pronchery     if (!TEST_ptr(ctx = shake_setup("SHAKE256")))
211*e7be843bSPierre Pronchery         return 0;
212*e7be843bSPierre Pronchery     if (!TEST_true(EVP_DigestUpdate(ctx, shake256_input,
213*e7be843bSPierre Pronchery                    sizeof(shake256_input))))
214*e7be843bSPierre Pronchery         return 0;
215*e7be843bSPierre Pronchery     ERR_set_mark();
216*e7be843bSPierre Pronchery     if (!TEST_false(EVP_DigestFinal(ctx, out, &digest_length))) {
217*e7be843bSPierre Pronchery         ERR_clear_last_mark();
218*e7be843bSPierre Pronchery         return 0;
219*e7be843bSPierre Pronchery     }
220*e7be843bSPierre Pronchery     ERR_pop_to_mark();
221*e7be843bSPierre Pronchery     EVP_MD_CTX_free(ctx);
222*e7be843bSPierre Pronchery 
223*e7be843bSPierre Pronchery     /* However EVP_DigestFinalXOF must work */
224*e7be843bSPierre Pronchery     if (!TEST_ptr(ctx = shake_setup("SHAKE256")))
225*e7be843bSPierre Pronchery         return 0;
226*e7be843bSPierre Pronchery     if (!TEST_true(EVP_DigestUpdate(ctx, shake256_input,
227*e7be843bSPierre Pronchery                    sizeof(shake256_input))))
228*e7be843bSPierre Pronchery         return 0;
229*e7be843bSPierre Pronchery     if (!TEST_true(EVP_DigestFinalXOF(ctx, out, sizeof(out)))
230*e7be843bSPierre Pronchery         || !TEST_mem_eq(out, sizeof(out),
231*e7be843bSPierre Pronchery                         shake256_output, sizeof(shake256_output))
232*e7be843bSPierre Pronchery         || !TEST_false(EVP_DigestFinalXOF(ctx, out, sizeof(out))))
233*e7be843bSPierre Pronchery         goto err;
234*e7be843bSPierre Pronchery     ret = 1;
235*e7be843bSPierre Pronchery err:
236*e7be843bSPierre Pronchery     EVP_MD_CTX_free(ctx);
237*e7be843bSPierre Pronchery     return ret;
238*e7be843bSPierre Pronchery }
239*e7be843bSPierre Pronchery 
240*e7be843bSPierre Pronchery /*
241*e7be843bSPierre Pronchery  * Test that EVP_DigestFinal() returns the output length
242*e7be843bSPierre Pronchery  * set by the OSSL_DIGEST_PARAM_XOFLEN param.
243*e7be843bSPierre Pronchery  */
shake_kat_digestfinal_xoflen_test(void)244*e7be843bSPierre Pronchery static int shake_kat_digestfinal_xoflen_test(void)
245*e7be843bSPierre Pronchery {
246*e7be843bSPierre Pronchery     int ret = 0;
247*e7be843bSPierre Pronchery     unsigned int digest_length = 0;
248*e7be843bSPierre Pronchery     EVP_MD_CTX *ctx = NULL;
249*e7be843bSPierre Pronchery     const EVP_MD *md;
250*e7be843bSPierre Pronchery     unsigned char out[sizeof(shake256_output)];
251*e7be843bSPierre Pronchery     OSSL_PARAM params[2];
252*e7be843bSPierre Pronchery     size_t sz = 12;
253*e7be843bSPierre Pronchery 
254*e7be843bSPierre Pronchery     if (!TEST_ptr(ctx = shake_setup("SHAKE256")))
255*e7be843bSPierre Pronchery         return 0;
256*e7be843bSPierre Pronchery     md = EVP_MD_CTX_get0_md(ctx);
257*e7be843bSPierre Pronchery 
258*e7be843bSPierre Pronchery     memset(out, 0, sizeof(out));
259*e7be843bSPierre Pronchery     params[0] = OSSL_PARAM_construct_size_t(OSSL_DIGEST_PARAM_XOFLEN, &sz);
260*e7be843bSPierre Pronchery     params[1] = OSSL_PARAM_construct_end();
261*e7be843bSPierre Pronchery 
262*e7be843bSPierre Pronchery     if (!TEST_int_eq(EVP_MD_CTX_size(ctx), -1)
263*e7be843bSPierre Pronchery         || !TEST_int_eq(EVP_MD_CTX_set_params(ctx, params), 1)
264*e7be843bSPierre Pronchery         || !TEST_int_eq(EVP_MD_CTX_size(ctx), sz)
265*e7be843bSPierre Pronchery         || !TEST_int_eq(EVP_MD_get_size(md), 0)
266*e7be843bSPierre Pronchery         || !TEST_true(EVP_MD_xof(md))
267*e7be843bSPierre Pronchery         || !TEST_true(EVP_DigestUpdate(ctx, shake256_input,
268*e7be843bSPierre Pronchery                                        sizeof(shake256_input)))
269*e7be843bSPierre Pronchery         || !TEST_true(EVP_DigestFinal(ctx, out, &digest_length))
270*e7be843bSPierre Pronchery         || !TEST_uint_eq(digest_length, (unsigned int)sz)
271*e7be843bSPierre Pronchery         || !TEST_mem_eq(out, digest_length,
272*e7be843bSPierre Pronchery                         shake256_output, digest_length)
273*e7be843bSPierre Pronchery         || !TEST_uchar_eq(out[digest_length], 0))
274*e7be843bSPierre Pronchery         goto err;
275*e7be843bSPierre Pronchery     ret = 1;
276*e7be843bSPierre Pronchery err:
277*e7be843bSPierre Pronchery     EVP_MD_CTX_free(ctx);
278*e7be843bSPierre Pronchery     return ret;
279*e7be843bSPierre Pronchery }
280*e7be843bSPierre Pronchery 
281*e7be843bSPierre Pronchery /*
282*e7be843bSPierre Pronchery  * Test that multiple absorb calls gives the expected result.
283*e7be843bSPierre Pronchery  * This is a nested test that uses multiple strides for the input.
284*e7be843bSPierre Pronchery  */
shake_absorb_test(void)285*e7be843bSPierre Pronchery static int shake_absorb_test(void)
286*e7be843bSPierre Pronchery {
287*e7be843bSPierre Pronchery     int ret = 0;
288*e7be843bSPierre Pronchery     EVP_MD_CTX *ctx = NULL;
289*e7be843bSPierre Pronchery     unsigned char out[sizeof(shake256_largemsg_output)];
290*e7be843bSPierre Pronchery     size_t total = sizeof(shake256_largemsg_input);
291*e7be843bSPierre Pronchery     size_t i, stride, sz;
292*e7be843bSPierre Pronchery 
293*e7be843bSPierre Pronchery     if (!TEST_ptr(ctx = shake_setup("SHAKE256")))
294*e7be843bSPierre Pronchery         return 0;
295*e7be843bSPierre Pronchery 
296*e7be843bSPierre Pronchery     for (stride = 1; stride < total; ++stride) {
297*e7be843bSPierre Pronchery         sz = 0;
298*e7be843bSPierre Pronchery         for (i = 0; i < total; i += sz) {
299*e7be843bSPierre Pronchery             sz += stride;
300*e7be843bSPierre Pronchery             if ((i + sz) > total)
301*e7be843bSPierre Pronchery                 sz = total - i;
302*e7be843bSPierre Pronchery             if (!TEST_true(EVP_DigestUpdate(ctx, shake256_largemsg_input + i,
303*e7be843bSPierre Pronchery                                             sz)))
304*e7be843bSPierre Pronchery                 goto err;
305*e7be843bSPierre Pronchery         }
306*e7be843bSPierre Pronchery         if (!TEST_true(EVP_DigestFinalXOF(ctx, out, sizeof(out)))
307*e7be843bSPierre Pronchery             || !TEST_mem_eq(out, sizeof(out),
308*e7be843bSPierre Pronchery                             shake256_largemsg_output,
309*e7be843bSPierre Pronchery                             sizeof(shake256_largemsg_output)))
310*e7be843bSPierre Pronchery             goto err;
311*e7be843bSPierre Pronchery         if (!TEST_true(EVP_DigestInit_ex2(ctx, NULL, NULL)))
312*e7be843bSPierre Pronchery             goto err;
313*e7be843bSPierre Pronchery     }
314*e7be843bSPierre Pronchery     ret = 1;
315*e7be843bSPierre Pronchery err:
316*e7be843bSPierre Pronchery     EVP_MD_CTX_free(ctx);
317*e7be843bSPierre Pronchery     return ret;
318*e7be843bSPierre Pronchery }
319*e7be843bSPierre Pronchery 
320*e7be843bSPierre Pronchery /*
321*e7be843bSPierre Pronchery  * Table containing the size of the output to squeeze for the
322*e7be843bSPierre Pronchery  * initially call, followed by a size for each subsequent call.
323*e7be843bSPierre Pronchery  */
324*e7be843bSPierre Pronchery static const struct {
325*e7be843bSPierre Pronchery     size_t startsz, incsz;
326*e7be843bSPierre Pronchery } stride_tests[] = {
327*e7be843bSPierre Pronchery     { 1, 1 },
328*e7be843bSPierre Pronchery     { 1, 136 },
329*e7be843bSPierre Pronchery     { 1, 136/2 },
330*e7be843bSPierre Pronchery     { 1, 136/2-1 },
331*e7be843bSPierre Pronchery     { 1, 136/2+1 },
332*e7be843bSPierre Pronchery     { 1, 136*3 },
333*e7be843bSPierre Pronchery     { 8, 8 },
334*e7be843bSPierre Pronchery     { 9, 9 },
335*e7be843bSPierre Pronchery     { 10, 10 },
336*e7be843bSPierre Pronchery     { 136/2 - 1, 136 },
337*e7be843bSPierre Pronchery     { 136/2 - 1, 136-1 },
338*e7be843bSPierre Pronchery     { 136/2 - 1, 136+1 },
339*e7be843bSPierre Pronchery     { 136/2, 136 },
340*e7be843bSPierre Pronchery     { 136/2, 136-1 },
341*e7be843bSPierre Pronchery     { 136/2, 136+1 },
342*e7be843bSPierre Pronchery     { 136/2 + 1, 136 },
343*e7be843bSPierre Pronchery     { 136/2 + 1, 136-1 },
344*e7be843bSPierre Pronchery     { 136/2 + 1, 136+1 },
345*e7be843bSPierre Pronchery     { 136, 2 },
346*e7be843bSPierre Pronchery     { 136, 136 },
347*e7be843bSPierre Pronchery     { 136-1, 136 },
348*e7be843bSPierre Pronchery     { 136-1, 136-1 },
349*e7be843bSPierre Pronchery     { 136-1, 136+1 },
350*e7be843bSPierre Pronchery     { 136+1, 136 },
351*e7be843bSPierre Pronchery     { 136+1, 136-1 },
352*e7be843bSPierre Pronchery     { 136+1, 136+1 },
353*e7be843bSPierre Pronchery     { 136*3, 136 },
354*e7be843bSPierre Pronchery     { 136*3, 136 + 1 },
355*e7be843bSPierre Pronchery     { 136*3, 136 - 1 },
356*e7be843bSPierre Pronchery     { 136*3, 136/2 },
357*e7be843bSPierre Pronchery     { 136*3, 136/2 + 1 },
358*e7be843bSPierre Pronchery     { 136*3, 136/2 - 1 },
359*e7be843bSPierre Pronchery };
360*e7be843bSPierre Pronchery 
361*e7be843bSPierre Pronchery /*
362*e7be843bSPierre Pronchery  * Helper to do multiple squeezes of output data using SHAKE256.
363*e7be843bSPierre Pronchery  * tst is an index into the stride_tests[] containing an initial starting
364*e7be843bSPierre Pronchery  * output length, followed by a second output length to use for all remaining
365*e7be843bSPierre Pronchery  * squeezes. expected_outlen contains the total number of bytes to squeeze.
366*e7be843bSPierre Pronchery  * in and inlen represent the input to absorb. expected_out and expected_outlen
367*e7be843bSPierre Pronchery  * represent the expected output.
368*e7be843bSPierre Pronchery  */
do_shake_squeeze_test(int tst,const unsigned char * in,size_t inlen,const unsigned char * expected_out,size_t expected_outlen)369*e7be843bSPierre Pronchery static int do_shake_squeeze_test(int tst,
370*e7be843bSPierre Pronchery                                  const unsigned char *in, size_t inlen,
371*e7be843bSPierre Pronchery                                  const unsigned char *expected_out,
372*e7be843bSPierre Pronchery                                  size_t expected_outlen)
373*e7be843bSPierre Pronchery {
374*e7be843bSPierre Pronchery     int ret = 0;
375*e7be843bSPierre Pronchery     EVP_MD_CTX *ctx = NULL;
376*e7be843bSPierre Pronchery     unsigned char *out = NULL;
377*e7be843bSPierre Pronchery     size_t i = 0, sz = stride_tests[tst].startsz;
378*e7be843bSPierre Pronchery 
379*e7be843bSPierre Pronchery     if (!TEST_ptr(ctx = shake_setup("SHAKE256")))
380*e7be843bSPierre Pronchery         return 0;
381*e7be843bSPierre Pronchery     if (!TEST_ptr(out = OPENSSL_malloc(expected_outlen)))
382*e7be843bSPierre Pronchery         goto err;
383*e7be843bSPierre Pronchery     if (!TEST_true(EVP_DigestUpdate(ctx, in, inlen)))
384*e7be843bSPierre Pronchery         goto err;
385*e7be843bSPierre Pronchery 
386*e7be843bSPierre Pronchery     while (i < expected_outlen) {
387*e7be843bSPierre Pronchery         if ((i + sz) > expected_outlen)
388*e7be843bSPierre Pronchery             sz = expected_outlen - i;
389*e7be843bSPierre Pronchery         if (!TEST_true(EVP_DigestSqueeze(ctx, out + i, sz)))
390*e7be843bSPierre Pronchery             goto err;
391*e7be843bSPierre Pronchery         i += sz;
392*e7be843bSPierre Pronchery         sz = stride_tests[tst].incsz;
393*e7be843bSPierre Pronchery     }
394*e7be843bSPierre Pronchery     if (!TEST_mem_eq(out, expected_outlen, expected_out, expected_outlen))
395*e7be843bSPierre Pronchery         goto err;
396*e7be843bSPierre Pronchery     ret = 1;
397*e7be843bSPierre Pronchery err:
398*e7be843bSPierre Pronchery     OPENSSL_free(out);
399*e7be843bSPierre Pronchery     EVP_MD_CTX_free(ctx);
400*e7be843bSPierre Pronchery     return ret;
401*e7be843bSPierre Pronchery }
402*e7be843bSPierre Pronchery 
shake_squeeze_kat_test(int tst)403*e7be843bSPierre Pronchery static int shake_squeeze_kat_test(int tst)
404*e7be843bSPierre Pronchery {
405*e7be843bSPierre Pronchery     return do_shake_squeeze_test(tst, shake256_input, sizeof(shake256_input),
406*e7be843bSPierre Pronchery                                  shake256_output, sizeof(shake256_output));
407*e7be843bSPierre Pronchery }
408*e7be843bSPierre Pronchery 
409*e7be843bSPierre Pronchery /*
410*e7be843bSPierre Pronchery  * Generate some random input to absorb, and then
411*e7be843bSPierre Pronchery  * squeeze it out in one operation to get a expected
412*e7be843bSPierre Pronchery  * output. Use this to test that multiple squeeze calls
413*e7be843bSPierre Pronchery  * on the same input gives the same output.
414*e7be843bSPierre Pronchery  */
shake_squeeze_large_test(int tst)415*e7be843bSPierre Pronchery static int shake_squeeze_large_test(int tst)
416*e7be843bSPierre Pronchery {
417*e7be843bSPierre Pronchery     int ret = 0;
418*e7be843bSPierre Pronchery     EVP_MD_CTX *ctx = NULL;
419*e7be843bSPierre Pronchery     unsigned char msg[16];
420*e7be843bSPierre Pronchery     unsigned char out[2000];
421*e7be843bSPierre Pronchery 
422*e7be843bSPierre Pronchery     if (!TEST_int_gt(RAND_bytes(msg, sizeof(msg)), 0)
423*e7be843bSPierre Pronchery         || !TEST_ptr(ctx = shake_setup("SHAKE256"))
424*e7be843bSPierre Pronchery         || !TEST_true(EVP_DigestUpdate(ctx, msg, sizeof(msg)))
425*e7be843bSPierre Pronchery         || !TEST_true(EVP_DigestFinalXOF(ctx, out, sizeof(out))))
426*e7be843bSPierre Pronchery         goto err;
427*e7be843bSPierre Pronchery 
428*e7be843bSPierre Pronchery     ret = do_shake_squeeze_test(tst, msg, sizeof(msg), out, sizeof(out));
429*e7be843bSPierre Pronchery err:
430*e7be843bSPierre Pronchery     EVP_MD_CTX_free(ctx);
431*e7be843bSPierre Pronchery     return ret;
432*e7be843bSPierre Pronchery }
433*e7be843bSPierre Pronchery 
434*e7be843bSPierre Pronchery static const size_t dupoffset_tests[] = {
435*e7be843bSPierre Pronchery     1, 135, 136, 137, 136*3-1, 136*3, 136*3+1
436*e7be843bSPierre Pronchery };
437*e7be843bSPierre Pronchery 
438*e7be843bSPierre Pronchery /* Helper function to test that EVP_MD_CTX_dup() copies the internal state */
do_shake_squeeze_dup_test(int tst,const char * alg,const unsigned char * in,size_t inlen,const unsigned char * expected_out,size_t expected_outlen)439*e7be843bSPierre Pronchery static int do_shake_squeeze_dup_test(int tst, const char *alg,
440*e7be843bSPierre Pronchery                                      const unsigned char *in, size_t inlen,
441*e7be843bSPierre Pronchery                                      const unsigned char *expected_out,
442*e7be843bSPierre Pronchery                                      size_t expected_outlen)
443*e7be843bSPierre Pronchery {
444*e7be843bSPierre Pronchery     int ret = 0;
445*e7be843bSPierre Pronchery     EVP_MD_CTX *cur, *ctx = NULL, *dupctx = NULL;
446*e7be843bSPierre Pronchery     unsigned char *out = NULL;
447*e7be843bSPierre Pronchery     size_t i = 0, sz = 10;
448*e7be843bSPierre Pronchery     size_t dupoffset = dupoffset_tests[tst];
449*e7be843bSPierre Pronchery 
450*e7be843bSPierre Pronchery     if (!TEST_ptr(ctx = shake_setup(alg)))
451*e7be843bSPierre Pronchery         return 0;
452*e7be843bSPierre Pronchery     cur = ctx;
453*e7be843bSPierre Pronchery     if (!TEST_ptr(out = OPENSSL_malloc(expected_outlen)))
454*e7be843bSPierre Pronchery         goto err;
455*e7be843bSPierre Pronchery     if (!TEST_true(EVP_DigestUpdate(ctx, in, inlen)))
456*e7be843bSPierre Pronchery         goto err;
457*e7be843bSPierre Pronchery 
458*e7be843bSPierre Pronchery     while (i < expected_outlen) {
459*e7be843bSPierre Pronchery         if ((i + sz) > expected_outlen)
460*e7be843bSPierre Pronchery             sz = expected_outlen - i;
461*e7be843bSPierre Pronchery         if (!TEST_true(EVP_DigestSqueeze(cur, out + i, sz)))
462*e7be843bSPierre Pronchery             goto err;
463*e7be843bSPierre Pronchery         i += sz;
464*e7be843bSPierre Pronchery         /* At a certain offset we swap to a new ctx that copies the state */
465*e7be843bSPierre Pronchery         if (dupctx == NULL && i >= dupoffset) {
466*e7be843bSPierre Pronchery             if (!TEST_ptr(dupctx = EVP_MD_CTX_dup(ctx)))
467*e7be843bSPierre Pronchery                 goto err;
468*e7be843bSPierre Pronchery             cur = dupctx;
469*e7be843bSPierre Pronchery         }
470*e7be843bSPierre Pronchery     }
471*e7be843bSPierre Pronchery     if (!TEST_mem_eq(out, expected_outlen, expected_out, expected_outlen))
472*e7be843bSPierre Pronchery         goto err;
473*e7be843bSPierre Pronchery     ret = 1;
474*e7be843bSPierre Pronchery err:
475*e7be843bSPierre Pronchery     OPENSSL_free(out);
476*e7be843bSPierre Pronchery     EVP_MD_CTX_free(ctx);
477*e7be843bSPierre Pronchery     EVP_MD_CTX_free(dupctx);
478*e7be843bSPierre Pronchery     return ret;
479*e7be843bSPierre Pronchery }
480*e7be843bSPierre Pronchery 
481*e7be843bSPierre Pronchery /* Test that the internal state can be copied */
shake_squeeze_dup_test(int tst)482*e7be843bSPierre Pronchery static int shake_squeeze_dup_test(int tst)
483*e7be843bSPierre Pronchery {
484*e7be843bSPierre Pronchery     int ret = 0;
485*e7be843bSPierre Pronchery     EVP_MD_CTX *ctx = NULL;
486*e7be843bSPierre Pronchery     unsigned char msg[16];
487*e7be843bSPierre Pronchery     unsigned char out[1000];
488*e7be843bSPierre Pronchery     const char *alg = "SHAKE128";
489*e7be843bSPierre Pronchery 
490*e7be843bSPierre Pronchery     if (!TEST_int_gt(RAND_bytes(msg, sizeof(msg)), 0)
491*e7be843bSPierre Pronchery         || !TEST_ptr(ctx = shake_setup(alg))
492*e7be843bSPierre Pronchery         || !TEST_true(EVP_DigestUpdate(ctx, msg, sizeof(msg)))
493*e7be843bSPierre Pronchery         || !TEST_true(EVP_DigestFinalXOF(ctx, out, sizeof(out))))
494*e7be843bSPierre Pronchery         goto err;
495*e7be843bSPierre Pronchery 
496*e7be843bSPierre Pronchery     ret = do_shake_squeeze_dup_test(tst, alg, msg, sizeof(msg),
497*e7be843bSPierre Pronchery                                     out, sizeof(out));
498*e7be843bSPierre Pronchery err:
499*e7be843bSPierre Pronchery     EVP_MD_CTX_free(ctx);
500*e7be843bSPierre Pronchery     return ret;
501*e7be843bSPierre Pronchery }
502*e7be843bSPierre Pronchery 
503*e7be843bSPierre Pronchery /* Test that a squeeze without a preceding absorb works */
shake_squeeze_no_absorb_test(void)504*e7be843bSPierre Pronchery static int shake_squeeze_no_absorb_test(void)
505*e7be843bSPierre Pronchery {
506*e7be843bSPierre Pronchery     int ret = 0;
507*e7be843bSPierre Pronchery     EVP_MD_CTX *ctx = NULL;
508*e7be843bSPierre Pronchery     unsigned char out[1000];
509*e7be843bSPierre Pronchery     unsigned char out2[1000];
510*e7be843bSPierre Pronchery     const char *alg = "SHAKE128";
511*e7be843bSPierre Pronchery 
512*e7be843bSPierre Pronchery     if (!TEST_ptr(ctx = shake_setup(alg))
513*e7be843bSPierre Pronchery         || !TEST_true(EVP_DigestFinalXOF(ctx, out, sizeof(out))))
514*e7be843bSPierre Pronchery         goto err;
515*e7be843bSPierre Pronchery 
516*e7be843bSPierre Pronchery     if (!TEST_true(EVP_DigestInit_ex2(ctx, NULL, NULL))
517*e7be843bSPierre Pronchery         || !TEST_true(EVP_DigestSqueeze(ctx, out2, sizeof(out2) / 2))
518*e7be843bSPierre Pronchery         || !TEST_true(EVP_DigestSqueeze(ctx, out2 + sizeof(out2) / 2,
519*e7be843bSPierre Pronchery                                         sizeof(out2) / 2)))
520*e7be843bSPierre Pronchery         goto err;
521*e7be843bSPierre Pronchery 
522*e7be843bSPierre Pronchery     if (!TEST_mem_eq(out2, sizeof(out2), out, sizeof(out)))
523*e7be843bSPierre Pronchery         goto err;
524*e7be843bSPierre Pronchery     ret = 1;
525*e7be843bSPierre Pronchery 
526*e7be843bSPierre Pronchery err:
527*e7be843bSPierre Pronchery     EVP_MD_CTX_free(ctx);
528*e7be843bSPierre Pronchery     return ret;
529*e7be843bSPierre Pronchery }
530*e7be843bSPierre Pronchery 
xof_fail_test(void)531*e7be843bSPierre Pronchery static int xof_fail_test(void)
532*e7be843bSPierre Pronchery {
533*e7be843bSPierre Pronchery     int ret;
534*e7be843bSPierre Pronchery     EVP_MD *md = NULL;
535*e7be843bSPierre Pronchery 
536*e7be843bSPierre Pronchery     ret = TEST_ptr(md = EVP_MD_fetch(NULL, "SHA256", NULL))
537*e7be843bSPierre Pronchery             && TEST_false(EVP_MD_xof(md));
538*e7be843bSPierre Pronchery     EVP_MD_free(md);
539*e7be843bSPierre Pronchery     return ret;
540*e7be843bSPierre Pronchery }
541*e7be843bSPierre Pronchery 
setup_tests(void)542*e7be843bSPierre Pronchery int setup_tests(void)
543*e7be843bSPierre Pronchery {
544*e7be843bSPierre Pronchery     ADD_TEST(shake_kat_test);
545*e7be843bSPierre Pronchery     ADD_TEST(shake_kat_digestfinal_test);
546*e7be843bSPierre Pronchery     ADD_TEST(shake_kat_digestfinal_xoflen_test);
547*e7be843bSPierre Pronchery     ADD_TEST(shake_absorb_test);
548*e7be843bSPierre Pronchery     ADD_ALL_TESTS(shake_squeeze_kat_test, OSSL_NELEM(stride_tests));
549*e7be843bSPierre Pronchery     ADD_ALL_TESTS(shake_squeeze_large_test, OSSL_NELEM(stride_tests));
550*e7be843bSPierre Pronchery     ADD_ALL_TESTS(shake_squeeze_dup_test, OSSL_NELEM(dupoffset_tests));
551*e7be843bSPierre Pronchery     ADD_TEST(xof_fail_test);
552*e7be843bSPierre Pronchery     ADD_TEST(shake_squeeze_no_absorb_test);
553*e7be843bSPierre Pronchery     return 1;
554*e7be843bSPierre Pronchery }
555