CK_RV dp_dh_set_default_attributes( TEMPLATE *tmpl, CK_ULONG mode ) { CK_RV rc; CK_ATTRIBUTE *prime_attr; CK_ATTRIBUTE *base_attr; CK_ATTRIBUTE *primebits_attr; CK_ATTRIBUTE *type_attr; rc = dp_object_set_default_attributes( tmpl, mode ); if (rc != CKR_OK) return rc; prime_attr = (CK_ATTRIBUTE *)malloc( sizeof(CK_ATTRIBUTE) ); base_attr = (CK_ATTRIBUTE *)malloc( sizeof(CK_ATTRIBUTE) ); primebits_attr = (CK_ATTRIBUTE *)malloc( sizeof(CK_ATTRIBUTE) ); type_attr = (CK_ATTRIBUTE *)malloc( sizeof(CK_ATTRIBUTE) + sizeof(CK_KEY_TYPE) ); if (!prime_attr || !base_attr || !primebits_attr || !type_attr) { if (prime_attr) free( prime_attr ); if (base_attr) free( base_attr ); if (primebits_attr) free( primebits_attr ); if (type_attr) free( type_attr ); TRACE_ERROR("%s\n", ock_err(ERR_HOST_MEMORY)); return CKR_HOST_MEMORY; } prime_attr->type = CKA_PRIME; prime_attr->ulValueLen = 0; prime_attr->pValue = NULL; base_attr->type = CKA_BASE; base_attr->ulValueLen = 0; base_attr->pValue = NULL; primebits_attr->type = CKA_PRIME_BITS; primebits_attr->ulValueLen = 0; primebits_attr->pValue = NULL; type_attr->type = CKA_KEY_TYPE; type_attr->ulValueLen = sizeof(CK_KEY_TYPE); type_attr->pValue = (CK_BYTE *)type_attr + sizeof(CK_ATTRIBUTE); *(CK_KEY_TYPE *)type_attr->pValue = CKK_DH; template_update_attribute( tmpl, prime_attr ); template_update_attribute( tmpl, base_attr ); template_update_attribute( tmpl, primebits_attr ); template_update_attribute( tmpl, type_attr ); return CKR_OK; }
CK_RV clock_set_default_attributes( TEMPLATE *tmpl, CK_ULONG mode ) { CK_RV rc; CK_ATTRIBUTE *value_attr; rc = hwf_object_set_default_attributes( tmpl, mode ); if (rc != CKR_OK) return rc; value_attr = (CK_ATTRIBUTE *)malloc( sizeof(CK_ATTRIBUTE) ); if (!value_attr) { OCK_LOG_ERR(ERR_HOST_MEMORY); return CKR_HOST_MEMORY; } value_attr->type = CKA_VALUE; value_attr->ulValueLen = 0; value_attr->pValue = NULL; template_update_attribute( tmpl, value_attr ); return CKR_OK; }
CK_RV counter_set_default_attributes( TEMPLATE *tmpl, CK_ULONG mode ) { CK_RV rc; CK_ATTRIBUTE *value_attr; CK_ATTRIBUTE *hasreset_attr; CK_ATTRIBUTE *resetoninit_attr; rc = hwf_object_set_default_attributes( tmpl, mode ); if (rc != CKR_OK) return rc; value_attr = (CK_ATTRIBUTE *)malloc( sizeof(CK_ATTRIBUTE) ); hasreset_attr = (CK_ATTRIBUTE *)malloc( sizeof(CK_ATTRIBUTE) + sizeof(CK_BBOOL)); resetoninit_attr = (CK_ATTRIBUTE *)malloc( sizeof(CK_ATTRIBUTE) + sizeof(CK_BBOOL)); if (!value_attr || !hasreset_attr || !resetoninit_attr) { if (value_attr) free( value_attr ); if (hasreset_attr) free( hasreset_attr ); if (resetoninit_attr) free( resetoninit_attr ); OCK_LOG_ERR(ERR_HOST_MEMORY); return CKR_HOST_MEMORY; } value_attr->type = CKA_VALUE; value_attr->ulValueLen = 0; value_attr->pValue = NULL; hasreset_attr->type = CKA_HAS_RESET; hasreset_attr->ulValueLen = sizeof(CK_BBOOL); hasreset_attr->pValue = (CK_BYTE *)hasreset_attr + sizeof(CK_ATTRIBUTE); *(CK_BBOOL *)hasreset_attr->pValue = FALSE; /* Hmm... Not sure if we should be setting this here. */ resetoninit_attr->type = CKA_RESET_ON_INIT; resetoninit_attr->ulValueLen = sizeof(CK_BBOOL); resetoninit_attr->pValue = (CK_BYTE *)resetoninit_attr + sizeof(CK_ATTRIBUTE); *(CK_BBOOL *)resetoninit_attr->pValue = FALSE; template_update_attribute( tmpl, value_attr ); template_update_attribute( tmpl, hasreset_attr ); template_update_attribute( tmpl, resetoninit_attr ); return CKR_OK; }
CK_RV counter_set_default_attributes(TEMPLATE *tmpl) { CK_ATTRIBUTE *value_attr; CK_ATTRIBUTE *hasreset_attr; CK_ATTRIBUTE *resetoninit_attr; value_attr = (CK_ATTRIBUTE *)malloc(sizeof (CK_ATTRIBUTE)); hasreset_attr = (CK_ATTRIBUTE *)malloc(sizeof (CK_ATTRIBUTE) + sizeof (CK_BBOOL)); resetoninit_attr = (CK_ATTRIBUTE *)malloc(sizeof (CK_ATTRIBUTE) + sizeof (CK_BBOOL)); if (! value_attr || ! hasreset_attr || ! resetoninit_attr) { if (value_attr) free(value_attr); if (hasreset_attr) free(hasreset_attr); if (resetoninit_attr) free(resetoninit_attr); return (CKR_HOST_MEMORY); } value_attr->type = CKA_VALUE; value_attr->ulValueLen = 0; value_attr->pValue = NULL; hasreset_attr->type = CKA_HAS_RESET; hasreset_attr->ulValueLen = sizeof (CK_BBOOL); hasreset_attr->pValue = (CK_BYTE *)hasreset_attr + sizeof (CK_ATTRIBUTE); *(CK_BBOOL *)hasreset_attr->pValue = FALSE; /* Hmm... Not sure if we should be setting this here. */ resetoninit_attr->type = CKA_RESET_ON_INIT; resetoninit_attr->ulValueLen = sizeof (CK_BBOOL); resetoninit_attr->pValue = (CK_BYTE *)resetoninit_attr + sizeof (CK_ATTRIBUTE); *(CK_BBOOL *)resetoninit_attr->pValue = FALSE; (void) template_update_attribute(tmpl, value_attr); (void) template_update_attribute(tmpl, hasreset_attr); (void) template_update_attribute(tmpl, resetoninit_attr); return (CKR_OK); }
/* * data_object_set_default_attributes() * * Set the default attributes for data objects: * * CKA_APPLICATION : empty string * CKA_VALUE : empty byte array */ CK_RV data_object_set_default_attributes(TEMPLATE *tmpl, CK_ULONG mode) { CK_ATTRIBUTE *class_attr = NULL; CK_ATTRIBUTE *app_attr = NULL; CK_ATTRIBUTE *value_attr = NULL; if (mode) app_attr = NULL; class_attr = (CK_ATTRIBUTE *)malloc(sizeof (CK_ATTRIBUTE) + sizeof (CK_OBJECT_CLASS)); app_attr = (CK_ATTRIBUTE *)malloc(sizeof (CK_ATTRIBUTE)); value_attr = (CK_ATTRIBUTE *)malloc(sizeof (CK_ATTRIBUTE)); if (! class_attr || ! app_attr || ! value_attr) { if (class_attr) free(class_attr); if (app_attr) free(app_attr); if (value_attr) free(value_attr); return (CKR_HOST_MEMORY); } app_attr->type = CKA_APPLICATION; app_attr->ulValueLen = 0; // empty string app_attr->pValue = NULL; value_attr->type = CKA_VALUE; value_attr->ulValueLen = 0; // empty byte array value_attr->pValue = NULL; class_attr->type = CKA_CLASS; class_attr->ulValueLen = sizeof (CK_OBJECT_CLASS); class_attr->pValue = (CK_BYTE *)class_attr + sizeof (CK_ATTRIBUTE); *(CK_OBJECT_CLASS *)class_attr->pValue = CKO_DATA; (void) template_update_attribute(tmpl, class_attr); (void) template_update_attribute(tmpl, app_attr); (void) template_update_attribute(tmpl, value_attr); return (CKR_OK); }
CK_RV clock_set_default_attributes(TEMPLATE *tmpl) { CK_ATTRIBUTE *value_attr; value_attr = (CK_ATTRIBUTE *)malloc(sizeof (CK_ATTRIBUTE)); if (! value_attr) { return (CKR_HOST_MEMORY); } value_attr->type = CKA_VALUE; value_attr->ulValueLen = 0; value_attr->pValue = NULL; (void) template_update_attribute(tmpl, value_attr); return (CKR_OK); }
// dp_object_set_default_attributes() // CK_RV dp_object_set_default_attributes( TEMPLATE *tmpl, CK_ULONG mode ) { CK_ATTRIBUTE * local_attr = NULL; local_attr = (CK_ATTRIBUTE *)malloc( sizeof(CK_ATTRIBUTE) + sizeof(CK_BBOOL) ); if (!local_attr) { TRACE_ERROR("%s\n", ock_err(ERR_HOST_MEMORY)); return CKR_HOST_MEMORY; } local_attr->type = CKA_LOCAL; local_attr->ulValueLen = sizeof(CK_BBOOL); local_attr->pValue = (CK_BYTE *)local_attr + sizeof(CK_ATTRIBUTE); *(CK_BBOOL *)local_attr->pValue = FALSE; template_update_attribute( tmpl, local_attr ); return CKR_OK; }
// hwf_object_set_default_attributes() // CK_RV hwf_object_set_default_attributes( TEMPLATE *tmpl, CK_ULONG mode ) { #if 0 CK_ATTRIBUTE * local_attr = NULL; local_attr = (CK_ATTRIBUTE *)malloc( sizeof(CK_ATTRIBUTE) + sizeof(CK_BBOOL) ); if (!local_attr) { OCK_LOG_ERR(ERR_HOST_MEMORY); return CKR_HOST_MEMORY; } local_attr->type = CKA_LOCAL; local_attr->ulValueLen = sizeof(CK_BBOOL); local_attr->pValue = (CK_BYTE *)local_attr + sizeof(CK_ATTRIBUTE); *(CK_BBOOL *)local_attr->pValue = FALSE; template_update_attribute( tmpl, local_attr ); #endif return CKR_OK; }
/* template_add_attributes() * * blindly add the given attributes to the template. do no sanity checking * at this point. sanity checking will occur later. */ CK_RV template_add_attributes(TEMPLATE *tmpl, CK_ATTRIBUTE *pTemplate, CK_ULONG ulCount) { CK_ATTRIBUTE *attr = NULL; CK_RV rc; unsigned int i; for (i = 0; i < ulCount; i++) { if (!is_attribute_defined(pTemplate[i].type)) { TRACE_ERROR("%s\n", ock_err(ERR_ATTRIBUTE_TYPE_INVALID)); return CKR_ATTRIBUTE_TYPE_INVALID; } attr = (CK_ATTRIBUTE *)malloc(sizeof(CK_ATTRIBUTE) + pTemplate[i].ulValueLen); if (!attr) { TRACE_ERROR("%s\n", ock_err(ERR_HOST_MEMORY)); return CKR_HOST_MEMORY; } attr->type = pTemplate[i].type; attr->ulValueLen = pTemplate[i].ulValueLen; if (attr->ulValueLen != 0) { attr->pValue = (CK_BYTE *)attr + sizeof(CK_ATTRIBUTE); memcpy(attr->pValue, pTemplate[i].pValue, attr->ulValueLen); } else attr->pValue = NULL; rc = template_update_attribute(tmpl, attr); if (rc != CKR_OK) { free(attr); TRACE_DEVEL("template_update_attribute failed.\n"); return rc; } } return CKR_OK; }