static TEE_Result read_rb_idx(uint32_t pt, TEE_Param params[TEE_NUM_PARAMS]) { const uint32_t exp_pt = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_VALUE_OUTPUT, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE); size_t slot_offset; uint64_t idx; uint32_t count; TEE_Result res; TEE_ObjectHandle h; if (pt != exp_pt) return TEE_ERROR_BAD_PARAMETERS; res = get_slot_offset(params[0].value.a, &slot_offset); if (res) return res; res = open_rb_state(DEFAULT_LOCK_STATE, &h); if (res) return res; res = TEE_SeekObjectData(h, slot_offset, TEE_DATA_SEEK_SET); if (res) goto out; res = TEE_ReadObjectData(h, &idx, sizeof(idx), &count); if (res) goto out; if (count != sizeof(idx)) { idx = 0; /* Not yet written slots are reported as 0 */ if (count) { /* * Somehow the file didn't even hold a complete * slot index entry. Write it as 0. */ res = TEE_SeekObjectData(h, slot_offset, TEE_DATA_SEEK_SET); if (res) goto out; res = TEE_WriteObjectData(h, &idx, sizeof(idx)); if (res) goto out; } } params[1].value.a = idx >> 32; params[1].value.b = idx; out: TEE_CloseObject(h); return res; }
static TEE_Result write_rb_idx(uint32_t pt, TEE_Param params[TEE_NUM_PARAMS]) { const uint32_t exp_pt = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_VALUE_INPUT, TEE_PARAM_TYPE_NONE, TEE_PARAM_TYPE_NONE); size_t slot_offset; uint64_t widx; uint64_t idx; uint32_t count; TEE_Result res; TEE_ObjectHandle h; if (pt != exp_pt) return TEE_ERROR_BAD_PARAMETERS; res = get_slot_offset(params[0].value.a, &slot_offset); if (res) return res; widx = ((uint64_t)params[1].value.a << 32) | params[1].value.b; res = open_rb_state(DEFAULT_LOCK_STATE, &h); if (res) return res; res = TEE_SeekObjectData(h, slot_offset, TEE_DATA_SEEK_SET); if (res) goto out; res = TEE_ReadObjectData(h, &idx, sizeof(idx), &count); if (res) goto out; if (count != sizeof(idx)) idx = 0; /* Not yet written slots are reported as 0 */ if (widx < idx) { res = TEE_ERROR_SECURITY; goto out; } res = TEE_SeekObjectData(h, slot_offset, TEE_DATA_SEEK_SET); if (res) goto out; res = TEE_WriteObjectData(h, &widx, sizeof(widx)); out: TEE_CloseObject(h); return res; }
static unsigned int radix_tree_descend(struct radix_tree_node *parent, struct radix_tree_node **nodep, unsigned long index) { unsigned int offset = (index >> parent->shift) & RADIX_TREE_MAP_MASK; void **entry = rcu_dereference_raw(parent->slots[offset]); #ifdef CONFIG_RADIX_TREE_MULTIORDER if (radix_tree_is_internal_node(entry)) { unsigned long siboff = get_slot_offset(parent, entry); if (siboff < RADIX_TREE_MAP_SIZE) { offset = siboff; entry = rcu_dereference_raw(parent->slots[offset]); } } #endif *nodep = (void *)entry; return offset; }
uint32_t get_TOTP_slot_offset(int slot_count){ return SLOTS_PAGE1_ADDRESS + get_slot_offset(slot_count + NUMBER_OF_HOTP_SLOTS); }
uint32_t get_HOTP_slot_offset(int slot_count){ return SLOTS_PAGE1_ADDRESS + get_slot_offset(slot_count); }