if (secret_info.dataSize > 0) { // data
out_len = secret_info.dataSize;
} else {
- out_len = secret_info.objectSize;
+ out_len = KM_MaxObjectSizeBytes(&secret_info);
}
output.data = malloc(out_len);
goto clean;
}
- // Fow now, only symmetric key can be wrapped.
- if (with_ktw_pwd)
- ret = KM_DecryptKey(ktw_id.data, ktw_id.data_size, &ktw_pwd_data, &ktw_key);
- else
- ret = KM_OpenKey(ktw_id.data, ktw_id.data_size, &ktw_key);
- if (ret != TEE_SUCCESS) {
- LOG("Error in KM_OpenKey()");
- goto clean;
- }
-
- ret = KM_GetBufferAttribute(ktw_key, TEE_ATTR_SECRET_VALUE, &ktw_data);
+ ret = KM_GetSecretValue(&ktw_id, &ktw_data, with_ktw_pwd, &ktw_pwd_data);
if (TEE_SUCCESS != ret) {
LOG("Failed to get TEE_ATTR_SECRET_VALUE from key to wrap.");
goto clean;
TEE_GetObjectInfo(key, &info);
- outSize = KM_ObjectSizeBytes(&info);
+ outSize = KM_MaxObjectSizeBytes(&info);
if (param[0].value.a == ALGO_ECDSA_SV)
outSize *= 2;
}
TEE_GetObjectInfo(keyHndl, &objInfo);
- keyBufSize = KM_ObjectSizeBytes(&objInfo);
- if (keyBufSize == 0) {
- LOG("Key provided for encryption is not initialized");
- return TEE_ERROR_BAD_PARAMETERS;
+ ret = TEE_GetObjectBufferAttribute(keyHndl, TEE_ATTR_SECRET_VALUE, NULL, &keyBufSize);
+ if (ret != TEE_ERROR_SHORT_BUFFER || keyBufSize == 0) {
+ LOG("Failed to acquire attribute size from object: ret=%x, keyBufSize=%d", ret, keyBufSize);
+ return TEE_ERROR_GENERIC;
}
if (tag == NULL) {
{
TEE_ObjectInfo objInfo;
TEE_Result ret;
- uint32_t objSize;
+ uint32_t attrSize;
if (attr == NULL) {
LOG("Attribute buffer is NULL");
return TEE_ERROR_BAD_PARAMETERS;
}
- /*
- * TODO current key size is used as maximum attribute size because prompting the size with NULL
- * buffer in TEE_GetObjectBufferAttribute doesn't work in simulator.
- */
TEE_GetObjectInfo(keyHndl, &objInfo);
- objSize = KM_ObjectSizeBytes(&objInfo);
- if (((objInfo.handleFlags & TEE_HANDLE_FLAG_INITIALIZED) == 0) || (objSize == 0)) {
- LOG("Key provided for KM_GetBufferAttribute is not initialized or objSize is zero. objSize=%d, objSizeInBits=%d", objSize, objInfo.objectSize);
+
+ ret = TEE_GetObjectBufferAttribute(keyHndl, attrId, NULL, &attrSize);
+ if (ret != TEE_ERROR_SHORT_BUFFER || attrSize == 0) {
+ LOG("Failed to acquire attribute size from object: ret=%x, attrSize=%d", ret, attrSize);
+ return TEE_ERROR_GENERIC;
+ }
+
+ if ((objInfo.handleFlags & TEE_HANDLE_FLAG_INITIALIZED) == 0) {
+ LOG("Key provided for KM_GetBufferAttribute is not initialized or objSize is zero.");
return TEE_ERROR_BAD_PARAMETERS;
}
- attr->data_size = objSize;
+ attr->data_size = attrSize;
attr->data = malloc(attr->data_size);
if (attr->data == NULL) {
LOG("Failed to allocate memory for key attribute.");
TEE_GetObjectInfo(objHandle, &objInfo);
- keyBufSize = KM_ObjectSizeBytes(&objInfo);
- if (keyBufSize == 0) {
- LOG("Key provided for encryption is not initialized");
- ret = TEE_ERROR_BAD_PARAMETERS;
- goto out;
+ ret = TEE_GetObjectBufferAttribute(objHandle, TEE_ATTR_SECRET_VALUE, NULL, &keyBufSize);
+ if (ret != TEE_ERROR_SHORT_BUFFER || keyBufSize == 0) {
+ LOG("Failed to acquire attribute size from object: ret=%x, keyBufSize=%d", ret, keyBufSize);
+ return TEE_ERROR_GENERIC;
}
keyBuf = malloc(keyBufSize);