Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of HASH peripheral for stm32mp1 #7259

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tbourgoi
Copy link
Contributor

@tbourgoi tbourgoi commented Feb 3, 2025

Add support of HASH peripheral for stm32mp15 and stm32mp13.
This PR :

  • add the driver stm32-hash.c
  • enable hash on stm32mp135-dk
  • compile the stm32_hash driver by default

Note:
HASH peripheral is allocated to non-secure on stm32mp15 boards , that's why it's not enable it in this PR.

toromanoSTM and others added 3 commits February 3, 2025 13:22
Add HASH IP drivers, and add hooks in OP-TEE crypto framework to use
HASH IP to do HASH and HMAC process

Signed-off-by: Nicolas Toromanoff <nicolas.toromanoff@foss.st.com>
Signed-off-by: Thomas Bourgoin <thomas.bourgoin@foss.st.com>
Sets HASH peripheral status to okay.

Signed-off-by: Thomas Bourgoin <thomas.bourgoin@foss.st.com>
Default enable HASH compilation.
Enable CFG_STM32_CRYPTO_DRIVERS if any crypto IP is compiled.

Signed-off-by: Thomas Bourgoin <thomas.bourgoin@foss.st.com>
core/drivers/crypto/stm32/hash.c Outdated Show resolved Hide resolved
core/drivers/crypto/stm32/hmac.c Show resolved Hide resolved
core/drivers/crypto/stm32/hmac.c Show resolved Hide resolved
core/drivers/crypto/stm32/stm32_hash.c Outdated Show resolved Hide resolved
core/drivers/crypto/stm32/stm32_hash.c Outdated Show resolved Hide resolved
core/drivers/crypto/stm32/stm32_hash.c Outdated Show resolved Hide resolved
core/drivers/crypto/stm32/stm32_hash.c Outdated Show resolved Hide resolved
hash.c & hmac.c:
 - Initial variables with errors where possible,
 - Remove dynamic allocation in do_hmac_final() and do_hash_final()
stm32_hash.c:
 - Fix documentation
 - Remove unnecessary "U"
 - Add space before }
 - Remove unnecessary parenthesis

Signed-off-by: Thomas Bourgoin <thomas.bourgoin@foss.st.com>
#define _HASH_CR_INIT BIT(2)
#define _HASH_CR_MODE BIT(6)
#define _HASH_CR_DATATYPE_SHIFT U(4)
#define _HASH_CR_DATATYPE_NONE (U(0) << _HASH_CR_DATATYPE_SHIFT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer SHIFT_U32() for all these.

{
uint64_t timeout = timeout_init_us(HASH_TIMEOUT_US);

while (io_read32(base + _HASH_SR) & _HASH_SR_BUSY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer IO_READ32_POLL_TIMEOUT()
Ditto in wait_digest_ready()

size_t *first, size_t *hmac_nb_regs,
size_t *hmac_first)
{
if (c->save_mode == SAVE_SMALL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer a swich/case implemenation


dst_buf = dst->remain.buf;
dst_csr = dst->csr;
memcpy(dst, src, sizeof(*dst));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer *dst = *src; when copying data of same type.

c->block_size = SHA3_512_BLOCK_SIZE;
c->save_mode = SAVE_SHA3;
break;
/* Default selected algo is SHA256 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems strange here. I think you can remove this inline comment and move the case between SHA224 and SAH384 cases.

!(io_read32(base + _HASH_SR) & _HASH_SR_DINIS)) {
uint32_t tmp_buf = 0;

memcpy(&tmp_buf, buffer, sizeof(uint32_t));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should sizeof(uint32_t) be replaced with MIN(len ,sizeof(uint32_t)).
Or maybe it is the || test at line 661 that should be a &&.
I must say that the first sentence in inline comment at line 653 is a bit cryptic to me.

goto exit;
}

memcpy((uint8_t *)c->remain.buf, buffer, len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cast not needed


/* We cannot fill the fifo */
if (c->remain.len + len < c->queue_size) {
if (!c->remain.buf) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this cannot happen. Ditto at line 723.

}

io_clrsetbits32(base + _HASH_STR, _HASH_STR_NBLW_MASK,
8U * (c->remain.len % sizeof(uint32_t)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/8U/8/

if (IS_ENABLED(CFG_CRYPTO_DRV_MAC)) {
res = stm32_register_hmac();
if (res) {
EMSG("Failed to register to mac: %#"PRIx32, res);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/mac/HMAC/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants