This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] AM62A7:加密和解密演示(tisci API)

Guru**** 2482105 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1455962/am62a7-encryption-and-decryption-demo-tisci-api

器件型号:AM62A7

工具与软件:

您好、ti

我使用 tisci API 接口编写了一个加密的演示、

但用于确定应如何调整某些参数的信息太少。

您能否提供演示?

int ti_sci_read_otp_mmr(uint8_t mmr_idx, uint32_t *val)
{
	struct ti_sci_msg_req_read_otp_mmr req = { };
	struct ti_sci_msg_resp_read_otp_mmr resp = { };
	struct ti_sci_xfer xfer = { };
	int ret = 0;

//----------------------encryption test  ------------
#if 1					
	struct csp_aes_ctx_v0 {
		uint8_t     mode;
		uint8_t     key_size;
		uint8_t     ctr_width;
		uint8_t     resv0;
		uint64_t    data_len;
		uint64_t    dest_addr;	//store data?????
		uint32_t    key[8];
		uint32_t    iv[4];
		uint32_t    tag[4];
	}__packed;
	struct csp_aes_opn_req_data {
    uint32_t ctx_address_lo;
    uint32_t ctx_address_hi;
	}__packed;

	struct csp_aes_opn_resp_data {
		uint8_t tag[16];		//????
	}__packed;
	#define AES_ECB		(0x1) 	//????
	#define AES_CBC		(0x2)	//????
	#define AES_GCM		(0x3)	//????
	#define TISCI_MSG_SA2UL_AES_ENCRYPT 0x9040	
	#define TISCI_MSG_SA2UL_AES_DECRYPT 0x9041	
	struct csp_aes_opn_req_data req2 = {};
	struct csp_aes_opn_resp_data resp2 = {};
	struct ti_sci_xfer xfer2 = { };
	char data[16] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
	struct csp_aes_ctx_v0 ctx1 = {
		.mode = AES_CBC,
		.key_size = 128,
		.data_len = sizeof(data),
		.dest_addr = (uint64_t)data,
		.key[0]	= 0x12,
		.key[1]	= 0x34,
		.key[2]	= 0x56,
		.key[3]	= 0x78,


	};
	ret = ti_sci_setup_xfer(TISCI_MSG_SA2UL_AES_ENCRYPT, 0,
				&req2, sizeof(req2), &resp2, sizeof(resp2), &xfer2);
	if (ret)
		goto exit;

	req2.ctx_address_lo = ( (uint64_t)(&ctx1) ) & 0xffffffff;
	req2.ctx_address_hi = ( ( (uint64_t)(&ctx1 ) ) >>32 ) & 0xffffffff;

	ret = ti_sci_do_xfer(&xfer2);
	if (ret)
		goto exit;

	EMSG("encrpto:%02x %02x %02x %02x\n", resp2.tag[0],resp2.tag[1],resp2.tag[2],resp2.tag[3] );
#endif

	ret = ti_sci_setup_xfer(TI_SCI_MSG_READ_OTP_MMR, 0,
				&req, sizeof(req), &resp, sizeof(resp), &xfer);
	if (ret)
		goto exit;

	req.mmr_idx = mmr_idx;

	ret = ti_sci_do_xfer(&xfer);
	if (ret)
		goto exit;

	*val = resp.mmr_val;

exit:
	memzero_explicit(&resp, sizeof(resp));
	return ret;
}