Skip to content

M487: Update BSP #12716

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

Merged
merged 3 commits into from
Apr 15, 2020
Merged
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
20 changes: 11 additions & 9 deletions features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/aes/aes_alt.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
/*
* Copyright (c) 2015-2016, Nuvoton Technology Corporation
*
* 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.
Expand Down Expand Up @@ -150,15 +152,15 @@ static void __nvt_aes_crypt( mbedtls_aes_context *ctx,
/* Init crypto module */
crypto_init();
/* Enable AES interrupt */
AES_ENABLE_INT();
AES_ENABLE_INT(CRPT);

/* We support multiple contexts with context save & restore and so needs just one
* H/W channel. Always use H/W channel #0. */

/* AES_IN_OUT_SWAP: Let H/W know both input/output data are arranged in little-endian */
AES_Open(0, ctx->encDec, ctx->opMode, ctx->keySize, AES_IN_OUT_SWAP);
AES_SetInitVect(0, ctx->iv);
AES_SetKey(0, ctx->keys, ctx->keySize);
AES_Open(CRPT, 0, ctx->encDec, ctx->opMode, ctx->keySize, AES_IN_OUT_SWAP);
AES_SetInitVect(CRPT, 0, ctx->iv);
AES_SetKey(CRPT, 0, ctx->keys, ctx->keySize);

/* AES DMA buffer requirements same as above */
if (! crypto_dma_buff_compat(input, dataSize, 16)) {
Expand All @@ -182,10 +184,10 @@ static void __nvt_aes_crypt( mbedtls_aes_context *ctx,
}
MBED_ASSERT(! crypto_dma_buffs_overlap(pIn, dataSize, pOut, dataSize));

AES_SetDMATransfer(0, (uint32_t)pIn, (uint32_t)pOut, dataSize);
AES_SetDMATransfer(CRPT, 0, (uint32_t)pIn, (uint32_t)pOut, dataSize);

crypto_aes_prestart();
AES_Start(0, CRYPTO_DMA_ONE_SHOT);
AES_Start(CRPT, 0, CRYPTO_DMA_ONE_SHOT);
crypto_aes_wait();

if( pOut != output ) {
Expand All @@ -199,7 +201,7 @@ static void __nvt_aes_crypt( mbedtls_aes_context *ctx,
ctx->iv[3] = CRPT->AES_FDBCK[3];

/* Disable AES interrupt */
AES_DISABLE_INT();
AES_DISABLE_INT(CRPT);
/* Uninit crypto module */
crypto_uninit();

Expand Down
21 changes: 12 additions & 9 deletions features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/des/des_alt.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
/*
* Copyright (c) 2015-2016, Nuvoton Technology Corporation
*
* 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.
Expand Down Expand Up @@ -355,7 +357,7 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
/* Init crypto module */
crypto_init();
/* Enable DES interrupt */
TDES_ENABLE_INT();
TDES_ENABLE_INT(CRPT);

/* Configure TDES_CTL register
*
Expand All @@ -373,7 +375,8 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
* 1. BE for byte sequence in word
* 2. BE for word sequence in double-word
*/
TDES_Open(0, // Channel number (0~4)
TDES_Open(CRPT
0, // Channel number (0~4)
enc, // 0: decode, 1: encode
(tdes_opmode & CRPT_TDES_CTL_TMODE_Msk) ? 1 : 0, // 0: DES, 1: TDES
(keyopt == 1) ? 1 : 0, // 0: TDES 2-key mode, 1: TDES 3-key mode
Expand All @@ -390,7 +393,7 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
keys3x2[i][0] = nu_get32_be(key[i] + 0);
keys3x2[i][1] = nu_get32_be(key[i] + 4);
}
TDES_SetKey(0, keys3x2);
TDES_SetKey(CRPT, 0, keys3x2);

uint32_t rmn = length;
const unsigned char *in_pos = input;
Expand All @@ -402,15 +405,15 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
uint32_t ivh, ivl;
ivh = nu_get32_be(iv);
ivl = nu_get32_be(iv + 4);
TDES_SetInitVect(0, ivh, ivl);
TDES_SetInitVect(CRPT, 0, ivh, ivl);

memcpy(dmabuf_in, in_pos, data_len);

/* We always use DMA backup buffers, which are guaranteed to be non-overlapped. */
TDES_SetDMATransfer(0, (uint32_t) dmabuf_in, (uint32_t) dmabuf_out, data_len);
TDES_SetDMATransfer(CRPT, 0, (uint32_t) dmabuf_in, (uint32_t) dmabuf_out, data_len);

crypto_des_prestart();
TDES_Start(0, CRYPTO_DMA_ONE_SHOT);
TDES_Start(CRPT, 0, CRYPTO_DMA_ONE_SHOT);
crypto_des_wait();

memcpy(out_pos, dmabuf_out, data_len);
Expand Down Expand Up @@ -452,7 +455,7 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S
}

/* Disable DES interrupt */
TDES_DISABLE_INT();
TDES_DISABLE_INT(CRPT);
/* Uninit crypto module */
crypto_uninit();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
/*
* Copyright (c) 2015-2016, Nuvoton Technology Corporation
*
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2016-2018 Nuvoton
/*
* Copyright (c) 2016-2018, Nuvoton Technology Corporation
*
* 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.
Expand Down Expand Up @@ -240,15 +242,15 @@ int mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp )
crypto_init();

/* Enable ECC interrupt */
ECC_ENABLE_INT();
ECC_ENABLE_INT(CRPT);

return 0;
}

void mbedtls_internal_ecp_free( const mbedtls_ecp_group *grp )
{
/* Disable ECC interrupt */
ECC_DISABLE_INT();
ECC_DISABLE_INT(CRPT);

/* Uninit crypto module */
crypto_uninit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
/*
* Copyright (c) 2015-2016, Nuvoton Technology Corporation
*
* 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.
Expand All @@ -13,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MBEDTLS_DEVICE_H
#define MBEDTLS_DEVICE_H

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
/*
* Copyright (c) 2015-2016, Nuvoton Technology Corporation
*
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
/*
* Copyright (c) 2015-2016, Nuvoton Technology Corporation
*
* 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.
Expand All @@ -13,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MBEDTLS_SHA1_ALT_H
#define MBEDTLS_SHA1_ALT_H

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
/*
* Copyright (c) 2015-2016, Nuvoton Technology Corporation
*
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
/*
* Copyright (c) 2015-2016, Nuvoton Technology Corporation
*
* 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.
Expand All @@ -13,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MBEDTLS_SHA256_ALT_H
#define MBEDTLS_SHA256_ALT_H

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
/*
* Copyright (c) 2015-2016, Nuvoton Technology Corporation
*
* 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
/*
* Copyright (c) 2015-2016, Nuvoton Technology Corporation
*
* 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.
Expand All @@ -13,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MBEDTLS_SHA512_ALT_H
#define MBEDTLS_SHA512_ALT_H

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
/*
* Copyright (c) 2015-2016, Nuvoton Technology Corporation
*
* 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.
Expand Down Expand Up @@ -69,7 +71,7 @@ void mbedtls_sha1_hw_starts(crypto_sha_context *ctx)
ctx->blocksize = 64;
ctx->blocksize_mask = 0x3F;

SHA_Open(SHA_MODE_SHA1, SHA_NO_SWAP, 0);
SHA_Open(CRPT, SHA_MODE_SHA1, SHA_NO_SWAP, 0);

// Ensure we have correct initial internal states in SHA_DGST registers even though SHA H/W is not actually started.
CRPT->HMAC_CTL |= CRPT_HMAC_CTL_START_Msk;
Expand Down Expand Up @@ -143,7 +145,7 @@ void mbedtls_sha256_hw_starts( crypto_sha_context *ctx, int is224)
ctx->blocksize_mask = 0x3F;
ctx->is224_384 = is224;

SHA_Open(is224 ? SHA_MODE_SHA224 : SHA_MODE_SHA256, SHA_NO_SWAP, 0);
SHA_Open(CRPT, is224 ? SHA_MODE_SHA224 : SHA_MODE_SHA256, SHA_NO_SWAP, 0);

// Ensure we have correct initial internal states in SHA_DGST registers even though SHA H/W is not actually started.
CRPT->HMAC_CTL |= CRPT_HMAC_CTL_START_Msk;
Expand Down Expand Up @@ -218,7 +220,7 @@ void mbedtls_sha512_hw_starts( crypto_sha_context *ctx, int is384)
ctx->blocksize_mask = 0x7F;
ctx->is224_384 = is384;

SHA_Open(is384 ? SHA_MODE_SHA384 : SHA_MODE_SHA512, SHA_NO_SWAP, 0);
SHA_Open(CRPT, is384 ? SHA_MODE_SHA384 : SHA_MODE_SHA512, SHA_NO_SWAP, 0);

// Ensure we have correct initial internal states in SHA_DGST registers even though SHA H/W is not actually started.
CRPT->HMAC_CTL |= CRPT_HMAC_CTL_START_Msk;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
/*
* Copyright (c) 2015-2016, Nuvoton Technology Corporation
*
* 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.
Expand All @@ -13,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MBEDTLS_SHA_ALT_HW_H
#define MBEDTLS_SHA_ALT_HW_H

Expand Down
Loading