@@ -113,13 +113,25 @@ static int test_krb5kdf_error_cases(OSSL_LIB_CTX* libCtx)
113113 }
114114 PRINT_MSG ("Negative test passed - KRB5KDF correctly rejected wrong key size for AES-256-CBC" );
115115
116+ PRINT_MSG ("Testing KRB5KDF error case - 0 length constant" );
117+ /* This should fail since AES-256 key size is 32 bytes */
118+ err = test_krb5kdf_calc (libCtx , key , sizeof (key ), "AES-256-CBC" ,
119+ inKey16 , sizeof (inKey16 ), constant , 0 );
120+ if (err == 0 ) {
121+ /* If we get here, the test failed because it should have errored */
122+ PRINT_MSG ("FAILED: KRB5KDF accepted 0 length constant" );
123+ return 1 ;
124+ }
125+ PRINT_MSG ("Negative test passed - KRB5KDF correctly rejected 0 length constant" );
126+
116127 return 0 ;
117128}
118129
119130/* Test vectors */
120131static int test_krb5kdf_vector (void )
121132{
122133 int err = 0 ;
134+ int i ;
123135 unsigned char oKey [32 ];
124136 unsigned char wKey [32 ];
125137 /* Test vector - AES-128-CBC */
@@ -135,51 +147,55 @@ static int test_krb5kdf_vector(void)
135147 0x19 , 0x1a , 0x1b , 0x1c , 0x1d , 0x1e , 0x1f , 0x20
136148 };
137149 unsigned char constant [] = {
150+ 0x11 , 0x22 , 0x33 , 0x44 , 0x55 , 0x66 , 0x77 , 0x88 ,
138151 0x11 , 0x22 , 0x33 , 0x44 , 0x55 , 0x66 , 0x77 , 0x88
139152 };
140153
141- /* Test AES-128-CBC */
142- PRINT_MSG ("Testing KRB5KDF with OpenSSL - AES-128-CBC" );
143- err = test_krb5kdf_calc (osslLibCtx , oKey , 16 , "AES-128-CBC" ,
144- inKey128 , sizeof (inKey128 ), constant , sizeof (constant ));
145- if (err == 1 ) {
146- PRINT_MSG ("FAILED OpenSSL - AES-128-CBC" );
147- return err ;
148- }
149- PRINT_MSG ("Testing KRB5KDF with wolfSSL - AES-128-CBC" );
150- err = test_krb5kdf_calc (wpLibCtx , wKey , 16 , "AES-128-CBC" ,
151- inKey128 , sizeof (inKey128 ), constant , sizeof (constant ));
152- if (err == 1 ) {
153- PRINT_MSG ("FAILED wolfSSL - AES-128-CBC" );
154- return err ;
155- }
156- if (memcmp (oKey , wKey , 16 ) != 0 ) {
157- PRINT_MSG ("FAILED, wolfSSL and OpenSSL derived different keys" );
158- PRINT_BUFFER ("OpenSSL key" , oKey , 16 );
159- PRINT_BUFFER ("wolfSSL key" , wKey , 16 );
160- return 1 ;
161- }
162-
163- /* Test AES-256-CBC */
164- PRINT_MSG ("Testing KRB5KDF with OpenSSL - AES-256-CBC" );
165- err = test_krb5kdf_calc (osslLibCtx , oKey , 32 , "AES-256-CBC" ,
166- inKey256 , sizeof (inKey256 ), constant , sizeof (constant ));
167- if (err == 1 ) {
168- PRINT_MSG ("FAILED OpenSSL - AES-256-CBC" );
169- return err ;
170- }
171- PRINT_MSG ("Testing KRB5KDF with wolfSSL - AES-256-CBC" );
172- err = test_krb5kdf_calc (wpLibCtx , wKey , 32 , "AES-256-CBC" ,
173- inKey256 , sizeof (inKey256 ), constant , sizeof (constant ));
174- if (err == 1 ) {
175- PRINT_MSG ("FAILED wolfSSL - AES-256-CBC" );
176- return err ;
177- }
178- if (memcmp (oKey , wKey , 32 ) != 0 ) {
179- PRINT_MSG ("FAILED, wolfSSL and OpenSSL derived different keys" );
180- PRINT_BUFFER ("OpenSSL key" , oKey , 32 );
181- PRINT_BUFFER ("wolfSSL key" , wKey , 32 );
182- return 1 ;
154+ for (i = 1 ; i < (int )sizeof (constant ); i ++ ) {
155+ PRINT_MSG ("Constant Length: %d" , i );
156+ /* Test AES-128-CBC */
157+ PRINT_MSG ("Testing KRB5KDF with OpenSSL - AES-128-CBC" );
158+ err = test_krb5kdf_calc (osslLibCtx , oKey , 16 , "AES-128-CBC" ,
159+ inKey128 , sizeof (inKey128 ), constant , i );
160+ if (err == 1 ) {
161+ PRINT_MSG ("FAILED OpenSSL - AES-128-CBC" );
162+ return err ;
163+ }
164+ PRINT_MSG ("Testing KRB5KDF with wolfSSL - AES-128-CBC" );
165+ err = test_krb5kdf_calc (wpLibCtx , wKey , 16 , "AES-128-CBC" ,
166+ inKey128 , sizeof (inKey128 ), constant , i );
167+ if (err == 1 ) {
168+ PRINT_MSG ("FAILED wolfSSL - AES-128-CBC" );
169+ return err ;
170+ }
171+ if (memcmp (oKey , wKey , 16 ) != 0 ) {
172+ PRINT_MSG ("FAILED, wolfSSL and OpenSSL derived different keys" );
173+ PRINT_BUFFER ("OpenSSL key" , oKey , 16 );
174+ PRINT_BUFFER ("wolfSSL key" , wKey , 16 );
175+ return 1 ;
176+ }
177+
178+ /* Test AES-256-CBC */
179+ PRINT_MSG ("Testing KRB5KDF with OpenSSL - AES-256-CBC" );
180+ err = test_krb5kdf_calc (osslLibCtx , oKey , 32 , "AES-256-CBC" ,
181+ inKey256 , sizeof (inKey256 ), constant , i );
182+ if (err == 1 ) {
183+ PRINT_MSG ("FAILED OpenSSL - AES-256-CBC" );
184+ return err ;
185+ }
186+ PRINT_MSG ("Testing KRB5KDF with wolfSSL - AES-256-CBC" );
187+ err = test_krb5kdf_calc (wpLibCtx , wKey , 32 , "AES-256-CBC" ,
188+ inKey256 , sizeof (inKey256 ), constant , i );
189+ if (err == 1 ) {
190+ PRINT_MSG ("FAILED wolfSSL - AES-256-CBC" );
191+ return err ;
192+ }
193+ if (memcmp (oKey , wKey , 32 ) != 0 ) {
194+ PRINT_MSG ("FAILED, wolfSSL and OpenSSL derived different keys" );
195+ PRINT_BUFFER ("OpenSSL key" , oKey , 32 );
196+ PRINT_BUFFER ("wolfSSL key" , wKey , 32 );
197+ return 1 ;
198+ }
183199 }
184200
185201 return err ;
0 commit comments