📄 hwf_obj.c
字号:
distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. *//* (C) COPYRIGHT International Business Machines Corp. 2001,2002 */// File: hwf_obj.c//// Hardware Feature Object functions#include <pthread.h>#include <stdlib.h>#include <string.h> // for memcmp() et al#include "pkcs11types.h"#include "defs.h"#include "host_defs.h"#include "h_extern.h"#include "tok_spec_struct.h"// hwf_object_check_required_attributes()//// Check required common attributes for hardware feature objects//CK_RVhwf_object_check_required_attributes( TEMPLATE *tmpl, CK_ULONG mode ){ CK_ATTRIBUTE * attr = NULL; CK_BBOOL found; found = template_attribute_find( tmpl, CKA_HW_FEATURE_TYPE, &attr ); if (!found) { if (mode == MODE_CREATE){ st_err_log(48, __FILE__, __LINE__); return CKR_TEMPLATE_INCOMPLETE; } } return template_check_required_base_attributes( tmpl, mode );}CK_RVclock_check_required_attributes( TEMPLATE *tmpl, CK_ULONG mode ){ CK_ATTRIBUTE *attr = NULL; CK_BBOOL found; if (mode == MODE_CREATE){ found = template_attribute_find( tmpl, CKA_VALUE, &attr ); if (!found) { st_err_log(48, __FILE__, __LINE__); return CKR_TEMPLATE_INCOMPLETE; } } return hwf_object_check_required_attributes( tmpl, mode );}CK_RVcounter_check_required_attributes( TEMPLATE *tmpl, CK_ULONG mode ){ CK_ATTRIBUTE *attr = NULL; CK_BBOOL found; if (mode == MODE_CREATE){ found = template_attribute_find( tmpl, CKA_VALUE, &attr ); if (!found) { st_err_log(48, __FILE__, __LINE__); return CKR_TEMPLATE_INCOMPLETE; } found = template_attribute_find( tmpl, CKA_HAS_RESET, &attr ); if (!found) { st_err_log(48, __FILE__, __LINE__); return CKR_TEMPLATE_INCOMPLETE; } found = template_attribute_find( tmpl, CKA_RESET_ON_INIT, &attr ); if (!found) { st_err_log(48, __FILE__, __LINE__); return CKR_TEMPLATE_INCOMPLETE; } } return hwf_object_check_required_attributes( tmpl, mode );}// hwf_object_set_default_attributes()//CK_RVhwf_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) { st_err_log(1, __FILE__, __LINE__); 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;}// hwf_object_validate_attribute()//CK_RVhwf_validate_attribute( TEMPLATE *tmpl, CK_ATTRIBUTE *attr, CK_ULONG mode){ switch (attr->type) { case CKA_HW_FEATURE_TYPE: if (mode == MODE_CREATE) return CKR_OK; else{ st_err_log(7, __FILE__, __LINE__); return CKR_ATTRIBUTE_READ_ONLY; } default: return template_validate_base_attribute( tmpl, attr, mode ); } st_err_log(8, __FILE__, __LINE__); return CKR_ATTRIBUTE_TYPE_INVALID;}////CK_RVclock_validate_attribute( TEMPLATE *tmpl, CK_ATTRIBUTE *attr, CK_ULONG mode){ switch (attr->type) { case CKA_VALUE: return CKR_OK; default: return hwf_validate_attribute( tmpl, attr, mode ); }}////CK_RVcounter_validate_attribute( TEMPLATE *tmpl, CK_ATTRIBUTE *attr, CK_ULONG mode){ switch (attr->type) { case CKA_VALUE: /* Fall Through */ case CKA_HAS_RESET: /* Fall Through */ case CKA_RESET_ON_INIT: st_err_log(7, __FILE__, __LINE__); return CKR_ATTRIBUTE_READ_ONLY; default: return hwf_validate_attribute( tmpl, attr, mode ); }}CK_RVclock_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) { st_err_log(1, __FILE__, __LINE__); 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_RVcounter_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 ); st_err_log(1, __FILE__, __LINE__); 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;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -