@@ -5289,6 +5289,48 @@ static CK_RV test_digest_fail(void* args)
52895289 return ret;
52905290}
52915291
5292+ #ifndef NO_SHA256
5293+ static CK_RV test_digest_single_size_query(void* args)
5294+ {
5295+ CK_SESSION_HANDLE session = *(CK_SESSION_HANDLE*)args;
5296+ CK_RV ret;
5297+ CK_MECHANISM mech;
5298+ byte data[32], hash[32];
5299+ CK_ULONG dataSz = sizeof(data);
5300+ CK_ULONG hashSz = 0;
5301+
5302+ XMEMSET(data, 0x42, sizeof(data));
5303+ mech.mechanism = CKM_SHA256;
5304+ mech.ulParameterLen = 0;
5305+ mech.pParameter = NULL;
5306+
5307+ /* C_Digest with pDigest=NULL should return size without computing */
5308+ ret = funcList->C_DigestInit(session, &mech);
5309+ CHECK_CKR(ret, "Digest Init for size query");
5310+ if (ret == CKR_OK) {
5311+ hashSz = 0;
5312+ ret = funcList->C_Digest(session, data, dataSz, NULL, &hashSz);
5313+ CHECK_CKR(ret, "C_Digest size query with pDigest=NULL");
5314+ }
5315+ if (ret == CKR_OK && hashSz != 32) {
5316+ ret = -1;
5317+ CHECK_CKR(ret, "C_Digest size query should return 32 for SHA-256");
5318+ }
5319+ /* Now actually compute with properly sized buffer */
5320+ if (ret == CKR_OK) {
5321+ hashSz = sizeof(hash);
5322+ ret = funcList->C_Digest(session, data, dataSz, hash, &hashSz);
5323+ CHECK_CKR(ret, "C_Digest compute");
5324+ }
5325+ if (ret == CKR_OK && hashSz != 32) {
5326+ ret = -1;
5327+ CHECK_CKR(ret, "C_Digest output should be 32 for SHA-256");
5328+ }
5329+
5330+ return ret;
5331+ }
5332+ #endif
5333+
52925334static CK_RV test_sign_verify(void* args)
52935335{
52945336 CK_SESSION_HANDLE session = *(CK_SESSION_HANDLE*)args;
@@ -17233,6 +17275,9 @@ static TEST_FUNC testFunc[] = {
1723317275 PKCS11TEST_FUNC_SESS_DECL(test_encrypt_decrypt_op_not_supported),
1723417276#endif
1723517277 PKCS11TEST_FUNC_SESS_DECL(test_digest_fail),
17278+ #ifndef NO_SHA256
17279+ PKCS11TEST_FUNC_SESS_DECL(test_digest_single_size_query),
17280+ #endif
1723617281 PKCS11TEST_FUNC_SESS_DECL(test_sign_verify),
1723717282 PKCS11TEST_FUNC_SESS_DECL(test_sign_verify_op_not_supported),
1723817283 PKCS11TEST_FUNC_SESS_DECL(test_recover),
0 commit comments