Skip to content

Commit a254964

Browse files
committed
Replace CKR_GENERAL_ERROR with CKR_ENCRYPTED_DATA_INVALID or CKR_ENCRYPTED_DATA_LEN_RANGE upon decryption failure
#689
1 parent ac70dc3 commit a254964

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/lib/SoftHSM.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,15 +3296,15 @@ static CK_RV SymDecrypt(Session* session, CK_BYTE_PTR pEncryptedData, CK_ULONG u
32963296
if (!cipher->decryptUpdate(encryptedData,data))
32973297
{
32983298
session->resetOp();
3299-
return CKR_GENERAL_ERROR;
3299+
return CKR_ENCRYPTED_DATA_INVALID;
33003300
}
33013301

33023302
// Finalize decryption
33033303
ByteString dataFinal;
33043304
if (!cipher->decryptFinal(dataFinal))
33053305
{
33063306
session->resetOp();
3307-
return CKR_GENERAL_ERROR;
3307+
return CKR_ENCRYPTED_DATA_INVALID;
33083308
}
33093309
data += dataFinal;
33103310
if (data.size() > ulEncryptedDataLen)
@@ -3365,15 +3365,15 @@ static CK_RV AsymDecrypt(Session* session, CK_BYTE_PTR pEncryptedData, CK_ULONG
33653365
if (!asymCrypto->decrypt(privateKey,encryptedData,data,mechanism))
33663366
{
33673367
session->resetOp();
3368-
return CKR_GENERAL_ERROR;
3368+
return CKR_ENCRYPTED_DATA_INVALID;
33693369
}
33703370

33713371
// Check size
33723372
if (data.size() > size)
33733373
{
33743374
ERROR_MSG("The size of the decrypted data exceeds the size of the mechanism");
33753375
session->resetOp();
3376-
return CKR_GENERAL_ERROR;
3376+
return CKR_ENCRYPTED_DATA_LEN_RANGE;
33773377
}
33783378
if (data.size() != 0)
33793379
{
@@ -3458,22 +3458,22 @@ static CK_RV SymDecryptUpdate(Session* session, CK_BYTE_PTR pEncryptedData, CK_U
34583458
ByteString data(pEncryptedData, ulEncryptedDataLen);
34593459
ByteString decryptedData;
34603460

3461-
// Encrypt the data
3461+
// Decrypt the data
34623462
if (!cipher->decryptUpdate(data, decryptedData))
34633463
{
34643464
session->resetOp();
3465-
return CKR_GENERAL_ERROR;
3465+
return CKR_ENCRYPTED_DATA_INVALID;
34663466
}
34673467
DEBUG_MSG("ulEncryptedDataLen: %#5x output buffer size: %#5x blockSize: %#3x remainingSize: %#4x maxSize: %#5x decryptedData.size(): %#5x",
34683468
ulEncryptedDataLen, *pDataLen, blockSize, remainingSize, maxSize, decryptedData.size());
34693469

3470-
// Check output size from crypto. Unrecoverable error if to large.
3470+
// Check output size from crypto. Unrecoverable error if too large.
34713471
if (*pDataLen < decryptedData.size())
34723472
{
34733473
session->resetOp();
34743474
ERROR_MSG("DecryptUpdate returning too much data. Length of output data buffer is %i but %i bytes was returned by the decrypt.",
34753475
*pDataLen, decryptedData.size());
3476-
return CKR_GENERAL_ERROR;
3476+
return CKR_ENCRYPTED_DATA_LEN_RANGE;
34773477
}
34783478

34793479
if (decryptedData.size() > 0)
@@ -3557,7 +3557,7 @@ static CK_RV SymDecryptFinal(Session* session, CK_BYTE_PTR pDecryptedData, CK_UL
35573557
if (!cipher->decryptFinal(decryptedFinal))
35583558
{
35593559
session->resetOp();
3560-
return CKR_GENERAL_ERROR;
3560+
return CKR_ENCRYPTED_DATA_INVALID;
35613561
}
35623562
DEBUG_MSG("output buffer size: %#2x size: %#2x decryptedFinal.size(): %#2x",
35633563
*pulDecryptedDataLen, size, decryptedFinal.size());
@@ -3568,7 +3568,7 @@ static CK_RV SymDecryptFinal(Session* session, CK_BYTE_PTR pDecryptedData, CK_UL
35683568
session->resetOp();
35693569
ERROR_MSG("DecryptFinal returning too much data. Length of output data buffer is %i but %i bytes was returned by the encrypt.",
35703570
*pulDecryptedDataLen, decryptedFinal.size());
3571-
return CKR_GENERAL_ERROR;
3571+
return CKR_ENCRYPTED_DATA_LEN_RANGE;
35723572
}
35733573

35743574
if (decryptedFinal.size() > 0)

0 commit comments

Comments
 (0)