Skip to content

Commit ac6d825

Browse files
Hisping LinJosephChen2017
authored andcommitted
lib: optee_clientApi: add support for esck key
Change-Id: Ibee79c0860f4c80b080a2cc50c35624d58cb1d37 Signed-off-by: Hisping Lin <[email protected]>
1 parent b285809 commit ac6d825

File tree

2 files changed

+177
-0
lines changed

2 files changed

+177
-0
lines changed

include/optee_include/OpteeClientInterface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ enum RK_HDCP_KEYID {
2424
RK_HDCP_KEYMAX
2525
};
2626

27+
enum RK_ESCK_KEYID {
28+
RK_ESCK_KEY0 = 0,
29+
RK_ESCK_KEYMAX
30+
};
31+
2732
/* Crypto mode */
2833
enum RK_CIPIHER_MODE {
2934
RK_CIPHER_MODE_ECB = 0,

lib/optee_clientApi/OpteeClientInterface.c

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#define STORAGE_CMD_SET_OEM_HDCP_KEY_MASK 23
3636
#define STORAGE_CMD_WRITE_OEM_ENCRYPT_DATA 24
3737
#define STORAGE_CMD_OEM_ENCRYPT_DATA_IS_WRITTEN 25
38+
#define STORAGE_CMD_WRITE_ESCK_KEY 27
39+
#define STORAGE_CMD_ESCK_KEY_IS_WRITTEN 28
40+
#define STORAGE_CMD_SET_ESCK_KEY_MASK 29
3841

3942
#define CRYPTO_SERVICE_CMD_OEM_OTP_KEY_PHYS_CIPHER 0x00000002
4043

@@ -1381,6 +1384,175 @@ uint32_t trusty_set_oem_hdcp_key_mask(enum RK_HDCP_KEYID key_id)
13811384
return TeecResult;
13821385
}
13831386

1387+
uint32_t trusty_write_esck_key(enum RK_ESCK_KEYID key_id,
1388+
uint8_t *byte_buf, uint32_t byte_len)
1389+
{
1390+
TEEC_Result TeecResult;
1391+
TEEC_Context TeecContext;
1392+
TEEC_Session TeecSession;
1393+
uint32_t ErrorOrigin;
1394+
1395+
TEEC_UUID tempuuid = { 0x2d26d8a8, 0x5134, 0x4dd8,
1396+
{ 0xb3, 0x2f, 0xb3, 0x4b, 0xce, 0xeb, 0xc4, 0x71 } };
1397+
TEEC_UUID *TeecUuid = &tempuuid;
1398+
TEEC_Operation TeecOperation = {0};
1399+
1400+
TeecResult = OpteeClientApiLibInitialize();
1401+
if (TeecResult != TEEC_SUCCESS)
1402+
return TeecResult;
1403+
1404+
TeecResult = TEEC_InitializeContext(NULL, &TeecContext);
1405+
if (TeecResult != TEEC_SUCCESS)
1406+
return TeecResult;
1407+
1408+
TeecResult = TEEC_OpenSession(&TeecContext,
1409+
&TeecSession,
1410+
TeecUuid,
1411+
TEEC_LOGIN_PUBLIC,
1412+
NULL,
1413+
NULL,
1414+
&ErrorOrigin);
1415+
if (TeecResult != TEEC_SUCCESS)
1416+
return TeecResult;
1417+
1418+
TeecOperation.params[0].value.a = key_id;
1419+
1420+
TEEC_SharedMemory SharedMem = {0};
1421+
1422+
SharedMem.size = byte_len;
1423+
SharedMem.flags = 0;
1424+
1425+
TeecResult = TEEC_AllocateSharedMemory(&TeecContext, &SharedMem);
1426+
if (TeecResult != TEEC_SUCCESS)
1427+
goto exit;
1428+
1429+
TeecOperation.params[1].tmpref.buffer = SharedMem.buffer;
1430+
TeecOperation.params[1].tmpref.size = SharedMem.size;
1431+
1432+
memcpy(SharedMem.buffer, byte_buf, SharedMem.size);
1433+
TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
1434+
TEEC_MEMREF_TEMP_INPUT,
1435+
TEEC_NONE,
1436+
TEEC_NONE);
1437+
1438+
TeecResult = TEEC_InvokeCommand(&TeecSession,
1439+
STORAGE_CMD_WRITE_ESCK_KEY,
1440+
&TeecOperation,
1441+
&ErrorOrigin);
1442+
if (TeecResult != TEEC_SUCCESS)
1443+
goto exit;
1444+
1445+
exit:
1446+
TEEC_ReleaseSharedMemory(&SharedMem);
1447+
TEEC_CloseSession(&TeecSession);
1448+
TEEC_FinalizeContext(&TeecContext);
1449+
1450+
return TeecResult;
1451+
}
1452+
1453+
uint32_t trusty_esck_key_is_written(enum RK_ESCK_KEYID key_id, uint8_t *value)
1454+
{
1455+
TEEC_Result TeecResult;
1456+
TEEC_Context TeecContext;
1457+
TEEC_Session TeecSession;
1458+
uint32_t ErrorOrigin;
1459+
1460+
*value = 0xFF;
1461+
1462+
TEEC_UUID tempuuid = { 0x2d26d8a8, 0x5134, 0x4dd8,
1463+
{ 0xb3, 0x2f, 0xb3, 0x4b, 0xce, 0xeb, 0xc4, 0x71 } };
1464+
TEEC_UUID *TeecUuid = &tempuuid;
1465+
TEEC_Operation TeecOperation = {0};
1466+
1467+
TeecResult = OpteeClientApiLibInitialize();
1468+
if (TeecResult != TEEC_SUCCESS)
1469+
return TeecResult;
1470+
1471+
TeecResult = TEEC_InitializeContext(NULL, &TeecContext);
1472+
if (TeecResult != TEEC_SUCCESS)
1473+
return TeecResult;
1474+
1475+
TeecResult = TEEC_OpenSession(&TeecContext,
1476+
&TeecSession,
1477+
TeecUuid,
1478+
TEEC_LOGIN_PUBLIC,
1479+
NULL,
1480+
NULL,
1481+
&ErrorOrigin);
1482+
if (TeecResult != TEEC_SUCCESS)
1483+
return TeecResult;
1484+
1485+
TeecOperation.params[0].value.a = key_id;
1486+
1487+
TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT,
1488+
TEEC_NONE,
1489+
TEEC_NONE,
1490+
TEEC_NONE);
1491+
1492+
TeecResult = TEEC_InvokeCommand(&TeecSession,
1493+
STORAGE_CMD_ESCK_KEY_IS_WRITTEN,
1494+
&TeecOperation,
1495+
&ErrorOrigin);
1496+
if (TeecResult == TEEC_SUCCESS)
1497+
*value = TeecOperation.params[0].value.b;
1498+
1499+
TEEC_CloseSession(&TeecSession);
1500+
TEEC_FinalizeContext(&TeecContext);
1501+
1502+
return TeecResult;
1503+
}
1504+
1505+
uint32_t trusty_set_esck_key_mask(enum RK_ESCK_KEYID key_id)
1506+
{
1507+
TEEC_Result TeecResult;
1508+
TEEC_Context TeecContext;
1509+
TEEC_Session TeecSession;
1510+
uint32_t ErrorOrigin;
1511+
1512+
TEEC_UUID tempuuid = { 0x2d26d8a8, 0x5134, 0x4dd8,
1513+
{ 0xb3, 0x2f, 0xb3, 0x4b, 0xce, 0xeb, 0xc4, 0x71 } };
1514+
TEEC_UUID *TeecUuid = &tempuuid;
1515+
TEEC_Operation TeecOperation = {0};
1516+
1517+
TeecResult = OpteeClientApiLibInitialize();
1518+
if (TeecResult != TEEC_SUCCESS)
1519+
return TeecResult;
1520+
1521+
TeecResult = TEEC_InitializeContext(NULL, &TeecContext);
1522+
if (TeecResult != TEEC_SUCCESS)
1523+
return TeecResult;
1524+
1525+
TeecResult = TEEC_OpenSession(&TeecContext,
1526+
&TeecSession,
1527+
TeecUuid,
1528+
TEEC_LOGIN_PUBLIC,
1529+
NULL,
1530+
NULL,
1531+
&ErrorOrigin);
1532+
if (TeecResult != TEEC_SUCCESS)
1533+
return TeecResult;
1534+
1535+
TeecOperation.params[0].value.a = key_id;
1536+
1537+
TeecOperation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT,
1538+
TEEC_NONE,
1539+
TEEC_NONE,
1540+
TEEC_NONE);
1541+
1542+
TeecResult = TEEC_InvokeCommand(&TeecSession,
1543+
STORAGE_CMD_SET_ESCK_KEY_MASK,
1544+
&TeecOperation,
1545+
&ErrorOrigin);
1546+
if (TeecResult != TEEC_SUCCESS)
1547+
goto exit;
1548+
1549+
exit:
1550+
TEEC_CloseSession(&TeecSession);
1551+
TEEC_FinalizeContext(&TeecContext);
1552+
1553+
return TeecResult;
1554+
}
1555+
13841556
uint32_t trusty_oem_user_ta_transfer(void)
13851557
{
13861558
TEEC_Result TeecResult;

0 commit comments

Comments
 (0)