@@ -109,56 +109,76 @@ static int test_hkdf_double_set_salt(OSSL_LIB_CTX* libCtx, unsigned char *key,
109109
110110 ctx = EVP_PKEY_CTX_new_from_name (libCtx , "HKDF" , NULL );
111111 if (ctx == NULL ) {
112+ PRINT_MSG ("Failed to create HKDF context" );
112113 err = 1 ;
113114 }
114115 if (err == 0 ) {
115116 if (EVP_PKEY_derive_init (ctx ) != 1 ) {
117+ PRINT_MSG ("Failed to init HKDF derive" );
116118 err = 1 ;
117119 }
118120 }
119121 if (err == 0 ) {
120122 if (EVP_PKEY_CTX_hkdf_mode (ctx , mode ) != 1 ) {
123+ PRINT_MSG ("Failed to set HKDF mode" );
121124 err = 1 ;
122125 }
123126 }
124127 if (err == 0 ) {
125128 if (EVP_PKEY_CTX_set_hkdf_md (ctx , md ) != 1 ) {
129+ PRINT_MSG ("Failed to set HKDF md" );
126130 err = 1 ;
127131 }
128132 }
129133 if (err == 0 ) {
130134 if (EVP_PKEY_CTX_set1_hkdf_key (ctx , inKey , sizeof (inKey )) != 1 ) {
135+ PRINT_MSG ("Failed to set HKDF key" );
131136 err = 1 ;
132137 }
133138 }
134139 if ((err == 0 ) && (mode != EVP_PKEY_HKDEF_MODE_EXPAND_ONLY )) {
140+ #if OPENSSL_VERSION_NUMBER >= 0x30100000L && \
141+ OPENSSL_VERSION_NUMBER != 0x30200050L && \
142+ OPENSSL_VERSION_NUMBER != 0x30300040L
135143 if (EVP_PKEY_CTX_set1_hkdf_salt (ctx , NULL , 0 ) != 1 ) {
144+ #else
145+ /* In 3.1.x, the following code was added to hkdf_common_set_ctx_params()
146+ * if (p->data_size != 0 && p->data != NULL) {
147+ * The above code is not present in 3.2.5 and 3.3.4. */
148+ if (EVP_PKEY_CTX_set1_hkdf_salt (ctx , NULL , 0 ) != 0 ) {
149+ #endif
150+ PRINT_MSG ("Failed to set HKDF salt to NULL" );
136151 err = 1 ;
137152 }
138153 }
139154 if ((err == 0 ) && (mode != EVP_PKEY_HKDEF_MODE_EXPAND_ONLY )) {
140155 if (EVP_PKEY_CTX_set1_hkdf_salt (ctx , salt , sizeof (salt )) != 1 ) {
156+ PRINT_MSG ("Failed to set HKDF salt" );
141157 err = 1 ;
142158 }
143159 }
144160 if ((err == 0 ) && (mode != EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY )) {
145161 if (EVP_PKEY_CTX_add1_hkdf_info (ctx , info , sizeof (info )) != 1 ) {
162+ PRINT_MSG ("Failed to set HKDF info" );
146163 err = 1 ;
147164 }
148165 }
149166 if (err == 0 ) {
150167 if (EVP_PKEY_derive (ctx , key , & len ) != 1 ) {
168+ PRINT_MSG ("Failed to derive HKDF key" );
151169 err = 1 ;
152170 }
153171 }
154172
155173 if ((err == 0 ) && (mode != EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY )) {
156174 if (len != (size_t )keyLen ) {
175+ PRINT_MSG ("HKDF key length mismatch" );
157176 err = 1 ;
158177 }
159178 }
160179 else {
161180 if (len != (size_t )EVP_MD_size (md )) {
181+ PRINT_MSG ("HKDF key length mismatch for extract only" );
162182 err = 1 ;
163183 }
164184 }
@@ -204,6 +224,7 @@ static int test_hkdf_md(const EVP_MD *md, int mode)
204224 memset (wKey , 0 , sizeof (wKey ));
205225
206226 if (err == 0 ) {
227+ PRINT_MSG ("Calc with OpenSSL" );
207228 err = test_hkdf_double_set_salt (osslLibCtx , oKey , sizeof (oKey ), md , mode );
208229 if (err == 1 ) {
209230 PRINT_MSG ("FAILED OpenSSL" );
0 commit comments