summaryrefslogtreecommitdiffstats
path: root/trusty
diff options
context:
space:
mode:
authorJocelyn Bohr <bohr@google.com>2017-02-09 17:42:15 -0800
committerJocelyn Bohr <bohr@google.com>2017-04-10 17:33:49 -0700
commit86eb9661068204221f56881ceb5e7afba3199010 (patch)
tree32043be800b2204fee3dc43195265aa402965c2c /trusty
parentd7da42c0fa19114da51fc0d80c74b3d522687b9a (diff)
downloadcore-86eb9661068204221f56881ceb5e7afba3199010.tar.gz
core-86eb9661068204221f56881ceb5e7afba3199010.tar.bz2
core-86eb9661068204221f56881ceb5e7afba3199010.zip
trusty: keymaster: Implement update
Test: builds Change-Id: Ie411a4e7ae3b5242814777f2781e1d2508917bfa
Diffstat (limited to 'trusty')
-rw-r--r--trusty/keymaster/trusty_keymaster_device.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/trusty/keymaster/trusty_keymaster_device.cpp b/trusty/keymaster/trusty_keymaster_device.cpp
index 6be07190f..bc390d7bc 100644
--- a/trusty/keymaster/trusty_keymaster_device.cpp
+++ b/trusty/keymaster/trusty_keymaster_device.cpp
@@ -508,6 +508,58 @@ keymaster_error_t TrustyKeymasterDevice::update(keymaster_operation_handle_t ope
keymaster_key_param_set_t* out_params,
keymaster_blob_t* output) {
ALOGD("Device received update");
+
+ if (error_ != KM_ERROR_OK) {
+ return error_;
+ }
+ if (!input) {
+ return KM_ERROR_UNEXPECTED_NULL_POINTER;
+ }
+ if (!input_consumed) {
+ return KM_ERROR_OUTPUT_PARAMETER_NULL;
+ }
+
+ if (out_params) {
+ *out_params = {};
+ }
+ if (output) {
+ *output = {};
+ }
+
+ UpdateOperationRequest request;
+ request.op_handle = operation_handle;
+ if (in_params) {
+ request.additional_params.Reinitialize(*in_params);
+ }
+ if (input && input->data_length > 0) {
+ size_t max_input_size = SEND_BUF_SIZE - request.SerializedSize();
+ request.input.Reinitialize(input->data, std::min(input->data_length, max_input_size));
+ }
+
+ UpdateOperationResponse response;
+ keymaster_error_t err = Send(KM_UPDATE_OPERATION, request, &response);
+ if (err != KM_ERROR_OK) {
+ return err;
+ }
+
+ if (response.output_params.size() > 0) {
+ if (out_params) {
+ response.output_params.CopyToParamSet(out_params);
+ } else {
+ return KM_ERROR_OUTPUT_PARAMETER_NULL;
+ }
+ }
+ *input_consumed = response.input_consumed;
+ if (output) {
+ output->data_length = response.output.available_read();
+ output->data = DuplicateBuffer(response.output.peek_read(), output->data_length);
+ if (!output->data) {
+ return KM_ERROR_MEMORY_ALLOCATION_FAILED;
+ }
+ } else if (response.output.available_read() > 0) {
+ return KM_ERROR_OUTPUT_PARAMETER_NULL;
+ }
+
return KM_ERROR_OK;
}