Import Mbed OS hard-float snapshot

This commit is contained in:
Beslan
2026-06-01 20:15:04 +03:00
commit d3738e2f89
16278 changed files with 10628036 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include "hal/trng_api.h"
#include "sss_driver_rng.h"
#include "mbed_error.h"
void trng_init(trng_t *obj)
{
(void)obj;
}
void trng_free(trng_t *obj)
{
(void)obj;
}
int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *output_length)
{
(void)obj;
stOCTET_STRING stRANDOM;
unsigned int ret = 0;
stRANDOM.pu08Data = (u08 *)output;
//generate an approximation of 1
ret = sss_generate_rawrandom(&stRANDOM, length);
*output_length = (size_t)stRANDOM.u32DataByteLen;
if (ret) {
mbed_error_printf("Fail to get RNG value from SSS(0x%08x)\r\n", ret);
}
return ret;
}

View File

@@ -0,0 +1,166 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
/*************** Include Files ********************************************/
/* Driver Common */
#include "sss_common.h"
#include "sss_driver_util.h"
#include "sss_map.h"
#include "sss_driver_error.h"
#include "mb_cmd_system.h"
/* Driver Algorithm */
#include "mb_cmd_hash.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
const unsigned char pu08hash_wlen[8] = { 0, 5, 7, 8, 12, 16, 0, 0 };
/*************** Functions ***********************************************/
/*! @fn mb_hash_init(unsigned int object_id, unsigned int msg_byte_len)
* @ingroup SECURITY_SSS_MAILBOX
* @brief mailbox api for hash to init. hash setting
* @version v0.50 : 2016.8.13 Init. release version
* @param[in] object_id : algorithm selection
* @param[in] msg_byte_len : length of message with byte unit
* @retval SUCCESS : Success
* @retval Others(!=0) : fail - error from sub-function
*/
unsigned int mb_hash_init(
const stOCTET_STRING *pstMessage,
unsigned int object_id)
{
unsigned int ret;
//! step 0 : check the status of mailbox
if (SSS_MB_STATUS) {
return ERROR_SYSTEM_MAILBOX_BUSY;
}
//! step 1-1 : set data field
SSS_DATA_FIELD_SET(0U, pstMessage->u32DataByteLen);
//! step 1-2 : set control field
SSS_SET_MB_OID(object_id);
//! step 2 : run mb_cmd
ret = sss_mb_command(FUNC_HASH_INIT);
return ret;
}
/*! @fn mb_hash_update(unsigned int block_byte_len, unsigned char * msg_block)
* @ingroup SECURITY_SSS_MAILBOX
* @brief mailbox api for hash to update partial block of message
* @version v0.50 : 2016.8.13 Init. release version
* @param[in] block_byte_len: length of partial block message. It differ from hash algorithm spec.
* @param[in] msg_block : partial message block with block_byte_len
* @retval SUCCESS : Success
* @retval Others(!=0) : fail - error from sub-function
*/
unsigned int mb_hash_update(
stOCTET_STRING *pstMessage,
unsigned int block_byte_len)
{
int ret = SSSR_SUCCESS;
//! step 1 : digest
while (pstMessage->u32DataByteLen > MAX_MB_HASH_BLOCK_BLEN) {
//! - check the status of mailbox
if (SSS_MB_STATUS) {
return ERROR_SYSTEM_MAILBOX_BUSY;
}
//! Set data field : message
ret = _sss_OS_to_MB(pstMessage, (unsigned int *)(SSS_DATA_FIELD_BASE), MAX_MB_HASH_BLOCK_BLEN);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! Run mb_cmd
ret = sss_mb_command(FUNC_HASH_UPDATE);
pstMessage->pu08Data += MAX_MB_HASH_BLOCK_BLEN;
pstMessage->u32DataByteLen -= MAX_MB_HASH_BLOCK_BLEN;
}
return ret;
}
/*!
* @ingroup SECURITY_SSS_MAILBOX
* @brief mailbox api for hash to update partial block of message
* @version v0.50 : 2016.8.13 Init. release version
* @param[out] hash : hash output
* @param[in] block_byte_len: length of last block message.
* @param[in] msg_block : last message block with block_byte_len
* @retval SUCCESS : Success
* @retval Others(!=0) : fail - error from sub-function
*/
unsigned int mb_hash_final(
stOCTET_STRING *pstMessage,
stOCTET_STRING *pstDigest)
{
unsigned int ret;
//! step 0 : check the status of mailbox
if (SSS_MB_STATUS) {
return ERROR_SYSTEM_MAILBOX_BUSY;
}
//! set data field
// Check boudary of msg_block
if (pstMessage->u32DataByteLen > MAX_MB_HASH_BLOCK_BLEN) {
return ERROR_HASH_INVALID_LEN_BLOCK;
}
ret = _sss_OS_to_MB(pstMessage, (unsigned int *)(SSS_DATA_FIELD_BASE), pstMessage->u32DataByteLen);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! step 2 : run mb_cmd
ret = sss_mb_command(FUNC_HASH_FINAL);
if (ret == SSSR_SUCCESS) {
ret = sss_mb_get_response(pstDigest);
}
return ret;
}

View File

@@ -0,0 +1,78 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef SSS_MB_CMD_HASH_H
#define SSS_MB_CMD_HASH_H
/*************** Include Files ********************************************/
#include "sss_common.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
#define MAX_HASH_BLOCK_BLEN (128) //when sha2
//!mailbox command
#define FUNC_HASH_INIT (0x00013101)
#define FUNC_HASH_UPDATE (0x00023101)
#define FUNC_HASH_FINAL (0x00033101)
/*************** New Data Types (Basic Data Types) ***********************/
//! @struct sHASH_MSG
//! @brief struct of message for Hash
struct sHASH_MSG {
unsigned int addr_low;
unsigned int addr_high;
unsigned int descriptor_byte_len;
unsigned int msg_byte_len;
unsigned int msg_type;
};
#define MAX_MB_HASH_BLOCK_BLEN (256)
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
unsigned int mb_hash_init(
const stOCTET_STRING *pstMessage,
unsigned int object_id);
unsigned int mb_hash_update(
stOCTET_STRING *pstMessage,
unsigned int block_byte_len);
unsigned int mb_hash_final(
stOCTET_STRING *pstMessage,
stOCTET_STRING *pstDigest);
#endif /* SSS_MB_CMD_HASH_H */

View File

@@ -0,0 +1,166 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
/*************** Include Files ********************************************/
/* Driver Common */
#include "sss_common.h"
#include "sss_driver_util.h"
#include "sss_map.h"
#include "sss_driver_error.h"
#include "mb_cmd_system.h"
/* Driver Algorithm */
#include "mb_cmd_rng.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
/*! @fn mb_generate_random_number(unsigned int *random_number, unsigned int random_wlen)
* @ingroup SECURITY_SSS_MAILBOX
* @brief mailbox api for random number generation
* @version v0.50 : 2016.8.13 Init. release version
* @version v0.51 : 2018.01.13 Modified for S111 SRAM code
* @param[out] random_number : array of random number
* @param[in] random_wlen : word length of random number
* @retval SUCCESS : Success
* @retval Others(!=0) : fail - error from sub-function
*/
unsigned int mb_generate_random_number(stOCTET_STRING *pstRandom, unsigned int request_byte_len)
{
unsigned int ret;
unsigned int rsp_byte_len;
//! step 0 : check the status of mailbox
if (SSS_MB_STATUS) {
return ERROR_SYSTEM_MAILBOX_BUSY;
}
//! set data field
// Check boudary of msg_block
if (request_byte_len > 256) {
return ERROR_RNG_INVALID_LEN_REQUEST;
}
//! step 1-2 : set control field
SSS_CTRL_FIELD_SET(1U, request_byte_len);
//! step 2 : run mb_cmd
SSS_SET_MB_COMMAND(FUNC_RNG);
//! step 3 : wait for response
WAIT_SFR_BIT_CLR(SSS_MB_STATUS, 0x01);
//! step 4 : get return value// get return value
SSS_GET_MB_RESULT(ret);
if (ret == RSP_SUCCESS) {
SSS_CTRL_FIELD_GET(1U, rsp_byte_len);
ret = _sss_MB_to_OS(pstRandom, (unsigned int *)(SSS_DATA_FIELD_BASE), rsp_byte_len);
} else {
SSS_GET_ERROR_CODE(ret);
}
return ret;
}
/*! @fn mb_generate_random_number(unsigned int *random_number, unsigned int random_wlen)
* @ingroup SECURITY_SSS_MAILBOX
* @brief mailbox api for random number generation
* @version v0.50 : 2016.8.13 Init. release version
* @version v0.51 : 2018.01.13 Modified for S111 SRAM code
* @param[out] random_number : array of random number
* @param[in] random_wlen : word length of random number
* @retval SUCCESS : Success
* @retval Others(!=0) : fail - error from sub-function
*/
unsigned int mb_generate_raw_random(stOCTET_STRING *pstRandom, unsigned int request_byte_len)
{
unsigned int ret;
unsigned int rsp_byte_len;
//! step 0 : check the status of mailbox
if (SSS_MB_STATUS) {
return ERROR_SYSTEM_MAILBOX_BUSY;
}
//! set data field
// Check boudary of msg_block
if (request_byte_len > 256U) {
return ERROR_RNG_INVALID_LEN_REQUEST;
}
//! step 1-2 : set control field
SSS_CTRL_FIELD_SET(1U, request_byte_len);
//! step 2 : run mb_cmd
SSS_SET_MB_COMMAND(FUNC_TRNG);
//! step 3 : wait for response
WAIT_SFR_BIT_CLR(SSS_MB_STATUS, 0x01);
//! step 4 : get return value// get return value
SSS_GET_MB_RESULT(ret);
if (ret == RSP_SUCCESS) {
SSS_CTRL_FIELD_GET(1U, rsp_byte_len);
ret = _sss_MB_to_OS(pstRandom, (unsigned int *)(SSS_DATA_FIELD_BASE), rsp_byte_len);
} else {
SSS_GET_ERROR_CODE(ret);
}
return ret;
}
unsigned int mb_KAT_RNG(void)
{
unsigned int ret;
//! step 0 : check the status of mailbox
if (SSS_MB_STATUS) {
return ERROR_SYSTEM_MAILBOX_BUSY;
}
//! step 2 : run mb_cmd
SSS_SET_MB_COMMAND(FUNC_RNG_KAT);
//! step 3 : wait for response
WAIT_SFR_BIT_CLR(SSS_MB_STATUS, 0x01);
//! step 4 : get return value// get return value
SSS_GET_MB_RESULT(ret);
if (ret == RSP_SUCCESS) {
ret = SSSR_SUCCESS;
} else {
SSS_GET_ERROR_CODE(ret);
}
return ret;
}

View File

@@ -0,0 +1,51 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef MB_CMD_RNG_H
#define MB_CMD_RNG_H
/*************** Include Files ********************************************/
#include "sss_common.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
// ======================================
// Mailbox Command
// ======================================
#define FUNC_RNG (0x00016101)
#define FUNC_TRNG (0x00026101)
#define FUNC_RNG_KAT (0x00A06101)
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
unsigned int mb_generate_random_number(stOCTET_STRING *pstRandom, unsigned int request_byte_len);
unsigned int mb_generate_raw_random(stOCTET_STRING *pstRandom, unsigned int request_byte_len);
unsigned int mb_KAT_RNG(void);
#endif /* MB_CMD_RNG_H */

View File

@@ -0,0 +1,264 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
/*************** Include Files ********************************************/
#include "sss_map.h"
#include "sss_driver_error.h"
#include "sss_driver_util.h"
#include "mb_cmd_system.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
unsigned int mb_system_clear(unsigned int type)
{
int ret;
//! step 0 : check the status of mailbox
if (SSS_MB_STATUS) {
return ERROR_SYSTEM_MAILBOX_BUSY;
}
//! set data field
//! step 1-2 : set control field
SSS_CTRL_FIELD_SET(1U, type);
//! step 2 : run mb_cmd
SSS_SET_MB_COMMAND(FUNC_SYSTEM_CLEAR);
//! step 3 : wait for response
WAIT_SFR_BIT_CLR(SSS_MB_STATUS, 0x01);
//! step 4 : get return value// get return value
SSS_GET_MB_RESULT(ret);
if (ret == RSP_SUCCESS) {
ret = SUCCESS;
} else {
SSS_GET_ERROR_CODE(ret);
}
return ret;
}
unsigned int mb_system_get_info(unsigned int *version)
{
int ret;
//! step 0 : check the status of mailbox
if (SSS_MB_STATUS) {
return ERROR_SYSTEM_MAILBOX_BUSY;
}
//! set data field
//! step 1-2 : set control field
//! step 2 : run mb_cmd
SSS_SET_MB_COMMAND(FUNC_SYSTEM_GET_INFO);
//! step 3 : wait for response
WAIT_SFR_BIT_CLR(SSS_MB_STATUS, 0x03);
//! step 4 : get return value// get return value
SSS_GET_MB_RESULT(ret);
if (ret == RSP_SUCCESS) {
//_isp_memcpy_mailbox((unsigned int *)version , (unsigned int *)(DATA_FIELD_BASE), 8);
*version++ = SSS_DATA_FIELD(0);
*version++ = SSS_DATA_FIELD(1);
ret = SUCCESS;
} else {
SSS_GET_ERROR_CODE(ret);
}
return ret;
}
unsigned int mb_system_get_info_sram(unsigned int *version)
{
int ret;
//! step 0 : check the status of mailbox
if (SSS_MB_STATUS) {
return ERROR_SYSTEM_MAILBOX_BUSY;
}
//! set data field
//! step 1-2 : set control field
//! step 2 : run mb_cmd
SSS_SET_MB_COMMAND(0x00000102);
//! step 3 : wait for response
WAIT_SFR_BIT_CLR(SSS_MB_STATUS, 0x03);
//! step 4 : get return value// get return value
SSS_GET_MB_RESULT(ret);
if (ret == RSP_SUCCESS) {
//_isp_memcpy_mailbox((unsigned int *)version , (unsigned int *)(DATA_FIELD_BASE), 8);
*version++ = SSS_DATA_FIELD(0);
*version++ = SSS_DATA_FIELD(1);
ret = SUCCESS;
} else {
SSS_GET_ERROR_CODE(ret);
}
return ret;
}
unsigned int mb_system_fw_loading(unsigned int u32REMAP_ADDR, unsigned int u32SFR_REMAP_ADDR)
{
int ret;
//! step 0 : check the status of mailbox
if (SSS_MB_STATUS) {
return ERROR_SYSTEM_MAILBOX_BUSY;
}
//! set data field
SSS_DATA_FIELD_SET(0, u32REMAP_ADDR);
SSS_DATA_FIELD_SET(1, u32SFR_REMAP_ADDR);
//! step 1-2 : set control field
//! step 2 : run mb_cmd
SSS_SET_MB_COMMAND(FUNC_SYSTEM_SELF_LOAD);
//! step 3 : wait for response
WAIT_SFR_BIT_CLR(SSS_MB_STATUS, 0x01);
//! step 4 : get return value// get return value
SSS_GET_MB_RESULT(ret);
if (ret == RSP_SUCCESS) {
ret = SSSR_SUCCESS;
} else {
SSS_GET_ERROR_CODE(ret);
}
return ret;
}
unsigned int sss_mb_command(unsigned int u32Command)
{
unsigned int ret;
//! - Run mb_cmd
SSS_SET_MB_COMMAND(u32Command);
//! - Wait for response
WAIT_SFR_BIT_CLR(SSS_MB_STATUS, 0x01);
//! - Check result
ret = sss_mb_check_error();
return ret;
}
unsigned int sss_mb_check_n_get_response(stOCTET_STRING *pstOutput, unsigned int u32ExpecedLen)
{
unsigned int ret;
unsigned int rsp_block_byte_len;
SSS_GET_RSP_LEN(rsp_block_byte_len);
if (rsp_block_byte_len == u32ExpecedLen) {
ret = _sss_MB_to_OS(pstOutput, (unsigned int *)(SSS_DATA_FIELD_BASE), rsp_block_byte_len);
} else {
return ERROR_INVALID_LEN_RSP_BLOCK;
}
return ret;
}
unsigned int sss_mb_get_response(stOCTET_STRING *pstOutput)
{
unsigned int ret;
unsigned int rsp_block_byte_len;
SSS_GET_RSP_LEN(rsp_block_byte_len);
ret = _sss_MB_to_OS(pstOutput, (unsigned int *)(SSS_DATA_FIELD_BASE), rsp_block_byte_len);
return ret;
}
unsigned int sss_mb_check_n_get_response_BN(stBIG_NUM *pstOutput, unsigned int u32ExpecedLen)
{
unsigned int ret;
unsigned int rsp_block_byte_len;
SSS_GET_RSP_LEN(rsp_block_byte_len);
if (rsp_block_byte_len == u32ExpecedLen) {
ret = _sss_MB_to_BN(pstOutput, (unsigned int *)(SSS_DATA_FIELD_BASE), rsp_block_byte_len);
} else {
return ERROR_INVALID_LEN_RSP_BLOCK;
}
return ret;
}
unsigned int sss_mb_get_response_BN(stBIG_NUM *pstOutput)
{
unsigned int ret;
unsigned int rsp_block_byte_len;
SSS_GET_RSP_LEN(rsp_block_byte_len);
ret = _sss_MB_to_BN(pstOutput, (unsigned int *)(SSS_DATA_FIELD_BASE), rsp_block_byte_len);
return ret;
}
unsigned int sss_mb_check_error(void)
{
unsigned int ret;
SSS_GET_MB_RESULT(ret);
if (ret == RSP_SUCCESS) {
ret = SSSR_SUCCESS;
} else {
SSS_GET_ERROR_CODE(ret);
}
return ret;
}

View File

@@ -0,0 +1,120 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef MB_CMD_SYSTEM_H
#define MB_CMD_SYSTEM_H
/*************** Include Files ********************************************/
#include "sss_common.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
#define CLEAR_TYPE_MAILBOX (0x00)
#define CLEAR_TYPE_ALL (0xff)
#define ERROR_INVALID_LEN_RSP_BLOCK (FROM_DRV | (INVALID_LEN | ERR_OUTPUT))
//! Mailbox Command
#define FUNC_SYSTEM_GET_INFO (0x00000101)
#define FUNC_SYSTEM_CLEAR (0x00000201)
#define FUNC_SYSTEM_SELF_LOAD (0x00000501)
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
/*!
* @brief mailbox command for clear function
* @param[in] type definition of clear level {}
* @return
Error Code Description
SSSR_SUCCESS Function operates normally
Others(!=0) fail - error from sub-function
* @author Jinsu Hyun
* @version V0.5
Version Date Person Description
V0.50 2016.08.13 jinsu Initial Version
V0.51 2018.01.04 kitak Modify for S111 SRAM code
*/
unsigned int mb_system_clear(unsigned int type);
/*!
* @brief mailbox command for get info function
* @param[in] version ??? ???
* @return
Error Code Description
SSSR_SUCCESS Function operates normally
Others(!=0) fail - error from sub-function
* @author Jinsu Hyun
* @version V0.5
Version Date Person Description
V0.50 2016.08.13 jinsu Initial Version
V0.51 2018.01.04 kitak Modify for S111 SRAM code
*/
unsigned int mb_system_get_info(unsigned int *version);
unsigned int mb_system_get_info_sram(unsigned int *version);
/**
* @brief mailbox command for self-loading
* @param[in] u32SrcAddr Address of FW to be loaded
* @return
Error Code Description
SSSR_SUCCESS Function operates normally
ERROR_IP_BUSY
ERROR_INVALID_OID_SIZE
* @author kiseok.bae (kiseok.bae@samsung.com)
* @version V0.00
Version Date Person Description
V0.00 2017.07.15 kiseok Initial Version
V0.51 2018.01.04 kitak Modify for S111 SRAM code
*/
unsigned int mb_system_fw_loading(unsigned int u32REMAP_ADDR, unsigned int u32SFR_REMAP_ADDR);
unsigned int sss_mb_command(unsigned int u32Command);
unsigned int sss_mb_check_error(void);
unsigned int sss_mb_check_n_get_response(stOCTET_STRING *pstOutput, unsigned int u32ExpecedLen);
unsigned int sss_mb_get_response(stOCTET_STRING *pstOutput);
unsigned int sss_mb_get_response_BN(stBIG_NUM *pstOutput);
unsigned int sss_mb_check_n_get_response_BN(stOCTET_STRING *pstOutput, unsigned int u32ExpecedLen);
#endif /* MB_CMD_SYSTEM_H */

View File

@@ -0,0 +1,161 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef SSS_COMMON_H
#define SSS_COMMON_H
/*************** Include Files ********************************************/
#include "sss_oid.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
#define SUCCESS (0x00)
#define FAIL (0x01)
#define SSSR_SUCCESS (0x00)
#define SSSR_FAIL (0x01)
#define RSP_FAIL (0xF1)
#define RSP_SUCCESS (0xA1)
#ifndef NULL
#define NULL ((void *) 0)
#endif
#define NULLPTR (void *)0
/////////////////////////////////////////////////////////
// MACRO ////////////////////////////////////////////////
/////////////////////////////////////////////////////////
#define BIT(nbit) (0x1u << (nbit))
#define SFR_BIT_SET(val, bit) ((val) |= (bit)) ///<bit set by bit value
#define SFR_W0i1C(sfr, bit) ((sfr) = (bit)) // write 0 ignore & write 1 clear
#define SFR_SET(sfr, val) ((sfr) = (val))
#define SFR_GET(sfr, val) ((val) = (sfr))
#define WAIT_SFR_BIT_CLR(sfr, bit) while((sfr) & (bit)) ///<wait until bit is cleared
#define WAIT_SFR_BIT_SET(sfr, bit) while(!((sfr) & (bit))) ///<wait until bit is set
#define SSS_SFR_SET(sfr, val) ((sfr) = (val))
#define SSS_SFR_GET(sfr, val) ((val) = (sfr))
#define SSS_SFR_BIT_SET(sfr, bit) ((sfr) = (sfr)|(bit))
#define SSS_WAIT_BIT_CLR(sfr, bit) while ((sfr) & (bit))
#define SSS_WAIT_SFR_BIT_SET(sfr, bit) while (!((sfr) & (bit)))
#define SSS_CTRL_FIELD_ADDR(val) (SSS_CTRL_FIELD_BASE+((val)<<2))
#define SSS_DATA_FIELD_ADDR(val) (SSS_DATA_FIELD_BASE+((val)<<2))
#define SSS_CTRL_FIELD(val) (*(volatile unsigned int *)(SSS_CTRL_FIELD_ADDR(val)))
#define SSS_DATA_FIELD(val) (*(volatile unsigned int *)(SSS_DATA_FIELD_ADDR(val)))
#define SSS_DATA_FIELD_SET(index, value) (SSS_DATA_FIELD(index) = (value))
#define SSS_DATA_FIELD_GET(index, value) ((value) = SSS_DATA_FIELD(index))
#define SSS_CTRL_FIELD_SET(index, value) (SSS_CTRL_FIELD(index) = (value))
#define SSS_CTRL_FIELD_GET(index, value) ((value) = SSS_CTRL_FIELD(index))
#define SSS_SET_MB_COMMAND(value) (SSS_CTRL_FIELD(0U) = (value))
#define SSS_SET_MB_OID(value) (SSS_CTRL_FIELD(1U) = (value))
#define SSS_GET_MB_RESULT(value) ((value) = SSS_CTRL_FIELD(0U))
#define SSS_GET_ERROR_CODE(value) ((value) = SSS_CTRL_FIELD(1U))
#define SSS_GET_RSP_LEN(value) ((value) = SSS_CTRL_FIELD(2U))
#define SET_DWORD_TO_BBUF(buf, dword) \
((u08 *)(buf))[3] = ((u08)((dword) >> 0)); \
((u08 *)(buf))[2] = ((u08)((dword) >> 8)); \
((u08 *)(buf))[1] = ((u08)((dword) >> 16)); \
((u08 *)(buf))[0] = ((u08)((dword) >> 24));
#define GET_DWORD_FROM_BBUF(buf) \
(u32)( \
((((u08 *)(buf))[3]) << 0) | \
((((u08 *)(buf))[2]) << 8) | \
((((u08 *)(buf))[1]) << 16) | \
((((u08 *)(buf))[0]) << 24))
#define SWAP32(val) \
(u32)( \
(((val) & 0xff) << 24) | \
(((val) & 0xff00) << 8) | \
(((val) & 0xff0000) >> 8) | \
(((val) & 0xff000000) >> 24) \
)
#define CEIL_16BYTE(val) (val&0xF) ? ((val&0xFFFFFFF0)+0x10) : (val)
#define CEIL_BY_WORD(val) (((val)+3)>>2)
#define CEIL_BY_16BYTE(val) (((val)+15)>>4)
//#define CEIL_BY_BYTE(bitval) (((bitval)+7)>>3)
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
//! 8bits unsigned data type
typedef unsigned char u08;
//! 16bits unsigned data type
typedef unsigned short u16;
//! 32bits unsigned data type
typedef unsigned int u32;
//! 64bits unsigned data type
typedef unsigned long long u64;
//! CPU size bits unsigned data type
typedef unsigned int uwd;
//! 8bits signed data type
typedef char s08;
//! 16bits signed data type
typedef short s16;
//! 32bits signed data type
typedef int s32;
//! 64bits signed data type
typedef long long s64;
//! CPU size bits signed data type
typedef int swd;
//! return error code
typedef u32 SSS_RV;
/**
* @brief struct of OCTET String / length & data
*/
typedef struct _OS_st {
//! byte length of Data
u32 u32DataByteLen;
//! byte array of Data
u08 *pu08Data;
} stOCTET_STRING;
/**
* @brief struct of BIGNUM String / length & data
*/
typedef stOCTET_STRING stBIG_NUM;
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
#endif /* SSS_COMMON_H */

View File

@@ -0,0 +1,368 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef SSS_DRIVER_ERROR_H
#define SSS_DRIVER_ERROR_H
/*************** Include Files ********************************************/
#include "sss_common.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
#define FROM_FW (0x0F)
#define FROM_DRV (0x0D)
//! Common Error Code
#define ERROR_AES (0x00001000)
#define ERROR_DH (0x00009000)
#define ERROR_ECC (0x00006000)
#define ERROR_ECDSA (0x00007000)
#define ERROR_ECDH (0x00008000)
#define ERROR_PKA (0x0000E000)
#define ERROR_RSA (0x00005000)
#define ERROR_RNG (0x00004000)
#define ERROR_RNG_TRNG (0x00004100)
#define ERROR_SHA (0x00002000)
#define ERROR_HMAC (0x00003000)
#define ERROR_SM3 (0x0000C200)
#define ERROR_SM3_HMAC (0x0000C300)
#define ERROR_SM4 (0x0000C100)
#define ERROR_KM (0x0000A000)
#define ERROR_SWDT1 (0x0000D100)
#define ERROR_SWDT2 (0x0000D200)
#define ERROR_FEEDER (0x0000F000)
#define INVALID_LEN (0x00010000)
#define INVALID_SEL (0x00FE0000)
#define INVALID_VAL (0x00FF0000)
#define INVALID_STS (0x00FD0000)
#define INVALID_SZ (0x00FC0000)
#define INVALID_FORM (0x00FB0000)
#define INVALID_FUNCID00 (0x00F00000)
#define INVALID_FUNCID01 (0x00F10000)
#define INVALID_FUNCID02 (0x00F20000)
#define INVALID_FUNCID03 (0x00F30000)
#define INVALID_ORDER (0x00FA0000)
#define INVALID_STATUS (0x00190000)
#define ERR_CNT (0x01000000)
#define ERR_IV (0x02000000)
#define ERR_TAG (0x03000000)
#define ERR_KEY (0x04000000)
#define ERR_BLOCK (0x05000000)
#define ERR_MSG (0x06000000)
#define ERR_MODE (0x07000000)
#define ERR_OID_ALG (0x08000000)
#define ERR_OID_SIZE (0x09000000)
#define ERR_SIGNATURE (0x0A000000)
#define ERR_PUBLICKEY (0x0B000000)
#define ERR_PRIVKEY (0x1B000000)
#define ERR_ROLLBACK_CNT (0x0C000000)
#define ERR_SIGNER_VER (0x0D000000)
#define ERR_FW (0x0E000000)
#define ERR_OUTPUT (0x0F000000)
#define ERR_BUSY (0x10000000)
#define ERR_CRNGT (0x11000000)
#define ERR_SLOT (0x12000000)
#define ERR_KEYMODE (0x13000000)
#define ERR_KAT (0x14000000)
#define ERR_HT (0x15000000)
#define ERR_RANDOM (0x16000000)
#define ERR_SALT (0x17000000)
#define ERR_PUF (0x18000000)
#define ERR_ERR_RATE (0x19000000)
#define ERR_MB_CMD (0x20000000)
#define ERR_AAD (0x21000000)
#define ERR_LABEL (0x30000000)
#define ERR_HW (0xFF000000)
#define ERR_DECRYPTION (0xDD000000)
//! Error From DRV
// System
#define ERROR_SYSTEM_MAILBOX_BUSY (FROM_DRV | (ERR_MB_CMD | INVALID_STATUS | ERR_BUSY))
#define ERROR_INVALID_VAL_OID (FROM_DRV | (INVALID_VAL | ERR_OID_ALG))
// AES
#define ERROR_AES_INVALID_LEN_BLOCK (FROM_DRV | (ERROR_AES | INVALID_LEN | ERR_BLOCK))
#define ERROR_AES_INVALID_LEN_RSP_BLOCK (FROM_DRV | (ERROR_AES | INVALID_LEN | ERR_OUTPUT))
#define ERROR_AES_INVALID_LEN_MSG (FROM_DRV | (ERROR_AES | INVALID_LEN | ERR_MSG))
#define ERROR_AES_INVALID_VAL_MODE (FROM_DRV | (ERROR_AES | INVALID_VAL | ERR_MSG))
#define ERROR_AES_INVALID_LEN_KEY (FROM_DRV | (ERROR_AES | INVALID_LEN | ERR_KEY))
#define ERROR_AES_INVALID_LEN_AAD (FROM_DRV | (ERROR_AES | INVALID_LEN | ERR_AAD))
#define ERROR_AES_INVALID_LEN_IV (FROM_DRV | (ERROR_AES | INVALID_LEN | ERR_IV))
#define ERROR_AES_INVALID_LEN_CNT (FROM_DRV | (ERROR_AES | INVALID_LEN | ERR_CNT))
#define ERROR_AES_INVALID_LEN_TAG (FROM_DRV | (ERROR_AES | INVALID_LEN | ERR_TAG))
#define ERROR_AES_INVALID_VAL_TAG (FROM_DRV | (ERROR_AES | INVALID_VAL | ERR_TAG))
// SM4
#define ERROR_SM4_INVALID_LEN_BLOCK (FROM_DRV | (ERROR_SM4 | INVALID_LEN | ERR_BLOCK))
#define ERROR_SM4_INVALID_LEN_RSP_BLOCK (FROM_DRV | (ERROR_SM4 | INVALID_LEN | ERR_OUTPUT))
#define ERROR_SM4_INVALID_LEN_MSG (FROM_DRV | (ERROR_SM4 | INVALID_LEN | ERR_MSG))
#define ERROR_SM4_INVALID_VAL_MODE (FROM_DRV | (ERROR_SM4 | INVALID_VAL | ERR_MODE))
#define ERROR_SM4_INVALID_LEN_KEY (FROM_DRV | (ERROR_SM4 | INVALID_LEN | ERR_KEY))
// Hash
#define ERROR_HASH_INVALID_LEN_BLOCK (FROM_DRV | (ERROR_SHA | INVALID_LEN | ERR_BLOCK))
#define ERROR_HASH_INVALID_LEN_MSG (FROM_DRV | (ERROR_SHA | INVALID_LEN | ERR_MSG))
#define ERROR_HASH_INVALID_VAL_MODE (FROM_DRV | (ERROR_SHA | INVALID_LEN | ERR_MODE))
// HMAC
#define ERROR_HMAC_INVALID_LEN_BLOCK (FROM_DRV | (ERROR_HMAC | INVALID_LEN | ERR_BLOCK))
#define ERROR_HMAC_INVALID_LEN_MSG (FROM_DRV | (ERROR_HMAC | INVALID_LEN | ERR_MSG))
#define ERROR_HMAC_INVALID_VAL_MODE (FROM_DRV | (ERROR_HMAC | INVALID_LEN | ERR_MODE))
#define ERROR_HMAC_INVALID_LEN_KEY (FROM_DRV | (ERROR_HMAC | INVALID_LEN | ERR_KEY))
// SM3
#define ERROR_SM3_INVALID_LEN_BLOCK (FROM_DRV | (ERROR_SM3 | INVALID_LEN | ERR_BLOCK))
#define ERROR_SM3_INVALID_LEN_MSG (FROM_DRV | (ERROR_SM3 | INVALID_LEN | ERR_MSG))
#define ERROR_SM3_INVALID_VAL_MODE (FROM_DRV | (ERROR_SM3 | INVALID_LEN | ERR_MODE))
// DH
#define ERROR_DH_INVALID_LEN_PUBKEY (FROM_DRV | (ERROR_DH | INVALID_LEN | ERR_PUBLICKEY))
#define ERROR_DH_INVALID_LEN_PRIVKEY (FROM_DRV | (ERROR_DH | INVALID_LEN | ERR_PRIVKEY))
#define ERROR_DH_INVALID_LEN_KEY (FROM_DRV | (ERROR_DH | INVALID_LEN | ERR_OUTPUT))
// ECDSA
#define ERROR_ECDSA_INVALID_LEN_MSG (FROM_DRV | (ERROR_ECDSA | INVALID_LEN | ERR_MSG))
#define ERROR_ECDSA_INVALID_LEN_SIGNATURE (FROM_DRV | (ERROR_ECDSA | INVALID_LEN | ERR_SIGNATURE))
#define ERROR_ECDSA_INVALID_LEN_PUBKEY (FROM_DRV | (ERROR_ECDSA | INVALID_LEN | ERR_PUBLICKEY))
#define ERROR_ECDSA_INVALID_LEN_PRIVKEY (FROM_DRV | (ERROR_ECDSA | INVALID_LEN | ERR_PRIVKEY))
//ECDH
#define ERROR_ECDH_INVALID_LEN_PUBKEY (FROM_DRV | (ERROR_ECDH | INVALID_LEN | ERR_PUBLICKEY))
#define ERROR_ECDH_INVALID_LEN_PRIVKEY (FROM_DRV | (ERROR_ECDH | INVALID_LEN | ERR_PRIVKEY))
#define ERROR_ECDH_INVALID_LEN_KEY (FROM_DRV | (ERROR_ECDH | INVALID_LEN | ERR_OUTPUT))
// RSASSA, RSAES
#define ERROR_RSA_INVALID_LEN_MSG (FROM_DRV | (ERROR_RSA | INVALID_LEN | ERR_MSG))
#define ERROR_RSA_INVALID_LEN_SIGNATURE (FROM_DRV | (ERROR_RSA | INVALID_LEN | ERR_SIGNATURE))
#define ERROR_RSA_INVALID_LEN_PUBKEY (FROM_DRV | (ERROR_RSA | INVALID_LEN | ERR_PUBLICKEY))
#define ERROR_RSA_INVALID_LEN_PRIVKEY (FROM_DRV | (ERROR_RSA | INVALID_LEN | ERR_PRIVKEY))
#define ERROR_RSA_INVALID_LEN_CIPHER (FROM_DRV | (ERROR_RSA | INVALID_LEN | ERR_OUTPUT))
#define ERROR_RSA_INVALID_LEN_LABEL (FROM_DRV | (ERROR_RSA | INVALID_LEN | ERR_LABEL))
// RNG
#define ERROR_RNG_INVALID_LEN_REQUEST (FROM_DRV | (ERROR_RNG | INVALID_LEN | ERR_OUTPUT))
//! Error From FW
#define FW_ERROR_AES_INVALID_VAL_OID (FROM_FW | (ERROR_AES | INVALID_VAL | ERR_OID_ALG))
#define FW_ERROR_AES_INVALID_LEN_MSG (FROM_FW | (ERROR_AES | INVALID_LEN | ERR_MSG))
#define FW_ERROR_AES_INVALID_STS_KEYMODE (FROM_FW | (ERROR_AES | INVALID_STS | ERR_KEYMODE))
#define FW_ERROR_AES_INVALID_LEN_KEY (FROM_FW | (ERROR_AES | INVALID_LEN | ERR_KEY))
#define FW_ERROR_AES_INVALID_VAL_TAG (FROM_FW | (ERROR_AES | INVALID_VAL | ERR_TAG))
#define FW_ERROR_AES_INVALID_LEN_TAG (FROM_FW | (ERROR_AES | INVALID_LEN | ERR_TAG))
#define FW_ERROR_AES_INVALID_LEN_IV (FROM_FW | (ERROR_AES | INVALID_LEN | ERR_IV))
#define FW_ERROR_AES_INVALID_LEN_AAD (FROM_FW | (ERROR_AES | INVALID_LEN | ERR_AAD))
#define FW_ERROR_AES_INVALID_LEN_CNT (FROM_FW | (ERROR_AES | INVALID_LEN | ERR_CNT))
#define FW_ERROR_DH_INVALID_VAL_OID (FROM_FW | (ERROR_DH | INVALID_VAL | ERR_OID_ALG))
#define FW_ERROR_DH_INVALID_VAL_KEY (FROM_FW | (ERROR_DH | INVALID_VAL | ERR_KEY))
#define FW_ERROR_DH_RNG_ERROR (FROM_FW | (ERROR_DH | INVALID_VAL | ERR_RANDOM))
#define FW_ERROR_ECC_INVALID_VAL_OID (FROM_FW | (ERROR_ECC | INVALID_VAL | ERR_OID_ALG))
#define FW_ERROR_ECDSA_INVALID_VAL_KEY (FROM_FW | (ERROR_ECDSA | INVALID_VAL | ERR_KEY))
#define FW_ERROR_ECDH_INVALID_VAL_KEY (FROM_FW | (ERROR_ECDH | INVALID_VAL | ERR_KEY))
#define FW_ERROR_ECDSA_INVALID_VAL_SIGN (FROM_FW | (ERROR_ECDSA | INVALID_VAL | ERR_SIGNATURE))
#define FW_ERROR_ECDSA_RNG_ERROR (FROM_FW | (ERROR_ECDSA | INVALID_VAL | ERR_RANDOM))
#define FW_ERROR_ECDH_RNG_ERROR (FROM_FW | (ERROR_ECDH | INVALID_VAL | ERR_RANDOM))
#define FW_ERROR_PKA_SFR_SET (FROM_FW | (ERROR_PKA|INVALID_VAL|ERR_HW))
#define FW_ERROR_RNG_TRNG_INVALID_CLKDIV (FROM_FW | (ERROR_RNG_TRNG | INVALID_VAL | ERR_HT))
#define FW_ERROR_RNG_TRNG_KAT_ERROR (FROM_FW | (ERROR_RNG_TRNG | INVALID_STS | ERR_KAT))
#define FW_ERROR_RNG_TRNG_HT_ERROR (FROM_FW | (ERROR_RNG_TRNG | INVALID_STS | ERR_HT))
#define FW_ERROR_RSA_INVALID_VAL_OID (FROM_FW | (ERROR_RSA | INVALID_VAL | ERR_OID_ALG))
#define FW_ERROR_RSA_INVALID_LEN_MESSAGE (FROM_FW | (ERROR_RSA | INVALID_LEN | ERR_MSG))
#define FW_ERROR_RSA_FAIL_DECRYPTION (FROM_FW | (ERROR_RSA | INVALID_STS | ERR_DECRYPTION))
#define FW_ERROR_RSA_INVALID_LEN_SALT (FROM_FW | (ERROR_RSA | INVALID_LEN | ERR_SALT))
#define FW_ERROR_RSA_INVALID_VAL_SIGNATURE (FROM_FW | (ERROR_RSA | INVALID_VAL | ERR_SIGNATURE))
#define FW_ERROR_RSA_INVALID_LEN_SIGNATURE (FROM_FW | (ERROR_RSA | INVALID_LEN | ERR_SIGNATURE))
#define FW_ERROR_SHA_INVALID_VAL_OID (FROM_FW | (ERROR_SHA | INVALID_VAL | ERR_OID_ALG))
#define FW_ERROR_HASH_INVALID_LEN_MSG (FROM_FW | (ERROR_SHA | INVALID_LEN | ERR_MSG))
#define FW_ERROR_HMAC_INVALID_LEN_KEY (FROM_FW | (ERROR_HMAC | INVALID_LEN | ERR_KEY))
#define FW_ERROR_SM3_INVALID_VAL_OID (FROM_FW | (ERROR_SM3 | INVALID_VAL | ERR_OID_ALG))
#define FW_ERROR_SM3_INVALID_LEN_MSG (FROM_FW | (ERROR_SM3 | INVALID_LEN | ERR_MSG))
#define FW_ERROR_SM3_HMAC_INVALID_LEN_KEY (FROM_FW | (ERROR_SM3_HMAC | INVALID_LEN | ERR_KEY))
#define FW_ERROR_SM4_INVALID_VAL_OID (FROM_FW | (ERROR_SM4 | INVALID_LEN | ERR_OID_ALG))
#define FW_ERROR_SM4_INVALID_LEN_KEY (FROM_FW | (ERROR_SM4 | INVALID_LEN | ERR_KEY))
#define FW_ERROR_SM4_INVALID_SEL_KEY (FROM_FW | (ERROR_SM4 | INVALID_SEL | ERR_KEY))
#define FW_ERROR_SM4_INVALID_LEN_MSG (FROM_FW | (ERROR_SM4 | INVALID_LEN | ERR_MSG))
#define FW_ERROR_AES_IP_BUSY (FROM_FW | (ERROR_AES | INVALID_STATUS | ERR_BUSY))
#define FW_ERROR_SM4_IP_BUSY (FROM_FW | (ERROR_SM4 | INVALID_STATUS | ERR_BUSY))
#define FW_ERROR_SM3_IP_BUSY (FROM_FW | (ERROR_SM3 | INVALID_STATUS | ERR_BUSY))
#define FW_ERROR_HASH_IP_BUSY (FROM_FW | (ERROR_SHA | INVALID_STATUS | ERR_BUSY))
#define FW_ERROR_TRNG_IP_BUSY (FROM_FW | (ERROR_RNG | INVALID_STATUS | ERR_BUSY))
#define FW_ERROR_PKA_IP_BUSY (FROM_FW | (ERROR_PKA | INVALID_STATUS | ERR_BUSY))
#define FW_ERROR_KM_IP_BUSY (FROM_FW | (ERROR_KM | INVALID_STATUS | ERR_BUSY))
#define FW_ERROR_SWDT1_IP_BUSY (FROM_FW | (ERROR_SWDT1 | INVALID_STATUS | ERR_BUSY))
#define FW_ERROR_SWDT2_IP_BUSY (FROM_FW | (ERROR_SWDT2 | INVALID_STATUS | ERR_BUSY))
#define FW_ERROR_FEEDER_IP_BUSY (FROM_FW | (ERROR_FEEDER | INVALID_STATUS | ERR_BUSY))
#define FW_ERROR_INVALID_FUNCID00 (FROM_FW | (ERR_MB_CMD | INVALID_FUNCID00))
#define FW_ERROR_INVALID_FUNCID01 (FROM_FW | (ERR_MB_CMD | INVALID_FUNCID01))
#define FW_ERROR_INVALID_FUNCID02 (FROM_FW | (ERR_MB_CMD | INVALID_FUNCID02))
#define FW_ERROR_INVALID_FUNCID03 (FROM_FW | (ERR_MB_CMD | INVALID_FUNCID03))
#define FW_ERROR_EXECUTION_ORDER (FROM_FW | (ERR_MB_CMD | INVALID_ORDER))
// Secure Storage
#define ERROR_SSTORAGE_INVALID_SLOT_INDEX (0x00F1A1D1)
#define ERROR_SSTORAGE_INVALID_DATA_LEN (0x00F2A1D1)
#define ERROR_SSTORAGE_INVALID_TYPE (0x00F3A1D1)
#define ERROR_SSTORAGE_DATA_INVALID_DATA_LEN (0x0002A1D1)
#define ERROR_SSTORAGE_CERT_INVALID_DATA_LEN (0x0003A2D1)
#define ERROR_SSTORAGE_KEY_INVALID_DATA_LEN (0x0004A3D1)
#define ERROR_SSTORAGE_KEY_INVALID_KEY_LEN (0x0005A3D1)
#define ERROR_SSTORAGE_KEY_INVALID_KEY_TYPE (0x0006A3D1)
#define ERROR_SSTORAGE_FACTORYKEY_PBKEY_INVALID_DATA_LEN (0x0007A2D1)
#define ERROR_SSTORAGE_WRITE (0x0008A2D1)
#define ERROR_SSTORAGE_READ (0x0008A2D1)
#define ERROR_SSTORAGE_SFS_FOPEN (0x0009A2D1)
#define ERROR_SSTORAGE_SFS_FSEEK (0x000AA2D1)
#define ERROR_SSTORAGE_SFS_FREAD (0x000BA2D1)
#define ERROR_SSTORAGE_SFS_FWRITE (0x000CA2D1)
#if 0
// SM4
#define ERROR_SM4_INVALID_BLOCK_LEN (0x000134D1)
#define ERROR_SM4_INVALID_RSP_BLOCK_LEN (0x000234D1)
#define ERROR_SM4_INVALID_MSG_LEN (0x000334D1)
#define ERROR_SM4_INVALID_MODE (0x000434D1)
#define ERROR_SM4_INVALID_KEY_LEN (0x000534D1)
#define ERROR_SM4_INVALID_INDEX (0x000834D1)
// Hash
#define ERROR_HASH_INVALID_MODE (0x000131D1)
#define ERROR_HASH_INVALID_BLOCK_LEN (0x000231D1)
#define ERROR_HASH_INVALID_MSG_LEN (0x000331D1)
// HMAC
#define ERROR_HMAC_INVALID_MODE (0x000132D1)
#define ERROR_HMAC_INVALID_KEY_LEN (0x000232D1)
#define ERROR_HMAC_INVALID_BLOCK_LEN (0x000332D1)
#define ERROR_HMAC_INVALID_INDEX (0x000432D1)
#define ERROR_HMAC_INVALID_RSP_BLOCK_LEN (0x000532D1)
// SM3
#define ERROR_SM3_INVALID_MODE (0x000133D1)
#define ERROR_SM3_INVALID_BLOCK_LEN (0x000233D1)
#define ERROR_SM3_INVALID_MSG_LEN (0x000333D1)
// DH
#define ERROR_DH_INVALID_PRIME_LEN (0x000125D1)
#define ERROR_DH_INVALID_PUBKEY_LEN (0x000225D1)
#define ERROR_DH_INVALID_PRIVATEKEY_LEN (0x000525D1)
#define ERROR_DH_INVALID_GENERATOR_LEN (0x000325D1)
#define ERROR_DH_INVALID_PRIME (0x000425D1)
#define ERROR_DH_INVALID_PUBKEY (0x000525D1)
#define ERROR_DH_INVALID_GENERATOR (0x000625D1)
// ECDSA
#define ERROR_ECDSA_INVALID_MSG_LEN (0x000111D1)
#define ERROR_ECDSA_INVALID_SIGNATURE_LEN (0x000311D1)
#define ERROR_ECDH_INVALID_PUBKEY_LEN (0x000411D1)
#define ERROR_ECDH_INVALID_PUBKEY (0x000511D1)
#define ERROR_ECDH_INVALID_PRIVKEY_LEN (0x000611D1)
#define ERROR_ECDH_INVALID_PRIVKEY (0x000711D1)
// RSA
#define ERROR_RSA_INVALID_CIPHER_LEN (0x000151D1)
#define ERROR_RSA_INVALID_MSG_LEN (0x000251D1)
#define ERROR_RSA_INVALID_SIGN_LEN (0x000351D1)
#define ERROR_RSA_INVALID_PAD_SELECTION (0x000451D1)
#define ERROR_RSA_INVALID_PUKEY (0x000551D1)
#define ERROR_RSA_INVALID_PRIVKEY (0x000651D1)
// RNG
#define ERROR_RNG_INVALID_RANDOM_REQUEST (0x000161D1)
// Common
#define ERROR_SSKeyID_InputID_MISSMATCH (0x000171D1)
#define ERROR_INVALID_OID (0x000271D1)
// System Function
#define ERROR_SYSTEM_INVALID_DATA_LEN (0x000201D1)
#define ERROR_SYSTEM_MAILBOX_BUSY (0x000100D1)
// Error from FW
#define FW_ERROR_ISP_INVALID_FUNCID00 (0x801000F1)
#define FW_ERROR_ISP_INVALID_FUNCID01 (0x801100F1)
#define FW_ERROR_ISP_INVALID_FUNCID02 (0x801200F1)
#define FW_ERROR_ISP_INVALID_FUNCID03 (0x801300F1)
#define FW_ERROR_ISP_INVALID_DATASIZE (0x801400F1)
#define FW_ERROR_ISP_FW_BODYSIZE (0x801500F1)
#define FW_ERROR_ISP_FW_ROLLBACK_CNT (0x801600F1)
#define FW_ERROR_ISP_FW_INVALID_PUBLICKEY (0x801700F1)
#define FW_ERROR_ISP_RESTORE_INTEGRITY_FAIL (0x801800F1)
#define FW_ERROR_ISP_IP_BUSY (0x801900F1)
#define FW_ERROR_ISP_SRAM_CMD_NOT_SUPPORTED (0x801A00F1)
#define FW_ERROR_INVALID_FUNCTION (0x000100f1)
#define FW_ERROR_FW_VERIFY (0x001400f1)
#define FW_ERROR_RESTORE_FAIL (0x001800f1)
#define FW_ERROR_IP_BUSY (0x001900f1)
#define FW_ERROR_INVALID_OID (0x003000f1)
#define FW_ERROR_INVALID_INPUT (0x003400f1)
#define FW_ERROR_INPUT_SETTING (0x004000f1)
#define FW_ERROR_PRNG (0x005000f1)
#define FW_FAIL_INVALID_SIGNATURE (0x006000f1)
#define FW_FAIL_INFINITY_POINT (0x006100f1)
#define FW_FAIL_NOT_ON_ECC_CURVE (0x006200f1)
// SRAM error
#define FW_ERROR_INVALID_EXEC_ORDER (0x80AF00F1)
#define FW_ERROR_OVER_VALID_RSA_MSGLEN (0x803500F1)
#define FW_ERROR_INVALID_RSA_MODLEN (0x803600F1)
#define FW_ERROR_Input_Public_is_not_odd (0x803700F1)
#define FW_ERROR_OVER_VALID_RSA_Saltlen (0x803800F1)
#define FW_ERROR_NO_PUKEY (0x803900F1)
#define FW_FAIL_OVER_MR_TRIALS (0x805600F1)
#define FW_FAIL_OVER_DH_RETRIALS (0x805600F1)
#define FW_FAIL_OVER_ECC_RETRIALS (0x805600F1)
#define FW_FAIL_NO_OUTPUT_KEY (0x805700F1)
#define FW_FAIL_OVER_GEN_RETRIALS (0x805800F1)
#define FW_ERROR_INVALID_RSASIGNATURE_0xBC (0x806400F1)
#define FW_ERROR_INVALID_RSASIGNATURE_lsb (0x806500F1)
#define FW_ERROR_INVALID_RSANONZERO_PS (0x806600F1)
#define FW_ERROR_INVALID_RSADB_SPLITTER (0x806700F1)
#define FW_ERROR_INVALID_SIGNATURE_BLEN (0x806800F1)
#define FW_ERROR_INVALID_CIPHER (0x806900F1)
#define FW_ERROR_INVALID_SEQUENCE (0x80ff00F1)
#define FW_ERROR_DER2INT_PARSE (0x80fe00F1)
#define FW_ERROR_AES_INVALID_KEYSEL (0x80D000F1)
#define FW_ERROR_AES_INVALID_KEY_LEN (0x80D100F1)
#define FW_ERROR_AES_INVALID_DIR_MODE (0x80D200F1)
#define FW_ERROR_AES_INVLIAD_SWAP (0x80D300F1)
#define FW_ERROR_AES_INVALID_MODE (0x80D400F1)
#define FW_ERROR_AES_INVALID_TAG (0x80D500F1)
#define FW_ERROR_AES_INVALID_BLOCK_LEN (0x80D600F1)
#define FW_ERROR_AES_KM_BUSY (0x80D700F1)
#define FW_ERROR_AES_KM_INIT (0x80D800F1)
#define FW_ERROR_SSTORAGE_DATA_INVALID_SLOT_INDEX (0x80E100F1)
#define FW_ERROR_SSTORAGE_CERT_INVALID_SLOT_INDEX (0x80E200F1)
#define FW_ERROR_SSTORAGE_KEY_INVALID_KEY_LEN (0x80E300F1)
#define FW_ERROR_SSTORAGE_KEY_INVALID_MODE (0x80E400F1)
#define FW_ERROR_SSTORAGE_INVALID_DATA_TYPE (0x80E500F1)
#define FW_ERROR_SSTORAGE_KEY_INVALID_KEYTYPE (0x80E600F1)
#define FW_ERROR_SSTORAGE_KEY_INVALID_SLOT_INDEX (0x80E700F1)
#define FW_ERROR_SSTORAGE_FACTORYKEY_INVALID_HMAC (0x80E800F1)
#define FW_ERROR_SSTORAGE_FACTORYKEY_INVALID_ENCODING (0x80E900F1)
#define FW_ERROR_SSTORAGE_FACTORYKEY_INVALID_KEYTYPE (0x80EA00F1)
#define FW_ERROR_RNG_INVALID_LEN (0x80f100F1)
#define FW_ERROR_KEYGEN_INVALID_KEYLEN (0x80f200F1)
#define FW_ERROR_PKA_IP_BUSY (0x80B100F1)
#define FW_ERROR_HASH_IP_BUSY (0x80B200F1)
#define FW_ERROR_PRNG_IP_BUSY (0x80B300F1)
#endif
#endif /* SSS_DRIVER_ERROR_H */

View File

@@ -0,0 +1,121 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
/*************** Include Files ********************************************/
#include "sss_driver_error.h"
#include "sss_driver_rng.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
/*! @fn sss_generate_random(unsigned int *random, unsigned int wlen)
* @ingroup SECURITY_SSS
* @brief rng function
* @version v0.50 : 2016.8.13 Init. release version
* @version v0.01 : 2018.01.13 Modified for S111 SRAM code
* @param[out] random : array of random number
* @param[in] wlen : word length of random number to be generated
* @retval SUCCESS : Success
* @retval Others(!=0) : fail - error from sub-function
*/
unsigned int sss_generate_random(stOCTET_STRING *pstRandom, unsigned int request_byte_len)
{
unsigned int ret;
//! step 0 : clear Mailbox
ret = mb_system_clear(CLEAR_TYPE_MAILBOX);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! step 1 : generate random
ret = mb_generate_random_number(pstRandom, request_byte_len);
return ret;
}
/*!
* @ingroup SECURITY_SSS
* @brief rng function
* @version v0.50 : 2016.8.13 Init. release version
* @version v0.51 : 2018.01.13 Modified for S111 SRAM code
* @param[out] random : array of random number
* @param[in] wlen : word length of random number to be generated
* @retval SUCCESS : Success
* @retval Others(!=0) : fail - error from sub-function
*/
unsigned int sss_generate_rawrandom(stOCTET_STRING *pstRandom, unsigned int request_byte_len)
{
unsigned int ret;
//! step 0 : clear Mailbox
ret = mb_system_clear(CLEAR_TYPE_MAILBOX);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! step 1 : generate random
ret = mb_generate_raw_random(pstRandom, request_byte_len);
return ret;
}
/*!
* @ingroup SECURITY_SSS
* @brief rng function
* @version v0.50 : 2016.8.13 Init. release version
* @version v0.51 : 2018.01.13 Modified for S111 SRAM code
* @param[out] random : array of random number
* @param[in] wlen : word length of random number to be generated
* @retval SUCCESS : Success
* @retval Others(!=0) : fail - error from sub-function
*/
unsigned int sss_KAT_RNG(void)
{
unsigned int ret;
//! step 0 : clear Mailbox
ret = mb_system_clear(CLEAR_TYPE_MAILBOX);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! step 1 : call KAT
ret = mb_KAT_RNG();
return ret;
}

View File

@@ -0,0 +1,45 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef SSS_DRIVER_RNG_H
#define SSS_DRIVER_RNG_H
/*************** Include Files ********************************************/
#include "sss_common.h"
#include "mb_cmd_rng.h"
#include "mb_cmd_system.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
unsigned int sss_generate_random(stOCTET_STRING *pstRandom, unsigned int request_byte_len);
unsigned int sss_generate_rawrandom(stOCTET_STRING *pstRandom, unsigned int request_byte_len);
unsigned int sss_KAT_RNG(void);
#endif /* SSS_DRIVER_RNG_H */

View File

@@ -0,0 +1,178 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
/*************** Include Files ********************************************/
#include "sss_driver_error.h"
#include "sss_driver_sha2.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
int sss_SHA2_256(
const stOCTET_STRING *pstMessage,
stOCTET_STRING *pstDigest)
{
int ret = FAIL;
stOCTET_STRING stHASH_Input;
unsigned int object_id;
unsigned int block_byte_len;
//! step 0 : clear Mailbox
ret = mb_system_clear(CLEAR_TYPE_MAILBOX);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! assign hash_byte_len to compare returned result from sss_fw after hash operation
object_id = OID_SHA2_256;
block_byte_len = 64;
//! step 1 : set message length parameter to SSS
ret = mb_hash_init(pstMessage, object_id);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! step 2 : set message block to SSS
stHASH_Input.pu08Data = pstMessage->pu08Data;
stHASH_Input.u32DataByteLen = pstMessage->u32DataByteLen;
ret = mb_hash_update(&stHASH_Input, block_byte_len);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! step 3 : get hash result from SSS
ret = mb_hash_final(&stHASH_Input, pstDigest);
return ret;
}
int sss_SHA2_384(
const stOCTET_STRING *pstMessage,
stOCTET_STRING *pstDigest)
{
int ret = FAIL;
stOCTET_STRING stHASH_Input;
unsigned int object_id;
unsigned int block_byte_len;
//! step 0 : clear Mailbox
ret = mb_system_clear(CLEAR_TYPE_MAILBOX);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! assign hash_byte_len to compare returned result from sss_fw after hash operation
object_id = OID_SHA2_384;
block_byte_len = 128;
//! step 1 : set message length parameter to SSS
ret = mb_hash_init(pstMessage, object_id);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! step 2 : set message block to SSS
stHASH_Input.pu08Data = pstMessage->pu08Data;
stHASH_Input.u32DataByteLen = pstMessage->u32DataByteLen;
ret = mb_hash_update(&stHASH_Input, block_byte_len);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! step 3 : get hash result from SSS
ret = mb_hash_final(&stHASH_Input, pstDigest);
return ret;
}
int sss_SHA2_512(
const stOCTET_STRING *pstMessage,
stOCTET_STRING *pstDigest)
{
int ret = FAIL;
stOCTET_STRING stHASH_Input;
unsigned int object_id;
unsigned int block_byte_len;
//! step 0 : clear Mailbox
ret = mb_system_clear(CLEAR_TYPE_MAILBOX);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! assign hash_byte_len to compare returned result from sss_fw after hash operation
object_id = OID_SHA2_512;
block_byte_len = 128;
//! step 1 : set message length parameter to SSS
ret = mb_hash_init(pstMessage, object_id);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! step 2 : set message block to SSS
stHASH_Input.pu08Data = pstMessage->pu08Data;
stHASH_Input.u32DataByteLen = pstMessage->u32DataByteLen;
ret = mb_hash_update(&stHASH_Input, block_byte_len);
if (ret != SSSR_SUCCESS) {
return ret;
}
//! step 3 : get hash result from SSS
ret = mb_hash_final(&stHASH_Input, pstDigest);
return ret;
}

View File

@@ -0,0 +1,138 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef SSS_DRIVER_SHA2_H
#define SSS_DRIVER_SHA2_H
/*************** Include Files ********************************************/
#include "sss_common.h"
#include "mb_cmd_hash.h"
#include "mb_cmd_system.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
/*!
* @brief SHA2-256 with normal mode
* @param[in] pstMessage pointer of struct for Message
Name Description Variables
pu08Data array of Data
u32DataByteLen Byte length of Data (0< x < 2^32)
* @param[out] pstDigest pointer of struct for Digest
Name Description Variables
pu08Data array of Data
u32DataByteLen Byte length of Data 32
* @return
Error Code Description
SSSR_SUCCESS Function operates normally
ERROR_SHA_INVALID_VAL_OID_ALG
ERROR_SHA_INVALID_LEN_MSG
* @author kitak Kim (kitak81.kim@samsung.com)
* @version V0.00
Version Date Person Description
V0.00 2017.01.15 kitak Initial Version
*/
int sss_SHA2_256(
const stOCTET_STRING *pstMessage,
stOCTET_STRING *pstDigest);
/*!
* @brief SHA2-384 with normal mode
* @param[in] pstMessage pointer of struct for Message
Name Description Variables
pu08Data array of Data
u32DataByteLen Byte length of Data (0< x < 2^32)
* @param[out] pstDigest pointer of struct for Digest
Name Description Variables
pu08Data array of Data
u32DataByteLen Byte length of Data 48
* @return
Error Code Description
SSSR_SUCCESS Function operates normally
ERROR_SHA_INVALID_VAL_OID_ALG
ERROR_SHA_INVALID_LEN_MSG
* @author kitak Kim (kitak81.kim@samsung.com)
* @version V0.00
Version Date Person Description
V0.00 2017.01.15 kitak Initial Version
V0.01 2018.01.09 kitak Modify for S111 SRAM code
*/
int sss_SHA2_384(
const stOCTET_STRING *pstMessage,
stOCTET_STRING *pstDigest);
/*!
* @brief SHA2-512 with normal mode
* @param[in] pstMessage pointer of struct for Message
Name Description Variables
pu08Data array of Data
u32DataByteLen Byte length of Data (0< x < 2^32)
* @param[out] pstDigest pointer of struct for Digest
Name Description Variables
pu08Data array of Data
u32DataByteLen Byte length of Data 64
* @return
Error Code Description
SSSR_SUCCESS Function operates normally
ERROR_SHA_INVALID_VAL_OID_ALG
ERROR_SHA_INVALID_LEN_MSG
* @author kitak Kim (kitak81.kim@samsung.com)
* @version V0.00
Version Date Person Description
V0.00 2017.01.15 kitak Initial Version
V0.01 2018.01.09 kitak Modify for S111 SRAM code
*/
int sss_SHA2_512(
const stOCTET_STRING *pstMessage,
stOCTET_STRING *pstDigest);
#endif /* ISP_DRIVER_SHA2_H */

View File

@@ -0,0 +1,679 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
/*************** Include Files ********************************************/
#include "sss_driver_util.h"
#include "sss_map.h"
#include "sss_driver_error.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
/*! @fn _sss_check_oid(u32 inputoid, u32 algorithm)
* @ingroup Util
* @brief Check valid oid according to algorithm
* @version v0.01 : 2016
* @version v0.02 : 2018.01.04 Modify for S111 SRAM code
* @param[in] inputoid
* @param[in] algorithm
* @retval SUCCESS : success
*/
int _sss_check_oid(u32 inputoid, u32 algorithm)
{
u32 index = 0;
u32 list_max = 0;
u32 *pu32_list = 0;
u32 OIDLIST_MHAC[OIDMAX_HMAC] = {
OID_HMAC_SHA1_160,
OID_HMAC_SHA2_256, OID_HMAC_SHA2_384, OID_HMAC_SHA2_512,
};
u32 OIDLIST_HASH[OIDMAX_HASH] = {
OID_SHA1_160,
OID_SHA2_256, OID_SHA2_384, OID_SHA2_512,
OID_SHA3_224, OID_SHA3_256, OID_SHA3_384, OID_SHA3_512,
};
u32 OIDLIST_DH[OIDMAX_DH] = {
OID_DH_R5114_1024_160, OID_DH_R5114_2048_224, OID_DH_R5114_2048_256,
OID_DH_R2409_1024, //IKE
OID_DH_R3526_2048,
OID_DH_R5054_3072, OID_DH_R5054_4096
};
u32 OIDLIST_ECC[OIDMAX_ECC] = {
OID_ECC_BP192, OID_ECC_BP224, OID_ECC_BP256, OID_ECC_BP384, OID_ECC_BP512,
OID_ECC_P192, OID_ECC_P224, OID_ECC_P256, OID_ECC_P384, OID_ECC_P521,
};
u32 OIDLIST_RSA[OIDMAX_RSA] = {
OID_RSA_1024, OID_RSA_2048,
};
u32 OIDLIST_ECDSA[OIDMAX_ECDSA] = {
OID_ECDSA_BP192_SHA1_160, OID_ECDSA_BP192_SHA2_256, OID_ECDSA_BP192_SHA2_384, OID_ECDSA_BP192_SHA2_512,
OID_ECDSA_BP224_SHA1_160, OID_ECDSA_BP224_SHA2_256, OID_ECDSA_BP224_SHA2_384, OID_ECDSA_BP224_SHA2_512,
OID_ECDSA_BP256_SHA1_160, OID_ECDSA_BP256_SHA2_256, OID_ECDSA_BP256_SHA2_384, OID_ECDSA_BP256_SHA2_512,
OID_ECDSA_BP384_SHA1_160, OID_ECDSA_BP384_SHA2_256, OID_ECDSA_BP384_SHA2_384, OID_ECDSA_BP384_SHA2_512,
OID_ECDSA_BP512_SHA1_160, OID_ECDSA_BP512_SHA2_256, OID_ECDSA_BP512_SHA2_384, OID_ECDSA_BP512_SHA2_512,
OID_ECDSA_P192_SHA1_160, OID_ECDSA_P192_SHA2_256, OID_ECDSA_P192_SHA2_384, OID_ECDSA_P192_SHA2_512,
OID_ECDSA_P224_SHA1_160, OID_ECDSA_P224_SHA2_256, OID_ECDSA_P224_SHA2_384, OID_ECDSA_P224_SHA2_512,
OID_ECDSA_P256_SHA1_160, OID_ECDSA_P256_SHA2_256, OID_ECDSA_P256_SHA2_384, OID_ECDSA_P256_SHA2_512,
OID_ECDSA_P384_SHA1_160, OID_ECDSA_P384_SHA2_256, OID_ECDSA_P384_SHA2_384, OID_ECDSA_P384_SHA2_512,
OID_ECDSA_P521_SHA1_160, OID_ECDSA_P521_SHA2_256,
OID_ECDSA_P521_SHA2_384, OID_ECDSA_P521_SHA2_512,
};
switch (algorithm) {
case SSS_HMAC:
list_max = OIDMAX_HMAC;
pu32_list = (u32 *) OIDLIST_MHAC;
break;
case SSS_HASH:
list_max = OIDMAX_HASH;
pu32_list = (u32 *) OIDLIST_HASH;
break;
case SSS_DH:
list_max = OIDMAX_DH;
pu32_list = (u32 *) OIDLIST_DH;
break;
case SSS_ECDH:
list_max = OIDMAX_ECC;
pu32_list = (u32 *) OIDLIST_ECC;
break;
case SSS_RSA:
list_max = OIDMAX_RSA;
pu32_list = (u32 *) OIDLIST_RSA;
break;
case SSS_ECDSA:
list_max = OIDMAX_ECDSA;
pu32_list = (u32 *) OIDLIST_ECDSA;
break;
default:
return ERROR_INVALID_VAL_OID;
};
index = 0;
do {
if (inputoid == *(pu32_list + index)) {
break;
}
//case for RSA oid & ECDH
if (inputoid == (*(pu32_list + index) + 0x10)) {
break;
}
index++;
if (index == list_max) {
return ERROR_INVALID_VAL_OID;
}
} while (index < list_max);
return SSSR_SUCCESS;
}
/*! @fn int _sss_is_zero(const u32* pu32Src, u32 u32Size)
* @ingroup Util
* @brief Check zero array
* @version v0.10 : 2017.01.05 Init.
* @version v0.11 : 2018.01.04 Modify for S111 SRAM code
* @param[in] pu32Src
* - type : const u32*
* - Memory Address for the first parameter
* @param[in] u32Size
* - type : u32
* - the size of memory to be compared
* @retval SUCCESS : success
* @retval 1 : fail
*/
#if 0
int _isp_is_zero(const u32 *pu32Src, u32 u32Size)
{
u32 i = 0;
u32 u32CompareFlag = 0;
for (i = 0; i < u32Size; i++) {
u32CompareFlag += (pu32Src[i] != 0x00) ? 0 : 1;
}
if ((i == u32CompareFlag) && (u32Size == u32CompareFlag)) {
// All variables are zero
return 0;
}
else {
// some variables are not zero
return 1;
}
}
#else /*
*/
int _sss_is_zero(const u08 *pu08Src, u32 u32ByteLen)
{
u32 i = 0;
u32 u32CompareFlag = 0;
for (i = 0; i < u32ByteLen; i++) {
u32CompareFlag += (pu08Src[i] != 0x00) ? 0 : 1;
}
if ((i == u32CompareFlag) && (u32ByteLen == u32CompareFlag)) {
// All variables are zero
return SSSR_SUCCESS;
}
else {
// some variables are not zero
return SSSR_FAIL;
}
}
#endif /*
*/
int _sss_is_valid(const u08 *pu08Src, u32 u32ByteLen)
{
int ret = SSSR_FAIL;
if ((u32ByteLen != 0) && ((pu08Src[0] & 0xC0) != 0)) {
ret = SSSR_SUCCESS;
}
return ret;
}
/*!
* @brief Function to Convert Octet-String to Mailbox
* @param[in] pstOSSrc Octet-String Source
* @param[in] pu32Dst Destination Address
* @param[in] u32RequestByteLen Byte length to be copied
* @return N/A
* @author Kiseok Bae (kiseok.bae@samsung.com)
* @version V0.00
Version Date Person Description
V0.00 2017.06.17 kiseok Initial Version
V0.01 2018.01.04 kitak Modify for S111 SRAM code
*/
int _sss_BN_to_MB(const stBIG_NUM *pstOSSrc, u32 *pu32Dst, u32 u32RequestByteLen)
{
volatile u32 u32Tmp;
int Index;
int i = pstOSSrc->u32DataByteLen;
u08 *pu08Src = pstOSSrc->pu08Data;
//! Step 1. Check valid length
if (u32RequestByteLen > 256) {
return SSSR_FAIL;
}
if (i > (int)u32RequestByteLen) {
i = u32RequestByteLen;
}
//! Step 2. Define Copy word length
Index = CEIL_BY_WORD(u32RequestByteLen) - 1;
//! Step 3. Data Copy
while (Index >= 0) {
//! - set default is zero
u32Tmp = 0;
//! - define update value
if (i >= 4) {
u32Tmp = (((u32) pu08Src[i - 1]) << 24)
| (((u32) pu08Src[i - 2]) << 16)
| (((u32) pu08Src[i - 3]) << 8)
| ((u32) pu08Src[i - 4]);
i -= 4;
} else {
switch (i) {
case 3:
u32Tmp |= ((u32) pu08Src[i - 3]) << 8;
case 2:
u32Tmp |= ((u32) pu08Src[i - 2]) << 16;
case 1:
u32Tmp |= ((u32) pu08Src[i - 1]) << 24;
default:
i = 0;
break;
}
}
//! - update to destination
*(pu32Dst + Index) = u32Tmp;
Index--;
}
return SSSR_SUCCESS;
}
int _sss_MB_to_BN(stBIG_NUM *pstOSSDst, u32 *pu32Src, u32 u32RespondByteLen)
{
volatile u32 u32Tmp;
int s32Index = 0;
int s08Index = 0;
u08 *pu08Dst = pstOSSDst->pu08Data;
//! Step 1. Check valid output length
if (u32RespondByteLen > 256) {
pstOSSDst->u32DataByteLen = 0;
return SSSR_FAIL;
}
//! Step 2. Find zero bytes from MSB
//! find nonzeroword
do {
u32Tmp = *(pu32Src + s32Index);
s32Index++;
} while (u32Tmp == 0x0);
//! find nonzerobyte
while ((u32Tmp & 0xff) == 0x0) {
u32Tmp = u32Tmp >> 8;
s08Index++;
}
//! Step 2. Assign Dst length
if (pstOSSDst->u32DataByteLen == 0x0) {
//! update length after zero unwrapping
pstOSSDst->u32DataByteLen = u32RespondByteLen - 4 * (s32Index - 1) - s08Index;
}
//! update length after zero unwrapping
//pstOSSDst->u32DataByteLen = u32RespondByteLen - 4*(s32Index-1) - s08Index;
//! Step 3. Assign Dst length & copy length
s32Index = CEIL_BY_WORD(u32RespondByteLen) - 1;
s08Index = pstOSSDst->u32DataByteLen;
//! Step 4. Data Copy
while (s32Index >= 0) {
//! - load 32bit data
u32Tmp = *(pu32Src + s32Index);
//! - define update value
if (s08Index >= 4) {
pu08Dst[s08Index - 4] = (u08)(u32Tmp);
pu08Dst[s08Index - 3] = (u08)(u32Tmp >> 8);
pu08Dst[s08Index - 2] = (u08)(u32Tmp >> 16);
pu08Dst[s08Index - 1] = (u08)(u32Tmp >> 24);
s08Index -= 4;
}
else {
switch (s08Index) {
case 3:
pu08Dst[s08Index - 3] = (u08)(u32Tmp >> 8);
case 2:
pu08Dst[s08Index - 2] = (u08)(u32Tmp >> 16);
case 1:
pu08Dst[s08Index - 1] = (u08)(u32Tmp >> 24);
default:
s08Index = 0;
break;
}
}
//! - update to destination
s32Index--;
}
return SSSR_SUCCESS;
}
int _sss_OS_to_MB(const stOCTET_STRING *pstOSSrc, u32 *pu32Dst, u32 u32RequestByteLen)
{
volatile u32 u32Tmp;
int Index;
u08 *pu08Src = pstOSSrc->pu08Data;
//! Step 1. Check valid length
if ((u32RequestByteLen > 256) || (pstOSSrc->u32DataByteLen < u32RequestByteLen)) {
return SSSR_FAIL;
}
//! Step 2. Define Copy word length
Index = u32RequestByteLen;
//! Step 3. Data Copy
//while(Index>=0)
while (Index > 0) {
//! - set default is zero
u32Tmp = 0;
//! - define update value
if (Index >= 4) {
u32Tmp = (((u32) * (pu08Src + 3) << 24)
| ((u32) * (pu08Src + 2) << 16)
| ((u32) * (pu08Src + 1) << 8)
| (u32) * (pu08Src));
pu08Src += 4;
}
else {
switch (Index) {
case 3:
u32Tmp |= ((u32) * (pu08Src + 2) << 16);
case 2:
u32Tmp |= ((u32) * (pu08Src + 1) << 8);
case 1:
u32Tmp |= ((u32) * (pu08Src));
default:
Index = 0;
break;
}
}
//! - update to destination
*(pu32Dst++) = u32Tmp;
Index -= 4;
}
return SSSR_SUCCESS;
}
int _sss_MB_to_OS(stOCTET_STRING *pstOSSDst, u32 *pu32Src, u32 u32RespondByteLen)
{
volatile u32 u32Tmp;
int Index;
u08 *pu08Dst = pstOSSDst->pu08Data;
//! Step 1. Check valid length
if (u32RespondByteLen > 256) {
pstOSSDst->u32DataByteLen = 0;
return SSSR_FAIL;
}
//! Step 2. Define Copy word length
pstOSSDst->u32DataByteLen = Index = u32RespondByteLen;
//! Step 3. Data Copy
//while(Index>=0)
while (Index > 0) {
//! - load 32bit data
u32Tmp = *(pu32Src++);
//! - define update value
if (Index >= 4) {
*(pu08Dst) = (u08)(u32Tmp);
*(pu08Dst + 1) = (u08)(u32Tmp >> 8);
*(pu08Dst + 2) = (u08)(u32Tmp >> 16);
*(pu08Dst + 3) = (u08)(u32Tmp >> 24);
pu08Dst += 4;
} else {
switch (Index) {
case 3:
*(pu08Dst + 2) = (u08)(u32Tmp >> 16);
case 2:
*(pu08Dst + 1) = (u08)(u32Tmp >> 8);
case 1:
*(pu08Dst) = (u08)(u32Tmp);
default:
Index = 0;
break;
}
}
//! - update to destination
Index -= 4;
}
return SSSR_SUCCESS;
}
/*! @fn _sss_memcpy_u08(u08* pu08Dst, u08* pu08Src, u32 u32Size)
* @ingroup Util
* @brief Memory Copy based on u08
* @version v0.01 : 2015
* @version v0.02 : 2018.01.04 Modify for S111 SRAM code
* @param pu08Dst [IN]
* - type : u08*
* - Memory Address for the destination
* @param pu08Src [IN]
* - type : const u08*
* - Memory Address for the destination
* @param u32Size [IN]
* - type : u32
* - the size of memory to be compared
* @retval SUCCESS : success
*/
int _sss_memcpy_u08(u08 *pu08Dst, u08 *pu08Src, u32 u32Size)
{
u08 *pu08DstAddr;
u08 *pu08SrcAddr;
pu08DstAddr = pu08Dst;
pu08SrcAddr = pu08Src;
while (u32Size--) {
*pu08DstAddr++ = *pu08SrcAddr++;
}
return 0;
}
/*! @fn _sss_memset_u08(u08* pu08Dst, const u08 u08Src, u32 u32Size)
* @ingroup Util
* @brief Memory Set using constant based on u08
* @version v0.01 : 2015
* @version v0.02 : 2018.01.04 Modify for S111 SRAM code
* @param pu08Dst [IN]
* - type : u08*
* - Memory Address for the destination
* @param u08Src [IN]
* - type : const u08
* - constant value
* @param u32Size [IN]
* - type : u32
* - the size of memory to be compared
* @retval SUCCESS : success
*/
int _sss_memset_u08(u08 *pu08Dst, const u08 u08Src, u32 u32Size)
{
while (u32Size--) {
*pu08Dst++ = u08Src;
}
return 0;
}
int _sss_memcpy_mailbox(u32 *pu32Dst, u32 *pu32Src, u32 u32Size_byte_len)
{
volatile u32 u32Temp;
// if ((u32Size_byte_len == 0) || (u32Size_byte_len > 256)) {
// return 1;
// }
while (u32Size_byte_len >= 4) {
u32Temp = *(pu32Src++);
*(pu32Dst++) = u32Temp;
u32Size_byte_len -= 4;
}
// taidong_161027 copy last block based on byte length
switch (u32Size_byte_len) {
case 1:
*pu32Dst = (*pu32Dst & 0xFFFFFF00) ^ (*pu32Src & 0x000000FF);
break;
case 2:
*pu32Dst = (*pu32Dst & 0xFFFF0000) ^ (*pu32Src & 0x0000FFFF);
break;
case 3:
*pu32Dst = (*pu32Dst & 0xFF000000) ^ (*pu32Src & 0x00FFFFFF);
break;
}
return 0;
}

View File

@@ -0,0 +1,59 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef SSS_DRIVER_UTIL_H
#define SSS_DRIVER_UTIL_H
/*************** Include Files ********************************************/
#include "sss_common.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
#define SSS_HMAC (0x001)
#define SSS_HASH (0x002)
#define SSS_DH (0x003)
#define SSS_ECDH (0x004)
#define SSS_RSA (0x005)
#define SSS_ECDSA (0x006)
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
int _sss_check_oid(u32 inputoid, u32 algorithm);
int _sss_is_zero(const u08 *pu08Src, u32 u32ByteLen);
int _sss_is_valid(const u08 *pu08Src, u32 u32ByteLen);
int _sss_MB_to_BN(stBIG_NUM *pstBNSDst, u32 *pu32Src, u32 u32RespondByteLen);
int _sss_BN_to_MB(const stBIG_NUM *pstBNSrc, u32 *pu32Dst, u32 u32RequestByteLen);
int _sss_OS_to_MB(const stOCTET_STRING *pstOSSrc, u32 *pu32Dst, u32 u32RequestByteLen);
int _sss_MB_to_OS(stOCTET_STRING *pstOSSDst, u32 *pu32Src, u32 u32RespondByteLen);
int _sss_memcpy_u08(u08 *pu08Dst, u08 *pu08Src, u32 u32Size);
int _sss_memset_u08(u08 *pu08Dst, const u08 u08Src, u32 u32Size);
int _sss_memcpy_mailbox(u32 *pu32Dst, u32 *pu32Src, u32 u32Size_byte_len);
#endif /* SSS_UTIL_H */

View File

@@ -0,0 +1,126 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef SSS_MAP_H
#define SSS_MAP_H
/*************** Include Files ********************************************/
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
#define SSS_CMD_GET_INFO (0x101)
#define SSS_CMD_SUCCESS (0xA1)
#define SSS_CMD_FAIL (0xF1)
#define SSS_SRAM_LOCK_EN (0x01)
#define SSS_DEBUG_LOCK_EN (0x08)
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
/////////////////////////////////////////////////////////
// SSS Address in S5J_S100 and S5JT100 //////////////////
/////////////////////////////////////////////////////////
#if defined(TARGET_S5JS100)
#define SSS_REG_BASE (0x83100000)
#define MAILBOX_BASE (0x83110000)
#define SSS_SRAM_BASE (0x83108000)
#define SSS_TRNG_BASE (0x83180000)
#endif
#if defined(TARGET_S3JT100)
#define SSS_REG_BASE (0x400C0000)
#define MAILBOX_BASE (0x400E0000)
#define SSS_SRAM_BASE (0x400C8000)
#define SSS_TRNG_BASE (0x400C1400)
#endif
/////////////////////////////////////////////////////////
// SSS MAP //////////////////////////////////////////////
/////////////////////////////////////////////////////////
#define SSS_FEEDER_BASE (SSS_REG_BASE)
#define SSS_DATA_BASE (SSS_SRAM_BASE + 0x6F00)
#define SSS_CM0_LP_CON (*(volatile unsigned int *)(SSS_FEEDER_BASE + 0x001C))
#define SSS_LOW_POWER_MODE_EN (1<<0)
#define SSS_CM0_RESET (*(volatile unsigned int *)(MAILBOX_BASE + 0x0004))
#define SSS_CM0_HRESET (1<<0)
#define SSS_CM0_SRAM_ACCESS_CONTROL (*(volatile unsigned int *)(MAILBOX_BASE + 0x0008))
#define SSS_CM0_DEBUG_CONTROL (*(volatile unsigned int *)(MAILBOX_BASE + 0x0038))
#define SSS_MB_STATUS (*(volatile unsigned int *)(MAILBOX_BASE + 0x0000))
#define SSS_CM0_BUSY (1<<0)
#define SSS_CTRL_FIELD_BASE (MAILBOX_BASE + 0x0100)
#define SSS_DATA_FIELD_BASE (MAILBOX_BASE + 0x0110)
#define SSS_TRNG_CLKDIV (*(volatile unsigned int *)(SSS_REG_BASE + 0x1400))
#define SSS_TRNG_STARTUP_CTRL (*(volatile unsigned int *)(SSS_REG_BASE + 0x144C))
#define SSS_STARTUP_HTPASS (1<<0)
#define SSS_STARTUP_HTPASS_CLR (1<<0)
#define SSS_TRNG_CTRL (*(volatile unsigned int *)(SSS_REG_BASE + 0x1420))
#define SSS_RNGEN (0x80000000)
#define SSS_TRNG_TEST_CTRL (*(volatile unsigned int *)(SSS_REG_BASE + 0x1440))
#define SSS_HTEN (1<<1)
#define SSS_TRNG_TEST_DONE (*(volatile unsigned int *)(SSS_REG_BASE + 0x1460))
#define SSS_HTDONE (1<<1)
#define SSS_KATDONE (1<<2)
#define SSS_TRNG_TEST_STAT (*(volatile unsigned int *)(SSS_REG_BASE + 0x1444))
#define SSS_HTERR (1<<2)
#define SSS_KAT_PPERR (1<<3)
#define SSS_KAT_CRNGTERR (1<<4)
#define SSS_TRNG_FIFO_CTRL (*(volatile unsigned int *)(SSS_REG_BASE + 0x1450))
#define SSS_GEN_1_BYTE (1)
#define SSS_GEN_2_BYTE (2)
#define SSS_GEN_32_BYTE (32)
#if defined(TARGET_S5JS100)
#ifdef OTP_BANK
#define OTP_BASE (0x80000000)
#define SSS_ROOT_ENCRYPTION_KEY_BASE (OTP_BASE + 0x000)
#define SSS_ROOT_PRIVATE_KEY_BASE (OTP_BASE + 0x020)
#define SSS_FW_ENCRYPTION_KEY_BASE (OTP_BASE + 0x080)
#define SSS_KM_DIAG_DISABLE (OTP_BASE + 0x0A0)
#define SSS_CM0_DEBUG_DISABLE (OTP_BASE + 0x0A4)
#define SSS_CM0_SRAM_BOOT_DISABLE (OTP_BASE + 0x0A8)
#define SSS_CM0_SRAM_READ_DISABLE (OTP_BASE + 0x0AC)
#define SSS_CM0_ANTI_ROLLBACK_COUNT (OTP_BASE + 0x0B0)
#define SSS_CM0_SECURE_BOOT_KEY_BASE (OTP_BASE + 0x0C0)
#define SSS_TRANSFER_KEY1_BASE (OTP_BASE + 0x100)
#define SSS_TRANSFER_KEY2_BASE (OTP_BASE + 0x110)
#define SSS_TRANSFER_KEY3_BASE (OTP_BASE + 0x120)
#define SSS_TRANSFER_KEY4_BASE (OTP_BASE + 0x130)
#define PUF_KEY_BASE (OTP_BASE + 0x140)
#define PUF_KEY_VALID (OTP_BASE + 0x160)
#define SSS_SW_POR (OTP_BASE + 0x200)
#endif //OTP_BANK
#endif //TARGET_S5JS100
#endif /* SSS_MAP_H */

View File

@@ -0,0 +1,242 @@
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef SSS_OID_H
#define SSS_OID_H
/*************** Include Files ********************************************/
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
/*
* OID LIST
*/
#define OIDMAX_AES (12)
#define OID_AES_ECB (0x00000008)
#define OID_AES_ECB_128 (0x00100008)
#define OID_AES_ECB_192 (0x00180008)
#define OID_AES_ECB_256 (0x00200008)
#define OID_AES_CBC (0x00000108)
#define OID_AES_CBC_128 (0x00100108)
#define OID_AES_CBC_192 (0x00180108)
#define OID_AES_CBC_256 (0x00200108)
#define OID_AES_CTR (0x00000208)
#define OID_AES_CTR_128 (0x00100208)
#define OID_AES_CTR_192 (0x00180208)
#define OID_AES_CTR_256 (0x00200208)
#define OID_AES_XTS (0x00000308)
#define OID_AES_XTS_128 (0x00100308)
#define OID_AES_XTS_256 (0x00200308)
#define OID_AES_CCM (0x00001008)
#define OID_AES_CCM_128 (0x00101008)
#define OID_AES_CCM_192 (0x00181008)
#define OID_AES_CCM_256 (0x00201008)
#define OID_AES_GCM (0x00001108)
#define OID_AES_GCM_128 (0x00101108)
#define OID_AES_GCM_192 (0x00181108)
#define OID_AES_GCM_256 (0x00201108)
#define OID_AES_CMAC (0x00001208)
#define OID_AES_CMAC_128 (0x00101208)
#define OID_AES_CMAC_192 (0x00181208)
#define OID_AES_CMAC_256 (0x00201208)
#define OID_AES_ENCRYPT (0x00000000)
#define OID_AES_DECRYPT (0x01000000)
#define OID_ENCRYPTION (0x00000000)
#define OID_DECRYPTION (0x01000000)
#define OIDMAX_SM4 (1)
#define OID_SM4_ECB (0x00000009)
#define OID_SM4_ECB_128 (0x00100009)
#define OID_SM4_ENCRYPT (OID_AES_ENCRYPT)
#define OID_SM4_DECRYPT (OID_AES_DECRYPT)
#define OIDMAX_HMAC (4)
#define OID_HMAC_SHA1_160 (0x00011100)
#define OID_HMAC_SHA2_224 (0x00012200) //NA
#define OID_HMAC_SHA2_256 (0x00012300)
#define OID_HMAC_SHA2_384 (0x00012400)
#define OID_HMAC_SHA2_512 (0x00012500)
#define OIDMAX_HASH (8)
#define OID_SHA1_160 (0x00001100)
#define OID_SHA2_224 (0x00002200) //NA
#define OID_SHA2_256 (0x00002300)
#define OID_SHA2_384 (0x00002400)
#define OID_SHA2_512 (0x00002500)
#define OID_SHA3_224 (0x00003200) //NA
#define OID_SHA3_256 (0x00003300) //NA
#define OID_SHA3_384 (0x00003400) //NA
#define OID_SHA3_512 (0x00003500) //NA
#define OIDMAX_HMACSM3 (1)
#define OID_HMAC_SM3_256 (0x01012300)
#define OIDMAX_SM3 (1)
#define OID_SM3_256 (0x01002300)
#define OIDMAX_DH (7)
#define OID_DH_R5114_1024_160 (0x00001151)
#define OID_DH_R5114_2048_224 (0x00003252)
#define OID_DH_R5114_2048_256 (0x00003352)
#define OID_DH_R2409_1024 (0x00001131)
#define OID_DH_R3526_2048 (0x00003332)
#define OID_DH_R5054_3072 (0x00004033)
#define OID_DH_R5054_4096 (0x00005034)
#define OIDMAX_ECC (10)
#define OID_ECC_P192 (0x00000011)
#define OID_ECC_P224 (0x00000012)
#define OID_ECC_P256 (0x00000013)
#define OID_ECC_P384 (0x00000014)
#define OID_ECC_P521 (0x00000015)
#define OID_ECC_BP192 (0x00000051)
#define OID_ECC_BP224 (0x00000052)
#define OID_ECC_BP256 (0x00000053)
#define OID_ECC_BP384 (0x00000054)
#define OID_ECC_BP512 (0x00000055)
#define OID_ECC_25519 (0x00000093)
#define OIDMAX_RSA (2)
#define OID_RSA_1024 (0x000000B1)
#define OID_RSA_2048 (0x000000B2)
#define OID_RSA_3072 (0x000000B3)
#define OID_RSA_4096 (0x000000B4)
#define OIDMAX_ECDSA (40)
#define OID_ECDSA_BP192_SHA1_160 (OID_ECC_BP192|OID_SHA1_160)
#define OID_ECDSA_BP192_SHA2_256 (OID_ECC_BP192|OID_SHA2_256)
#define OID_ECDSA_BP192_SHA2_384 (OID_ECC_BP192|OID_SHA2_384)
#define OID_ECDSA_BP192_SHA2_512 (OID_ECC_BP192|OID_SHA2_512)
#define OID_ECDSA_BP224_SHA1_160 (OID_ECC_BP224|OID_SHA1_160)
#define OID_ECDSA_BP224_SHA2_256 (OID_ECC_BP224|OID_SHA2_256)
#define OID_ECDSA_BP224_SHA2_384 (OID_ECC_BP224|OID_SHA2_384)
#define OID_ECDSA_BP224_SHA2_512 (OID_ECC_BP224|OID_SHA2_512)
#define OID_ECDSA_BP256_SHA1_160 (OID_ECC_BP256|OID_SHA1_160)
#define OID_ECDSA_BP256_SHA2_256 (OID_ECC_BP256|OID_SHA2_256)
#define OID_ECDSA_BP256_SHA2_384 (OID_ECC_BP256|OID_SHA2_384)
#define OID_ECDSA_BP256_SHA2_512 (OID_ECC_BP256|OID_SHA2_512)
#define OID_ECDSA_BP384_SHA1_160 (OID_ECC_BP384|OID_SHA1_160)
#define OID_ECDSA_BP384_SHA2_256 (OID_ECC_BP384|OID_SHA2_256)
#define OID_ECDSA_BP384_SHA2_384 (OID_ECC_BP384|OID_SHA2_384)
#define OID_ECDSA_BP384_SHA2_512 (OID_ECC_BP384|OID_SHA2_512)
#define OID_ECDSA_BP512_SHA1_160 (OID_ECC_BP512|OID_SHA1_160)
#define OID_ECDSA_BP512_SHA2_256 (OID_ECC_BP512|OID_SHA2_256)
#define OID_ECDSA_BP512_SHA2_384 (OID_ECC_BP512|OID_SHA2_384)
#define OID_ECDSA_BP512_SHA2_512 (OID_ECC_BP512|OID_SHA2_512)
#define OID_ECDSA_P192_SHA1_160 (OID_ECC_P192|OID_SHA1_160)
#define OID_ECDSA_P192_SHA2_256 (OID_ECC_P192|OID_SHA2_256)
#define OID_ECDSA_P192_SHA2_384 (OID_ECC_P192|OID_SHA2_384)
#define OID_ECDSA_P192_SHA2_512 (OID_ECC_P192|OID_SHA2_512)
#define OID_ECDSA_P224_SHA1_160 (OID_ECC_P224|OID_SHA1_160)
#define OID_ECDSA_P224_SHA2_256 (OID_ECC_P224|OID_SHA2_256)
#define OID_ECDSA_P224_SHA2_384 (OID_ECC_P224|OID_SHA2_384)
#define OID_ECDSA_P224_SHA2_512 (OID_ECC_P224|OID_SHA2_512)
#define OID_ECDSA_P256_SHA1_160 (OID_ECC_P256|OID_SHA1_160)
#define OID_ECDSA_P256_SHA2_256 (OID_ECC_P256|OID_SHA2_256)
#define OID_ECDSA_P256_SHA2_384 (OID_ECC_P256|OID_SHA2_384)
#define OID_ECDSA_P256_SHA2_512 (OID_ECC_P256|OID_SHA2_512)
#define OID_ECDSA_P384_SHA1_160 (OID_ECC_P384|OID_SHA1_160)
#define OID_ECDSA_P384_SHA2_256 (OID_ECC_P384|OID_SHA2_256)
#define OID_ECDSA_P384_SHA2_384 (OID_ECC_P384|OID_SHA2_384)
#define OID_ECDSA_P384_SHA2_512 (OID_ECC_P384|OID_SHA2_512)
#define OID_ECDSA_P521_SHA1_160 (OID_ECC_P521|OID_SHA1_160)
#define OID_ECDSA_P521_SHA2_256 (OID_ECC_P521|OID_SHA2_256)
#define OID_ECDSA_P521_SHA2_384 (OID_ECC_P521|OID_SHA2_384)
#define OID_ECDSA_P521_SHA2_512 (OID_ECC_P521|OID_SHA2_512)
#define OIDMAX_RSASSA (8)
#define OID_RSASSA_PADDING_PKCS (0x01)
#define OID_RSASSA_PADDING_PSS (0x00)
#define OID_RSASSA_1024_SHA1_160 (OID_RSA_1024|OID_SHA1_160)
#define OID_RSASSA_1024_SHA2_256 (OID_RSA_1024|OID_SHA2_256)
#define OID_RSASSA_1024_SHA2_384 (OID_RSA_1024|OID_SHA2_384)
#define OID_RSASSA_1024_SHA2_512 (OID_RSA_1024|OID_SHA2_512)
#define OID_RSASSA_2048_SHA1_160 (OID_RSA_2048|OID_SHA1_160)
#define OID_RSASSA_2048_SHA2_256 (OID_RSA_2048|OID_SHA2_256)
#define OID_RSASSA_2048_SHA2_384 (OID_RSA_2048|OID_SHA2_384)
#define OID_RSASSA_2048_SHA2_512 (OID_RSA_2048|OID_SHA2_512)
#define OIDMAX_RSAES (8)
#define OID_RSAES_PADDING_PKCS (0x01)
#define OID_RSAES_PADDING_OAEP (0x00)
#define OID_RSAES_1024_SHA1_160 (OID_RSA_1024|OID_SHA1_160)
#define OID_RSAES_1024_SHA2_256 (OID_RSA_1024|OID_SHA2_256)
#define OID_RSAES_1024_SHA2_384 (OID_RSA_1024|OID_SHA2_384)
#define OID_RSAES_1024_SHA2_512 (OID_RSA_1024|OID_SHA2_512)
#define OID_RSAES_2048_SHA1_160 (OID_RSA_2048|OID_SHA1_160)
#define OID_RSAES_2048_SHA2_256 (OID_RSA_2048|OID_SHA2_256)
#define OID_RSAES_2048_SHA2_384 (OID_RSA_2048|OID_SHA2_384)
#define OID_RSAES_2048_SHA2_512 (OID_RSA_2048|OID_SHA2_512)
/*************** Macros *****************************************/
//ECC
#define GET_ECC_CURVE(OID) ((OID) & 0x07)
#define GET_ECC_ALG(OID) ((OID >> 4) & 0x0F)
#define Is_ECC_BP(OID) (OID & 0x40)
//RSA
#define GET_RSA_Keyblen(OID) ((OID & 0xF) << 10) //1024 or 2048
#define GET_RSA_KeyBytelen(OID) ((OID & 0xF) << 7) //128, 256
#define GET_RSA_Type(OID) ((OID >> 4) & 0xF) //B(ENC) or C(SIGN)
//Hash
#define GET_HASH_SIZE(OID) ((OID >> 8) & 0x07)
#define GET_HASH_ALG(OID) ((OID >> 12) & 0x0F)
//HMAC
#define Is_HMAC_ALG(OID) ((OID >> 16) & 0x0F)
//AES
#define GET_AES_MODE(OID) (OID & 0xffff)
#define GET_AES_SIZE(OID) ((OID >> 16) & 0xFF)
#define GET_ENC_DIRECTION(OID) ((OID >> 24) & 0x0F)
//DH
#define IS_NOT_DHPARAM_R5114(OID) (((OID >> 4) & 0xf) ^ 0x5)
#define GET_DHPRIME_SIZE(OID) ((OID >> 12) & 0xf)
#define GET_DHORDER_SIZE(OID) ((OID >> 8) & 0xf)
#define OIDMAX_MILENAGE (1)
#define OID_MILENAGE (0x00080000)
#define OID_F1 (0x01000000)
#define OID_F1S (0x02000000)
#define OID_F2 (0x03000000)
#define OID_F3 (0x04000000)
#define OID_F4 (0x05000000)
#define OID_F5 (0x06000000)
#define OID_F5S (0x07000000)
#define OID_MILENAGE_F1 (OID_MILENAGE | OID_F1)
#define OID_MILENAGE_F1S (OID_MILENAGE | OID_F1S)
#define OID_MILENAGE_F2 (OID_MILENAGE | OID_F2)
#define OID_MILENAGE_F3 (OID_MILENAGE | OID_F3)
#define OID_MILENAGE_F4 (OID_MILENAGE | OID_F4)
#define OID_MILENAGE_F5 (OID_MILENAGE | OID_F5)
#define OID_MILENAGE_F5S (OID_MILENAGE | OID_F5S)
#endif /* SSS_OID_H */

View File

@@ -0,0 +1,176 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2019 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/****************************************************************************
*
* Copyright 2020 Samsung Electronics All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#ifndef SSS_COMMON_H
#define SSS_COMMON_H
/*************** Include Files ********************************************/
#include "sss_oid.h"
/*************** Assertions ***********************************************/
/*************** Definitions / Macros *************************************/
#define SUCCESS (0x00)
#define FAIL (0x01)
#define SSSR_SUCCESS (0x00)
#define SSSR_FAIL (0x01)
#define RSP_FAIL (0xF1)
#define RSP_SUCCESS (0xA1)
#ifndef NULL
#define NULL ((void *) 0)
#endif
#define NULLPTR (void *)0
/////////////////////////////////////////////////////////
// MACRO ////////////////////////////////////////////////
/////////////////////////////////////////////////////////
#define BIT(nbit) (0x1u << (nbit))
#define SFR_BIT_SET(val, bit) ((val) |= (bit)) ///<bit set by bit value
#define SFR_W0i1C(sfr, bit) ((sfr) = (bit)) // write 0 ignore & write 1 clear
#define SFR_SET(sfr, val) ((sfr) = (val))
#define SFR_GET(sfr, val) ((val) = (sfr))
#define WAIT_SFR_BIT_CLR(sfr, bit) while((sfr) & (bit)) ///<wait until bit is cleared
#define WAIT_SFR_BIT_SET(sfr, bit) while(!((sfr) & (bit))) ///<wait until bit is set
#define SSS_SFR_SET(sfr, val) ((sfr) = (val))
#define SSS_SFR_GET(sfr, val) ((val) = (sfr))
#define SSS_SFR_BIT_SET(sfr, bit) ((sfr) = (sfr)|(bit))
#define SSS_WAIT_BIT_CLR(sfr, bit) while ((sfr) & (bit))
#define SSS_WAIT_SFR_BIT_SET(sfr, bit) while (!((sfr) & (bit)))
#define SSS_CTRL_FIELD_ADDR(val) (SSS_CTRL_FIELD_BASE+((val)<<2))
#define SSS_DATA_FIELD_ADDR(val) (SSS_DATA_FIELD_BASE+((val)<<2))
#define SSS_CTRL_FIELD(val) (*(volatile unsigned int *)(SSS_CTRL_FIELD_ADDR(val)))
#define SSS_DATA_FIELD(val) (*(volatile unsigned int *)(SSS_DATA_FIELD_ADDR(val)))
#define SSS_DATA_FIELD_SET(index, value) (SSS_DATA_FIELD(index) = (value))
#define SSS_DATA_FIELD_GET(index, value) ((value) = SSS_DATA_FIELD(index))
#define SSS_CTRL_FIELD_SET(index, value) (SSS_CTRL_FIELD(index) = (value))
#define SSS_CTRL_FIELD_GET(index, value) ((value) = SSS_CTRL_FIELD(index))
#define SSS_SET_MB_COMMAND(value) (SSS_CTRL_FIELD(0U) = (value))
#define SSS_SET_MB_OID(value) (SSS_CTRL_FIELD(1U) = (value))
#define SSS_GET_MB_RESULT(value) ((value) = SSS_CTRL_FIELD(0U))
#define SSS_GET_ERROR_CODE(value) ((value) = SSS_CTRL_FIELD(1U))
#define SSS_GET_RSP_LEN(value) ((value) = SSS_CTRL_FIELD(2U))
#define SET_DWORD_TO_BBUF(buf, dword) \
((u08 *)(buf))[3] = ((u08)((dword) >> 0)); \
((u08 *)(buf))[2] = ((u08)((dword) >> 8)); \
((u08 *)(buf))[1] = ((u08)((dword) >> 16)); \
((u08 *)(buf))[0] = ((u08)((dword) >> 24));
#define GET_DWORD_FROM_BBUF(buf) \
(u32)( \
((((u08 *)(buf))[3]) << 0) | \
((((u08 *)(buf))[2]) << 8) | \
((((u08 *)(buf))[1]) << 16) | \
((((u08 *)(buf))[0]) << 24))
#define SWAP32(val) \
(u32)( \
(((val) & 0xff) << 24) | \
(((val) & 0xff00) << 8) | \
(((val) & 0xff0000) >> 8) | \
(((val) & 0xff000000) >> 24) \
)
#define CEIL_16BYTE(val) (val&0xF) ? ((val&0xFFFFFFF0)+0x10) : (val)
#define CEIL_BY_WORD(val) (((val)+3)>>2)
#define CEIL_BY_16BYTE(val) (((val)+15)>>4)
//#define CEIL_BY_BYTE(bitval) (((bitval)+7)>>3)
/*************** New Data Types (Basic Data Types) ***********************/
/*************** New Data Types *******************************************/
//! 8bits unsigned data type
typedef unsigned char u08;
//! 16bits unsigned data type
typedef unsigned short u16;
//! 32bits unsigned data type
typedef unsigned int u32;
//! 64bits unsigned data type
typedef unsigned long long u64;
//! CPU size bits unsigned data type
typedef unsigned int uwd;
//! 8bits signed data type
typedef char s08;
//! 16bits signed data type
typedef short s16;
//! 32bits signed data type
typedef int s32;
//! 64bits signed data type
typedef long long s64;
//! CPU size bits signed data type
typedef int swd;
//! return error code
typedef u32 SSS_RV;
/**
* @brief struct of OCTET String / length & data
*/
typedef struct _OS_st {
//! byte length of Data
u32 u32DataByteLen;
//! byte array of Data
u08 *pu08Data;
} stOCTET_STRING;
/**
* @brief struct of BIGNUM String / length & data
*/
typedef stOCTET_STRING stBIG_NUM;
/*************** Constants ************************************************/
/*************** Variable declarations ************************************/
/*************** Functions ***********************************************/
#endif /* SSS_COMMON_H */