Skip to content

Commit 557b2fd

Browse files
authored
Merge pull request #690 from hansonchar/develop
Replace CKR_GENERAL_ERROR with CKR_ENCRYPTED_DATA_INVALID or CKR_ENCRYPTED_DATA_LEN_RANGE upon decryption failure
2 parents 7081d3b + e287379 commit 557b2fd

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/lib/SoftHSM.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,15 +3309,15 @@ static CK_RV SymDecrypt(Session* session, CK_BYTE_PTR pEncryptedData, CK_ULONG u
33093309
if (!cipher->decryptUpdate(encryptedData,data))
33103310
{
33113311
session->resetOp();
3312-
return CKR_GENERAL_ERROR;
3312+
return CKR_ENCRYPTED_DATA_INVALID;
33133313
}
33143314

33153315
// Finalize decryption
33163316
ByteString dataFinal;
33173317
if (!cipher->decryptFinal(dataFinal))
33183318
{
33193319
session->resetOp();
3320-
return CKR_GENERAL_ERROR;
3320+
return CKR_ENCRYPTED_DATA_INVALID;
33213321
}
33223322
data += dataFinal;
33233323
if (data.size() > ulEncryptedDataLen)
@@ -3378,15 +3378,15 @@ static CK_RV AsymDecrypt(Session* session, CK_BYTE_PTR pEncryptedData, CK_ULONG
33783378
if (!asymCrypto->decrypt(privateKey,encryptedData,data,mechanism))
33793379
{
33803380
session->resetOp();
3381-
return CKR_GENERAL_ERROR;
3381+
return CKR_ENCRYPTED_DATA_INVALID;
33823382
}
33833383

33843384
// Check size
33853385
if (data.size() > size)
33863386
{
33873387
ERROR_MSG("The size of the decrypted data exceeds the size of the mechanism");
33883388
session->resetOp();
3389-
return CKR_GENERAL_ERROR;
3389+
return CKR_ENCRYPTED_DATA_LEN_RANGE;
33903390
}
33913391
if (data.size() != 0)
33923392
{
@@ -3475,22 +3475,22 @@ static CK_RV SymDecryptUpdate(Session* session, CK_BYTE_PTR pEncryptedData, CK_U
34753475
ByteString data(pEncryptedData, ulEncryptedDataLen);
34763476
ByteString decryptedData;
34773477

3478-
// Encrypt the data
3478+
// Decrypt the data
34793479
if (!cipher->decryptUpdate(data, decryptedData))
34803480
{
34813481
session->resetOp();
3482-
return CKR_GENERAL_ERROR;
3482+
return CKR_ENCRYPTED_DATA_INVALID;
34833483
}
34843484
DEBUG_MSG("ulEncryptedDataLen: %#5x output buffer size: %#5x blockSize: %#3x remainingSize: %#4x maxSize: %#5x decryptedData.size(): %#5x",
34853485
ulEncryptedDataLen, *pDataLen, blockSize, remainingSize, maxSize, decryptedData.size());
34863486

3487-
// Check output size from crypto. Unrecoverable error if to large.
3487+
// Check output size from crypto. Unrecoverable error if too large.
34883488
if (*pDataLen < decryptedData.size())
34893489
{
34903490
session->resetOp();
34913491
ERROR_MSG("DecryptUpdate returning too much data. Length of output data buffer is %i but %i bytes was returned by the decrypt.",
34923492
*pDataLen, decryptedData.size());
3493-
return CKR_GENERAL_ERROR;
3493+
return CKR_ENCRYPTED_DATA_LEN_RANGE;
34943494
}
34953495

34963496
if (decryptedData.size() > 0)
@@ -3578,7 +3578,7 @@ static CK_RV SymDecryptFinal(Session* session, CK_BYTE_PTR pDecryptedData, CK_UL
35783578
if (!cipher->decryptFinal(decryptedFinal))
35793579
{
35803580
session->resetOp();
3581-
return CKR_GENERAL_ERROR;
3581+
return CKR_ENCRYPTED_DATA_INVALID;
35823582
}
35833583
DEBUG_MSG("output buffer size: %#2x size: %#2x decryptedFinal.size(): %#2x",
35843584
*pulDecryptedDataLen, size, decryptedFinal.size());
@@ -3589,7 +3589,7 @@ static CK_RV SymDecryptFinal(Session* session, CK_BYTE_PTR pDecryptedData, CK_UL
35893589
session->resetOp();
35903590
ERROR_MSG("DecryptFinal returning too much data. Length of output data buffer is %i but %i bytes was returned by the encrypt.",
35913591
*pulDecryptedDataLen, decryptedFinal.size());
3592-
return CKR_GENERAL_ERROR;
3592+
return CKR_ENCRYPTED_DATA_LEN_RANGE;
35933593
}
35943594

35953595
if (decryptedFinal.size() > 0)

0 commit comments

Comments
 (0)