Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion api-tests/platform/drivers/watchdog/stm/pal_wd_stm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* Copyright (c) 2018 - 2025, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Copyright (c) 2018 - 2025, STMicroelectronics.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -54,6 +57,37 @@ int pal_wd_stm_init(addr_t base_addr, uint32_t time_us, uint32_t timer_tick_us)
return 0;
}

/**
@brief - Initializes an hardware watchdog timer
@param - base_addr : Base address of the watchdog module for STM32WBA
- time_us : Time in micro seconds
- timer_tick_us : Number of ticks per micro second
@return - SUCCESS/FAILURE
**/
int pal_wd_stm_wba_init(addr_t base_addr, uint32_t time_us, uint32_t timer_tick_us)
{
volatile uint32_t ti = time_us;
volatile uint32_t titi = timer_tick_us;
ti;
titi;
/* enable watchog clock */
#define RCC_APB1ENR1_WWDGEN_Pos (11U)
#define RCC_APB1ENR1_WWDGEN_Msk (0x1UL << RCC_APB1ENR1_WWDGEN_Pos)/*!< 0x00000800 */
#define RCC_APB1ENR1_WWDGEN RCC_APB1ENR1_WWDGEN_Msk
/* RCC_APB1ENR1 */
volatile uint32_t *reg = (uint32_t *)0x40002C00;
*reg |= RCC_APB1ENR1_WWDGEN;
*reg |= RCC_APB1ENR1_WWDGEN;
/* prescaler */
MODIFY_REG(((WWDG_TypeDef *)base_addr)->CFR, WWDG_CFR_WDGTB, LL_WWDG_PRESCALER_128);
/* Counter 0..0x7F (7 bit counter value)*/
MODIFY_REG(((WWDG_TypeDef *)base_addr)->CR, WWDG_CR_T, 0x7F);
/* Window 0x00..0x7F*/
MODIFY_REG(((WWDG_TypeDef *)base_addr)->CFR, WWDG_CFR_W, 0x7F);

return 0;
}

/**
@brief - Enables a hardware watchdog timer
@param - base_addr : Base address of the watchdog module
Expand Down
6 changes: 5 additions & 1 deletion api-tests/platform/drivers/watchdog/stm/pal_wd_stm.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* Copyright (c) 2018 - 2025, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Copyright (c) 2018 - 2025, STMicroelectronics.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -101,6 +104,7 @@ typedef struct {


int pal_wd_stm_init(addr_t base_addr, uint32_t time_us, uint32_t timer_tick_us);
int pal_wd_stm_wba_init(addr_t base_addr, uint32_t time_us, uint32_t timer_tick_us);
int pal_wd_stm_enable(addr_t base_addr);
int pal_wd_stm_disable(addr_t base_addr);
int pal_wd_stm_is_enabled(addr_t base_addr);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/** @file
* Copyright (c) 2025, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Copyright (c) 2025, STMicroelectronics.
* 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 _PAL_ATTESTATION_CONFIG_H_
#define _PAL_ATTESTATION_CONFIG_H_

#define COSE_ALGORITHM_ES256 -7
#define COSE_ALG_SHA256_PROPRIETARY -72000

#define USEFUL_BUF_MAKE_STACK_UB UsefulBuf_MAKE_STACK_UB

#define COSE_SIG_CONTEXT_STRING_SIGNATURE1 "Signature1"

/* Private value. Intentionally not documented for Doxygen.
* This is the size allocated for the encoded protected headers. It
* needs to be big enough for make_protected_header() to succeed. It
* currently sized for one header with an algorithm ID up to 32 bits
* long -- one byte for the wrapping map, one byte for the label, 5
* bytes for the ID. If this is made accidentially too small, QCBOR will
* only return an error, and not overrun any buffers.
*
* 9 extra bytes are added, rounding it up to 16 total, in case some
* other protected header is to be added.
*/
#define T_COSE_SIGN1_MAX_PROT_HEADER (1+1+5+9)

/**
* This is the size of the first part of the CBOR encoded TBS
* bytes. It is around 20 bytes. See create_tbs_hash().
*/
#define T_COSE_SIZE_OF_TBS \
1 + /* For opening the array */ \
sizeof(COSE_SIG_CONTEXT_STRING_SIGNATURE1) + /* "Signature1" */ \
2 + /* Overhead for encoding string */ \
T_COSE_SIGN1_MAX_PROT_HEADER + /* entire protected headers */ \
3 * (/* 3 NULL bstrs for fields not used */ \
1 /* size of a NULL bstr */ \
)
#define NULL_USEFUL_BUF_C NULLUsefulBufC

#define ATTEST_PUBLIC_KEY_SLOT 4
#define ECC_CURVE_SECP256R1_PULBIC_KEY_LENGTH (1 + 2 * PSA_BITS_TO_BYTES(256))

typedef struct {
uint8_t *pubx_key;
size_t pubx_key_size;
uint8_t *puby_key;
size_t puby_key_size;
} ecc_key_t;

struct ecc_public_key_t {
const uint8_t a;
uint8_t public_key[]; /* X-coordinate || Y-coordinate */
};

static const struct ecc_public_key_t attest_public_key = {
/* Constant byte */
0x04,
/* X-coordinate */
{0x79, 0xEB, 0xA9, 0x0E, 0x8B, 0xF4, 0x50, 0xA6,
0x75, 0x15, 0x76, 0xAD, 0x45, 0x99, 0xB0, 0x7A,
0xDF, 0x93, 0x8D, 0xA3, 0xBB, 0x0B, 0xD1, 0x7D,
0x00, 0x36, 0xED, 0x49, 0xA2, 0xD0, 0xFC, 0x3F,
/* Y-coordinate */
0xBF, 0xCD, 0xFA, 0x89, 0x56, 0xB5, 0x68, 0xBF,
0xDB, 0x86, 0x73, 0xE6, 0x48, 0xD8, 0xB5, 0x8D,
0x92, 0x99, 0x55, 0xB1, 0x4A, 0x26, 0xC3, 0x08,
0x0F, 0x34, 0x11, 0x7D, 0x97, 0x1D, 0x68, 0x64},
};

static const uint8_t initial_attestation_public_x_key[] = {
0x79, 0xEB, 0xA9, 0x0E, 0x8B, 0xF4, 0x50, 0xA6,
0x75, 0x15, 0x76, 0xAD, 0x45, 0x99, 0xB0, 0x7A,
0xDF, 0x93, 0x8D, 0xA3, 0xBB, 0x0B, 0xD1, 0x7D,
0x00, 0x36, 0xED, 0x49, 0xA2, 0xD0, 0xFC, 0x3F
};

static const uint8_t initial_attestation_public_y_key[] = {
0xBF, 0xCD, 0xFA, 0x89, 0x56, 0xB5, 0x68, 0xBF,
0xDB, 0x86, 0x73, 0xE6, 0x48, 0xD8, 0xB5, 0x8D,
0x92, 0x99, 0x55, 0xB1, 0x4A, 0x26, 0xC3, 0x08,
0x0F, 0x34, 0x11, 0x7D, 0x97, 0x1D, 0x68, 0x64
};

/* Initialize the structure with given public key */
static const ecc_key_t attest_key = {
(uint8_t *)initial_attestation_public_x_key,
sizeof(initial_attestation_public_x_key),
(uint8_t *)initial_attestation_public_y_key,
sizeof(initial_attestation_public_y_key)
};

#endif /* _PAL_ATTESTATION_CONFIG_H_ */
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/** @file
* Copyright (c) 2025, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Copyright (c) 2025, STMicroelectronics.
* 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 _PAL_CONFIG_H_
#define _PAL_CONFIG_H_

#include "pal_crypto_config.h"
#include "pal_attestation_config.h"
#include "pal_storage_config.h"

/* Define PSA test suite dependent macros for non-cmake build */
#if !defined(PSA_CMAKE_BUILD)

/* Print verbosity = TEST */
#define VERBOSE 3

/* NSPE or SPE VAL build? */
#define VAL_NSPE_BUILD

/* NSPE or SPE TEST build? */
#define NONSECURE_TEST_BUILD

/* If not defined, skip watchdog programming */
#define WATCHDOG_AVAILABLE

/* Are Dynamic memory APIs available to secure partition? */
#define SP_HEAP_MEM_SUPP

/* PSA Isolation level supported by platform */
#define PLATFORM_PSA_ISOLATION_LEVEL 3
#endif /* PSA_CMAKE_BUILD */

/* Version of crypto spec used in attestation */
#define CRYPTO_VERSION_BETA3

/* Use hardcoded public key */
#define PLATFORM_OVERRIDE_ATTEST_PK

/*
* Include of PSA defined Header files
*/
#ifdef IPC
/* psa/client.h: Contains the PSA Client API elements */
#include "psa/client.h"

/*
* psa_manifest/sid.h: Macro definitions derived from manifest files that map from RoT Service
* names to Service IDs (SIDs). Partition manifest parse build tool must provide the implementation
* of this file.
*/
#include "psa_manifest/sid.h"

/*
* psa_manifest/pid.h: Secure Partition IDs
* Macro definitions that map from Secure Partition names to Secure Partition IDs.
* Partition manifest parse build tool must provide the implementation of this file.
*/
#include "psa_manifest/pid.h"
#endif

#ifdef CRYPTO
/* psa/crypto.h: Contains the PSA Crypto API elements */
#include "psa/crypto.h"
#endif

#if defined(INTERNAL_TRUSTED_STORAGE) || defined(STORAGE)
/* psa/internal_trusted_storage.h: Contains the PSA ITS API elements */
#include "psa/internal_trusted_storage.h"
#endif

#if defined(PROTECTED_STORAGE) || defined(STORAGE)
/* psa/protected_storage.h: Contains the PSA PS API elements */
#include "psa/protected_storage.h"
#endif

#ifdef INITIAL_ATTESTATION
/* psa/initial_attestation.h: Contains the PSA Initial Attestation API elements */
#include "psa/initial_attestation.h"
#endif

#endif /* _PAL_CONFIG_H_ */
Loading