Skip to content

Commit eb36a02

Browse files
authored
Merge pull request #123 from LinuxJedi/object_heap
Fixes to reduce the size of heap use for PKCS11 objects.
2 parents 2315bfb + fc36b94 commit eb36a02

File tree

3 files changed

+437
-227
lines changed

3 files changed

+437
-227
lines changed

src/crypto.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,13 @@ static CK_RV NewObject(WP11_Session* session, CK_KEY_TYPE keyType,
702702
if (ret != 0)
703703
return CKR_FUNCTION_FAILED;
704704

705+
/* Now that object class is set, allocate type-specific data */
706+
ret = wp11_Object_AllocateTypeData(obj);
707+
if (ret == MEMORY_E)
708+
return CKR_DEVICE_MEMORY;
709+
if (ret != 0)
710+
return CKR_FUNCTION_FAILED;
711+
705712
rv = SetAttributeValue(session, obj, pTemplate, ulCount, CK_TRUE);
706713
if (rv != CKR_OK) {
707714
WP11_Object_Free(obj);
@@ -1141,6 +1148,18 @@ CK_RV C_CopyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject,
11411148
if (ret != 0)
11421149
return CKR_FUNCTION_FAILED;
11431150

1151+
/* Set the object class from the original object */
1152+
ret = WP11_Object_SetClass(newObj, WP11_Object_GetClass(obj));
1153+
if (ret != 0)
1154+
return CKR_FUNCTION_FAILED;
1155+
1156+
/* Now that object class is set, allocate type-specific data */
1157+
ret = wp11_Object_AllocateTypeData(newObj);
1158+
if (ret == MEMORY_E)
1159+
return CKR_DEVICE_MEMORY;
1160+
if (ret != 0)
1161+
return CKR_FUNCTION_FAILED;
1162+
11441163
/* Use get and set attribute value to fill in object. */
11451164
rv = C_GetAttributeValue(hSession, hObject, pTemplate, ulCount);
11461165
if (rv != CKR_OK) {

0 commit comments

Comments
 (0)