Ejemplo n.º 1
0
TEE_Result crypt_cipher_interface(TEE_OperationHandle operation, 
								const void *message, size_t message_len, 
								void *cipher, size_t *cipher_len,
								const void *IV, size_t IVLen) 
{
	TEE_Result res = TEE_ERROR_GENERIC;
	void * src = (void *)message;
	void * dst = (void *)cipher;
	size_t process_len = message_len;
	size_t block_size = operation->block_size;
	TEE_Printf("[info] operation->block_size = 0x%x\n", block_size);

	TEE_CipherInit(operation, IV, IVLen);


	if( process_len < block_size) {
		return res;
	}

	switch(0) {

		case 0:
			res = TEE_CipherDoFinal(operation, src, process_len, dst, &process_len);		// dst_len >= sum(src_len)
			if (res != TEE_SUCCESS) {
				TEE_Printf("[err] TEE_CipherDoFinal\n");
				return res;
			}
			*cipher_len =  process_len;

			break;

		case 1: // using TEE_CipherUpdate
		default: 
			process_len -= block_size;
			res = TEE_CipherUpdate(operation, src, process_len, dst, &process_len);
			if (res != TEE_SUCCESS) {
				TEE_Printf("[err] TEE_CipherDoFinal\n");
				return res;
			}
			// last block
			res = TEE_CipherDoFinal(operation, src+process_len, block_size, dst+process_len, &block_size);		// dst_len >= sum(src_len)
			if (res != TEE_SUCCESS) {
				TEE_Printf("[err] TEE_CipherDoFinal\n");
				return res;
			}
			*cipher_len =  process_len + block_size;		
	}

	return res;
}
Ejemplo n.º 2
0
TEE_Result ta_entry_cipher_init(uint32_t param_type, TEE_Param params[4])
{
	void *buffer;
	size_t size;

	if (param_type == TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT,
					  TEE_PARAM_TYPE_NONE,
					  TEE_PARAM_TYPE_NONE,
					  TEE_PARAM_TYPE_NONE)) {
		buffer = NULL;
		size = 0;
	} else if (param_type == TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT,
						 TEE_PARAM_TYPE_MEMREF_INPUT,
						 TEE_PARAM_TYPE_NONE,
						 TEE_PARAM_TYPE_NONE)) {
		buffer = params[1].memref.buffer;
		size = params[1].memref.size;
	} else
		return TEE_ERROR_BAD_PARAMETERS;
	TEE_CipherInit((TEE_OperationHandle) params[0].value.a, buffer, size);
	return TEE_SUCCESS;
}