-
Notifications
You must be signed in to change notification settings - Fork 411
Add AES-CCM #883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add AES-CCM #883
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -810,6 +810,7 @@ void SoftHSM::prepareSupportedMechanisms(std::map<std::string, CK_MECHANISM_TYPE | |
| t["CKM_AES_CBC_PAD"] = CKM_AES_CBC_PAD; | ||
| t["CKM_AES_CTR"] = CKM_AES_CTR; | ||
| t["CKM_AES_GCM"] = CKM_AES_GCM; | ||
| t["CKM_AES_CCM"] = CKM_AES_CCM; | ||
| t["CKM_AES_KEY_WRAP"] = CKM_AES_KEY_WRAP; | ||
| #ifdef HAVE_AES_KEY_WRAP_PAD | ||
| t["CKM_AES_KEY_WRAP_PAD"] = CKM_AES_KEY_WRAP_PAD; | ||
|
|
@@ -1218,6 +1219,7 @@ CK_RV SoftHSM::C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, CK_ | |
| case CKM_AES_ECB: | ||
| case CKM_AES_CTR: | ||
| case CKM_AES_GCM: | ||
| case CKM_AES_CCM: | ||
| pInfo->ulMinKeySize = 16; | ||
| pInfo->ulMaxKeySize = 32; | ||
| pInfo->flags |= CKF_ENCRYPT | CKF_DECRYPT; | ||
|
|
@@ -2226,6 +2228,7 @@ static bool isSymMechanism(CK_MECHANISM_PTR pMechanism) | |
| case CKM_AES_CBC_PAD: | ||
| case CKM_AES_CTR: | ||
| case CKM_AES_GCM: | ||
| case CKM_AES_CCM: | ||
| return true; | ||
| default: | ||
| return false; | ||
|
|
@@ -2445,6 +2448,34 @@ CK_RV SoftHSM::SymEncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMech | |
| } | ||
| tagBytes = tagBytes / 8; | ||
| break; | ||
| case CKM_AES_CCM: | ||
| if (keyType != CKK_AES) | ||
| return CKR_KEY_TYPE_INCONSISTENT; | ||
| algo = SymAlgo::AES; | ||
| mode = SymMode::CCM; | ||
| if (pMechanism->pParameter == NULL_PTR || | ||
| pMechanism->ulParameterLen != sizeof(CK_CCM_PARAMS)) | ||
| { | ||
| DEBUG_MSG("CCM mode requires parameters"); | ||
| return CKR_ARGUMENTS_BAD; | ||
| } | ||
| if (CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulNonceLen < 7 && CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulNonceLen > 13) { | ||
| DEBUG_MSG("Invalid ulNonceLen value, is %#5d should be 7 ≤ ulNonceLen ≤ 13.", CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulNonceLen); | ||
| return CKR_ARGUMENTS_BAD; | ||
| } | ||
| iv.resize(CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulNonceLen); | ||
| memcpy(&iv[0], CK_CCM_PARAMS_PTR(pMechanism->pParameter)->nonce, CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulNonceLen); | ||
| aad.resize(CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulAADLen); | ||
| if (CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulAADLen > 0) | ||
| memcpy(&aad[0], CK_CCM_PARAMS_PTR(pMechanism->pParameter)->aad, CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulAADLen); | ||
| tagBytes = CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulMACLen; | ||
| counterBits = CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulDataLen; | ||
| if (tagBytes != 16 && tagBytes != 14 && tagBytes != 12 && tagBytes != 10 && tagBytes != 8) | ||
| { | ||
| DEBUG_MSG("Invalid ulMACLen value, is %#5d should be 16, 14, 12, 10 or 8", tagBytes); | ||
| return CKR_ARGUMENTS_BAD; | ||
| } | ||
|
Comment on lines
+2471
to
+2477
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix CCM parameter validation (
File: Suggested fix- if (tagBytes != 16 && tagBytes != 14 && tagBytes != 12 && tagBytes != 10 && tagBytes != 8)
+ if (tagBytes != 16 && tagBytes != 14 && tagBytes != 12 &&
+ tagBytes != 10 && tagBytes != 8 && tagBytes != 6 && tagBytes != 4)
{
DEBUG_MSG("Invalid ulMACLen value, is %#5d should be 16, 14, 12, 10 or 8", tagBytes);
return CKR_ARGUMENTS_BAD;
}
+ size_t L = 15 - CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulNonceLen;
+ if (L < sizeof(CK_ULONG) &&
+ CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulDataLen >= (CK_ULONG(1) << (8 * L)))
+ {
+ return CKR_MECHANISM_PARAM_INVALID;
+ }Update the DEBUG_MSG text to include 4 and 6 as well. 🤖 Prompt for AI Agents |
||
| break; | ||
| default: | ||
| return CKR_MECHANISM_INVALID; | ||
| } | ||
|
|
@@ -3201,6 +3232,34 @@ CK_RV SoftHSM::SymDecryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMech | |
| } | ||
| tagBytes = tagBytes / 8; | ||
| break; | ||
| case CKM_AES_CCM: | ||
| if (keyType != CKK_AES) | ||
| return CKR_KEY_TYPE_INCONSISTENT; | ||
| algo = SymAlgo::AES; | ||
| mode = SymMode::CCM; | ||
| if (pMechanism->pParameter == NULL_PTR || | ||
| pMechanism->ulParameterLen != sizeof(CK_CCM_PARAMS)) | ||
| { | ||
| DEBUG_MSG("CCM mode requires parameters"); | ||
| return CKR_ARGUMENTS_BAD; | ||
| } | ||
| if (CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulNonceLen < 7 && CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulNonceLen > 13) { | ||
| DEBUG_MSG("Invalid ulNonceLen value, is %#5d should be 7 ≤ ulNonceLen ≤ 13.", CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulNonceLen); | ||
| return CKR_ARGUMENTS_BAD; | ||
| } | ||
| iv.resize(CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulNonceLen); | ||
| memcpy(&iv[0], CK_CCM_PARAMS_PTR(pMechanism->pParameter)->nonce, CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulNonceLen); | ||
| aad.resize(CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulAADLen); | ||
| if (CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulAADLen > 0) | ||
| memcpy(&aad[0], CK_CCM_PARAMS_PTR(pMechanism->pParameter)->aad, CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulAADLen); | ||
| tagBytes = CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulMACLen; | ||
| counterBits = CK_CCM_PARAMS_PTR(pMechanism->pParameter)->ulDataLen; | ||
| if (tagBytes != 16 && tagBytes != 14 && tagBytes != 12 && tagBytes != 10 && tagBytes != 8) | ||
| { | ||
| DEBUG_MSG("Invalid ulDataLen value, is %#5d should be 16, 14, 12, 10 or 8", tagBytes); | ||
| return CKR_ARGUMENTS_BAD; | ||
| } | ||
| break; | ||
| default: | ||
| return CKR_MECHANISM_INVALID; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: softhsm/SoftHSMv2
Length of output: 104
🏁 Script executed:
Repository: softhsm/SoftHSMv2
Length of output: 164
🏁 Script executed:
Repository: softhsm/SoftHSMv2
Length of output: 2744
Align
--with-opensslpath withopenssl@3.6brew install openssl@3.6but./configureuses--with-openssl=/usr/local/opt/openssl(lines 91-92, 101-102); update to the versioned OpenSSL path (e.g.,/usr/local/opt/openssl@3.6, or whatever Homebrew symlink targets) to ensure the build links against the intended OpenSSL 3.6+.#22773” needs clearer context (repo/URL) for readers (lines 51-52).🧰 Tools
🪛 markdownlint-cli2 (0.22.1)
[warning] 46-46: Dollar signs used before commands without showing output
(MD014, commands-show-output)
🤖 Prompt for AI Agents