Hi, I found this blog article and wanted to try the same. I exracted the tegra_crypto_opt
function from the trusty-sample:
int tegra_crypto_op(unsigned char *in, unsigned char *out, int len,
unsigned char *iv, int iv_len, int encrypt,
unsigned int crypto_op_mode, bool close)
{
struct tegra_crypt_req crypt_req;
int rc = 0;
if (fd == -1)
fd = open("/dev/tegra-crypto", O_RDWR);
if (fd < 0) {
LOG("%s: /dev/tegra-crypto open fail\n", __func__);
return -1;
}
crypt_req.skip_exit = !close;
crypt_req.op = crypto_op_mode;
crypt_req.encrypt = encrypt;
memset(crypt_req.key, 0, AES_KEYSIZE_128);
crypt_req.keylen = AES_KEYSIZE_128;
memcpy(crypt_req.iv, iv, iv_len);
crypt_req.ivlen = iv_len;
crypt_req.plaintext = in;
crypt_req.plaintext_sz = len;
crypt_req.result = out;
crypt_req.skip_key = 0;
crypt_req.skip_iv = 0;
rc = ioctl(fd, TEGRA_CRYPTO_IOCTL_NEED_SSK, 1);
if (rc < 0) {
LOG("tegra_crypto ioctl error: TEGRA_CRYPTO_IOCTL_NEED_SSK\n");
goto err;
}
rc = ioctl(fd, TEGRA_CRYPTO_IOCTL_PROCESS_REQ, &crypt_req);
if (rc < 0) {
LOG("tegra_crypto ioctl error: TEGRA_CRYPTO_IOCTL_PROCESS_REQ\n");
goto err;
}
if (close)
tegra_crypto_op_close();
err:
return rc;
}
Then I tried to call it the following way:
unsigned char in[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
unsigned char out[8] = {0};
unsigned char iv[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
int len = 8;
int iv_len = 16;
auto rc = tegra_crypto_op(in, out, len, iv, iv_len, TEGRA_CRYPTO_ENCRYPT, TEGRA_CRYPTO_CBC, true);
if (rc != 0) {
std::cout << "tegra_crypto_op failed: " << rc << std::endl;
return 1;
};
Unfortunately, I get an ioctl error:
tegra_crypto ioctl error: TEGRA_CRYPTO_IOCTL_PROCESS_REQ
tegra_crypto_op failed: -1
dmesg
gives the following output:
[ 2639.956217] tegra-se 70012000.se: tegra_se_irq::error status is 4
[ 2639.962306] tegra-se 70012000.se: tegra_se_irq::error status is 4
[ 2640.968117] tegra-se 70012000.se: operation timed out no interrupt
[ 2640.974365] encrypt failed (-110)
Any idea what’s wrong here? Thanks!