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

Fix order value for curve x448 #5811

Merged
merged 7 commits into from
Jun 27, 2022
Merged

Conversation

polhenarejos
Copy link
Contributor

@polhenarejos polhenarejos commented May 5, 2022

Closes: #5810

Status

READY

Requires Backporting

Yes
Which branch? 2.28 only

Todos

Steps to test or reproduce

See #5810

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
@polhenarejos
Copy link
Contributor Author

How do you usually backport bugfixes?

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
…e the group also for all curves.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
@tom-cosgrove-arm tom-cosgrove-arm added component-crypto Crypto primitives and low-level interfaces Community size-s Estimated task size: small (~2d) priority-medium Medium priority - this can be reviewed as time permits labels May 6, 2022
@tom-cosgrove-arm
Copy link
Contributor

@polhenarejos any chance of a non-regression test for this?

@tom-cosgrove-arm tom-cosgrove-arm added needs-work needs-ci Needs to pass CI tests labels May 6, 2022
@tom-cosgrove-arm
Copy link
Contributor

Backport only needed to mbedtls-2.28

@polhenarejos
Copy link
Contributor Author

@polhenarejos any chance of a non-regression test for this?

To make a quick test I use the provided test code in #5810

#include "common.h"
#include "mbedtls/private_access.h"

#include "mbedtls/build_info.h"
#include "mbedtls/ecp.h"

#define DEBUG_BUF(p,s) { \
    printf("Payload %s (%d bytes):\r\n", #p,(int)s);\
    for (int i = 0; i < s; i += 16) {\
        for (int j = 0; j < 16; j++) {\
            if (j < s-i) printf("%02x ",(p)[i+j]);\
            else printf("   ");\
            if (j == 7) printf(" ");\
            } \
            printf("\r\n");\
        } printf("\r\n"); \
    }

int main() 
{
    int ret; 
    mbedtls_ecp_group grp;
    mbedtls_mpi N, Ns;
    uint8_t bf[56];
    static const unsigned char curve448_part_of_n[] = {
        0x83, 0x35, 0xDC, 0x16, 0x3B, 0xB1, 0x24,
        0xB6, 0x51, 0x29, 0xC9, 0x6F, 0xDE, 0x93,
        0x3D, 0x8D, 0x72, 0x3A, 0x70, 0xAA, 0xDC,
        0x87, 0x3D, 0x6D, 0x54, 0xA7, 0xBB, 0x0D,
    };
    
    mbedtls_mpi_init( &N );
    mbedtls_mpi_init( &Ns );
    mbedtls_ecp_group_init( &grp );
    
    /* N = 2^446 - 0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d */
    MBEDTLS_MPI_CHK( mbedtls_mpi_set_bit( &N, 446, 1 ) );
    MBEDTLS_MPI_CHK( mbedtls_mpi_read_binary( &Ns,
                        curve448_part_of_n, sizeof( curve448_part_of_n ) ) );
    MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &N, &N, &Ns ) );
    
    MBEDTLS_MPI_CHK( mbedtls_ecp_group_load( &grp, MBEDTLS_ECP_DP_CURVE448 ) );
    
    printf( "Are equal? %s\n\n", mbedtls_mpi_cmp_mpi( &N, &grp.N ) == 0 ? "YES!" : "Oh no... :(" );

    mbedtls_mpi_write_binary( &grp.N, bf, sizeof( bf ) );
    DEBUG_BUF( bf, sizeof( bf ) );
    mbedtls_mpi_write_binary( &N, bf, sizeof( bf ) );
    DEBUG_BUF( bf, sizeof( bf ) );
    cleanup:
    mbedtls_mpi_free( &N );
    mbedtls_mpi_free( &Ns );
    return 0;
}

I am not sure if it fits to you.

@gilles-peskine-arm
Copy link
Contributor

It would be nice to have this as a unit test, generalized to all the curves and values. Murphy's law: even with something as simple as a constant, if it's possible to get it wrong, sooner or later somebody will.

@mpg
Copy link
Contributor

mpg commented May 9, 2022

How do you usually backport bugfixes?

By creating new PR(s) for the supported branch(es) - currently, that's only mbedtls-2.28 as Tom mentioned. (See for example #5733 which is the backport of #5732.)

@gilles-peskine-arm gilles-peskine-arm removed the needs-ci Needs to pass CI tests label May 13, 2022
ccli8 added a commit to ccli8/mbed-os that referenced this pull request May 24, 2022
1.  Replace ecp.c full-module, and other ec modules dependent on ecp.c (ecdh.c/ecdsa.c/ecjpake.c) will improve followingly.
2.  Recover from Crypto ECC H/W failure:
    (1) Enable timed-out wait to escape from ECC H/W trap
    (2) On ECC H/W timeout, stop this ECC H/W operation
    (3) Fall back to S/W implementation on failure
3.  Support Short Weierstrass curve
    NOTE: ECC H/W will trap on m*P with SCAP enabled, esp m = 2 or close to (order - 1).
          Cannot work around by fallback to S/W, because following operations are easily to fail with data error.
          Disable SCAP temporarily.
4.  Support Montgomery curve
    Montgomery curve has the form: B y^2 = x^3 + A x^2 + x
    (1) In S/W impl, A is used as (A + 2) / 4. Figure out its original value for engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L219-L220
    (2) In S/W impl, B is unused. Actually, B is 1 for Curve25519/Curve448 and needs to configure to engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L221-L222
    (3) In S/W impl, y-coord is absent, but engine needs it. Deduce it from x-coord following:
        https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html
        https://www.rieselprime.de/ziki/Modular_square_root
    NOTE: Fix Curve448 has wrong order value
          Mbed-TLS/mbedtls#5811
ccli8 added a commit to OpenNuvoton/mbed that referenced this pull request May 24, 2022
In loading Curve448, MPI N is in uninitialized state and its sign flag N.s isn't initialized to 1.
This is fixed by following:
Mbed-TLS/mbedtls#5811
ccli8 added a commit to ccli8/mbed-os that referenced this pull request May 24, 2022
1.  Replace ecp.c full-module, and other ec modules dependent on ecp.c (ecdh.c/ecdsa.c/ecjpake.c) will improve followingly.
2.  Recover from Crypto ECC H/W failure:
    (1) Enable timed-out wait to escape from ECC H/W trap
    (2) On ECC H/W timeout, stop this ECC H/W operation
    (3) Fall back to S/W implementation on failure
3.  Support Short Weierstrass curve
4.  Support Montgomery curve
    Montgomery curve has the form: B y^2 = x^3 + A x^2 + x
    (1) In S/W impl, A is used as (A + 2) / 4. Figure out its original value for engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L219-L220
    (2) In S/W impl, B is unused. Actually, B is 1 for Curve25519/Curve448 and needs to configure to engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L221-L222
    (3) In S/W impl, y-coord is absent, but engine needs it. Deduce it from x-coord following:
        https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html
        https://www.rieselprime.de/ziki/Modular_square_root
    NOTE: Fix Curve448 has wrong order value
          Mbed-TLS/mbedtls#5811
ccli8 added a commit to ccli8/mbed-os that referenced this pull request May 26, 2022
1.  Replace ecp.c full-module, and other ec modules dependent on ecp.c (ecdh.c/ecdsa.c/ecjpake.c) will improve followingly.
2.  Recover from Crypto ECC H/W failure:
    (1) Enable timed-out wait to escape from ECC H/W trap
    (2) On ECC H/W timeout, stop this ECC H/W operation
    (3) Fall back to S/W implementation on failure
3.  Support Short Weierstrass curve
4.  Support Montgomery curve
    Montgomery curve has the form: B y^2 = x^3 + A x^2 + x
    (1) In S/W impl, A is used as (A + 2) / 4. Figure out its original value for engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L219-L220
    (2) In S/W impl, B is unused. Actually, B is 1 for Curve25519/Curve448 and needs to configure to engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L221-L222
    (3) In S/W impl, y-coord is absent, but engine needs it. Deduce it from x-coord following:
        https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html
        https://www.rieselprime.de/ziki/Modular_square_root
    NOTE: Fix Curve448 has wrong order value
          Mbed-TLS/mbedtls#5811
@daverodgman daverodgman added the bug label Jun 6, 2022
@daverodgman daverodgman added this to To Do in Roadmap Board for Mbed TLS via automation Jun 6, 2022
ccli8 added a commit to ccli8/mbed-os that referenced this pull request Jun 17, 2022
1.  Replace ecp.c full-module, and other ec modules dependent on ecp.c (ecdh.c/ecdsa.c/ecjpake.c) will improve followingly.
2.  Recover from Crypto ECC H/W failure:
    (1) Enable timed-out wait to escape from ECC H/W trap
    (2) On ECC H/W timeout, stop this ECC H/W operation
    (3) Fall back to S/W implementation on failure
3.  Support Short Weierstrass curve
4.  Support Montgomery curve
    Montgomery curve has the form: B y^2 = x^3 + A x^2 + x
    (1) In S/W impl, A is used as (A + 2) / 4. Figure out its original value for engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L219-L220
    (2) In S/W impl, B is unused. Actually, B is 1 for Curve25519/Curve448 and needs to configure to engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L221-L222
    (3) In S/W impl, y-coord is absent, but engine needs it. Deduce it from x-coord following:
        https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html
        https://www.rieselprime.de/ziki/Modular_square_root
    NOTE: Fix Curve448 has wrong order value
          Mbed-TLS/mbedtls#5811
@daverodgman daverodgman added needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review needs-preceding-pr Requires another PR to be merged first labels Jun 17, 2022
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
@daverodgman daverodgman added needs-backports Backports are missing or are pending review and approval. and removed needs-work needs-preceding-pr Requires another PR to be merged first labels Jun 17, 2022
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
@daverodgman daverodgman removed the needs-ci Needs to pass CI tests label Jun 19, 2022
Copy link
Contributor

@AndrzejKurek AndrzejKurek left a comment

Choose a reason for hiding this comment

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

Looks good. I can confirm that without this fix the ECP check order for CURVE448 fails.

@bensze01 bensze01 moved this from To Do to Has Approval in Roadmap Board for Mbed TLS Jun 24, 2022
Copy link
Contributor

@tom-cosgrove-arm tom-cosgrove-arm left a comment

Choose a reason for hiding this comment

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

LGTM

@tom-cosgrove-arm tom-cosgrove-arm removed needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review labels Jun 27, 2022
@mpg mpg added the approved Design and code approved - may be waiting for CI or backports label Jun 27, 2022
@daverodgman daverodgman merged commit f5b7082 into Mbed-TLS:development Jun 27, 2022
Roadmap Board for Mbed TLS automation moved this from Has Approval to Done Jun 27, 2022
@@ -4737,6 +4737,8 @@ int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id )
ECP_VALIDATE_RET( grp != NULL );
mbedtls_ecp_group_free( grp );

Choose a reason for hiding this comment

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

Please explain to me how it can be right to free the grp and then init it right after that?
https://os.mbed.com/teams/sandbox/code/mbedtls/docs/tip/ecp_8c_source.html#l00321

Clearly shows everything gets freed after that.
What am I missing here?

As far as I can understand this will essentially set the already freed memory region to zero.

Copy link
Contributor

Choose a reason for hiding this comment

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

The version you point to is 2.2.0. There's a different behaviour in current development:

void mbedtls_ecp_group_init( mbedtls_ecp_group *grp )

Please see #5810 (comment) for more details.

multiplemonomials pushed a commit to mbed-ce/mbed-os that referenced this pull request Jul 9, 2022
In loading Curve448, MPI N is in uninitialized state and its sign flag N.s isn't initialized to 1.
This is fixed by following:
Mbed-TLS/mbedtls#5811
ccli8 added a commit to ccli8/mbed-os that referenced this pull request Jul 15, 2022
1.  Replace ecp.c full-module, and other ec modules dependent on ecp.c (ecdh.c/ecdsa.c/ecjpake.c) will improve followingly.
2.  Recover from Crypto ECC H/W failure:
    (1) Enable timed-out wait to escape from ECC H/W trap
    (2) On ECC H/W timeout, stop this ECC H/W operation
    (3) Fall back to S/W implementation on failure
3.  Support Short Weierstrass curve
4.  Support Montgomery curve
    Montgomery curve has the form: B y^2 = x^3 + A x^2 + x
    (1) In S/W impl, A is used as (A + 2) / 4. Figure out its original value for engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L219-L220
    (2) In S/W impl, B is unused. Actually, B is 1 for Curve25519/Curve448 and needs to configure to engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L221-L222
    (3) In S/W impl, y-coord is absent, but engine needs it. Deduce it from x-coord following:
        https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html
        https://www.rieselprime.de/ziki/Modular_square_root
    NOTE: Fix Curve448 has wrong order value
          Mbed-TLS/mbedtls#5811
ccli8 added a commit to ccli8/mbed-os that referenced this pull request Jul 26, 2022
1.  Replace ecp.c full-module, and other ec modules dependent on ecp.c (ecdh.c/ecdsa.c/ecjpake.c) will improve followingly.
2.  Recover from Crypto ECC H/W failure:
    (1) Enable timed-out wait to escape from ECC H/W trap
    (2) On ECC H/W timeout, stop this ECC H/W operation
    (3) Fall back to S/W implementation on failure
3.  Support Short Weierstrass curve
4.  Support Montgomery curve
    Montgomery curve has the form: B y^2 = x^3 + A x^2 + x
    (1) In S/W impl, A is used as (A + 2) / 4. Figure out its original value for engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L219-L220
    (2) In S/W impl, B is unused. Actually, B is 1 for Curve25519/Curve448 and needs to configure to engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L221-L222
    (3) In S/W impl, y-coord is absent, but engine needs it. Deduce it from x-coord following:
        https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html
        https://www.rieselprime.de/ziki/Modular_square_root
    NOTE: Fix Curve448 has wrong order value
          Mbed-TLS/mbedtls#5811
ccli8 added a commit to ccli8/mbed-os that referenced this pull request Aug 4, 2022
1.  Replace ecp.c full-module, and other ec modules dependent on ecp.c (ecdh.c/ecdsa.c/ecjpake.c) will improve followingly.
2.  Recover from Crypto ECC H/W failure:
    (1) Enable timed-out wait to escape from ECC H/W trap
    (2) On ECC H/W timeout, stop this ECC H/W operation
    (3) Fall back to S/W implementation on failure
3.  Support Short Weierstrass curve
4.  Support Montgomery curve
    Montgomery curve has the form: B y^2 = x^3 + A x^2 + x
    (1) In S/W impl, A is used as (A + 2) / 4. Figure out its original value for engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L219-L220
    (2) In S/W impl, B is unused. Actually, B is 1 for Curve25519/Curve448 and needs to configure to engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L221-L222
    (3) In S/W impl, y-coord is absent, but engine needs it. Deduce it from x-coord following:
        https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html
        https://www.rieselprime.de/ziki/Modular_square_root
    NOTE: Fix Curve448 has wrong order value
          Mbed-TLS/mbedtls#5811
ccli8 added a commit to ccli8/mbed-os that referenced this pull request Sep 1, 2022
1.  Replace ecp.c full-module, and other ec modules dependent on ecp.c (ecdh.c/ecdsa.c/ecjpake.c) will improve followingly.
2.  Recover from Crypto ECC H/W failure:
    (1) Enable timed-out wait to escape from ECC H/W trap
    (2) On ECC H/W timeout, stop this ECC H/W operation
    (3) Fall back to S/W implementation on failure
3.  Support Short Weierstrass curve
4.  Support Montgomery curve
    Montgomery curve has the form: B y^2 = x^3 + A x^2 + x
    (1) In S/W impl, A is used as (A + 2) / 4. Figure out its original value for engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L219-L220
    (2) In S/W impl, B is unused. Actually, B is 1 for Curve25519/Curve448 and needs to configure to engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L221-L222
    (3) In S/W impl, y-coord is absent, but engine needs it. Deduce it from x-coord following:
        https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html
        https://www.rieselprime.de/ziki/Modular_square_root
    NOTE: Fix Curve448 has wrong order value
          Mbed-TLS/mbedtls#5811
multiplemonomials added a commit to mbed-ce/mbed-os that referenced this pull request Jan 1, 2023
* Fix for calculating CAN timing settings.

NominalPrescaler value needs to be as high as possible to ensure a good approximation of the target CAN speed.
Previous usage of macro IS_FDCAN_DATA_TSEG1 refers to (unsupported by Mbed ) FDCAN CAN controller settings and leads to too low prescaler values.
Usage Macro IS_FDCAN_NOMINAL_TSEG1 yields optimum results.
See also correct macro usage in line #158.

* Add complete support of DHCP relay interface ID option

RFC3315 specifies the following: "The relay agent MAY send the Interface-id
option to identify the interface on which the client message was received.
If a relay agent  receives a Relay-reply message with an Interface-id
option, the relay agent relays the message to the client through the
interface identified by the option."

The current implementation of the DHCP relay reply handling, the interface
ID field from the server response is ignored. Managing the interface ID
is very important especially as DHCP requests/replies use link-local
addresses. The consequence of this is that the interface must always be
specified because the routing layer cannot guess the correct interface.
Moreover, Mbed provides a mechanism to enable/disable the interface ID
option on a DHCP relay instance, so it is important to fully support it.

The reason why this issue has not been discoverd until now is that the DHCP
relay is mainly used on systems that use only one interface (such as Wi-SUN
routers). By default, when no interface ID is specified for the socket, the
latter will choose 6loWPAN interface by default. This means that if two
interfaces are used on the same device, the 6loWPAN interface is always
selected.

The commit adds code to retrieve the interface-id value contained within
the DHCP relay reply message and write it to a control message header
that is added to the socket message. This tells the socket which
interface to choose. If the interface-id option is not enabled on the
relay, this procedure is simply ignored.

* Support Nuvoton target NUMAKER_IOT_M467

1.  Based on alpha version BSP (85564a2716548e7b6d6a79a490c6d94a24cf9bcf)
2.  Continuing above, tweak BSP:
    (1) Add EPWM_ConfigOutputChannel2() to enable below 1Hz and below 1% duty cycle for PWM output (m460_epwm.h/c).
    (2) Add dummy RTC_WaitAccessEnable() for consistency with previous ports (m460_rtc.h).
3.  Target NuMaker-M467HJ V0.1 board temporarily
4.  Support Arduino UNO form factor for NUMAKER_IOT_M467 target
5.  Enable export to Keil/IAR project
    -   tools/arm_pack_manager/index.json
    -   tools/export/iar/iar_definitions.json

* M467: Fix Greentea reset_reason test failure

HRESETRF is combined reset flag. Filter it out to avoid interference with reset reason check.

* M467: Support HyperRAM

1.  For GCC, support multi-block .data/.bss initialization
2.  HyperRAM is mapped to two regions: 0x0A000000 and 0x80000000
    According to default system address map, 0x0A000000 is located at 'Code' region and 0x80000000 at 'RAM' region.
    With MPU enabled on Mbed OS, 'Code' region is write-never and 'RAM' region execute-never.
    0x80000000 is chosen because 'RAM' regioin is naturally for HyperRAM.
3.  Configurable multi-function pins for HBI
4.  To locate code/data at external HyperRAM:
    -   Specify __attribute__((section(".text.nu.exthyperram"))) for RO/.text/readonly section type
        Invoke mbed_mpu_manager_lock_ram_execution()/mbed_mpu_manager_unlock_ram_execution() to run HyperRAM code
    -   Specify __attribute__((section(".data.nu.exthyperram"))) for RW/.data/readwrite section type
    -   Specify __attribute__((section(".bss.nu.exthyperram"))) for ZI/.bss/zeroinit section type
5.  Add readme

* Config for M460 EMAC

* Add M460 EMAC driver

* Adjust M460 EMAC RX/TX buffer

* M467: Fix EMAC compile error with IAR

* M467: Support Crypto SHA/ECC H/W

1.  Prepare crypto common code
2.  Support list
    -   SHA
    -   ECC
    NOTE: AES/RSA are to support in other works
    NOTE: Compared to M487, M467's SHA supports context save & restore (DMA Cascade mode) and so no software fallback is needed.
    NOTE: M467's ECC, following M487, goes partial-module replacement and it can just improve primitives e.g. point addition/doubling by 2X,
          and cannot improve high level point multiplication because MbedTLS doesn’t open it.
          To improve performance best, full-module replacement is needed.
    NOTE: Continuing above, add support for Montgomery curve

* M467 H/W AES self-test pass

* M467 Support crypto GCM H/W

* M467: GCM support one simple mode instead of using composite GHASH & CTR MODE

* Update M467 AES-GCM to pass AWS-IoT test

* Update M467 AES-GCM for H/W gcm in-buffer creteria

* M467: Improve Crypto H/W wait helper routine

Add crypto_xxx_wait2 helper routine to replace crypto_xxx_wait for Crypto H/W control

* M467: Seed PRNG with TRNG for SCAP

According to TRM, it is suggested PRNG be seeded by TRNG on every Crypto H/W reset.

* M467: Support Crypto RSA H/W

1.  Crypto RSA H/W supports 1024/2048/3072/4096 key bits. Fall back to software implementation for other key bits.
2.  For decrypt, if MBEDTLS_RSA_NO_CRT isn't defined, go CRT, or normal.
3.  For decrypt, when blinding (f_rng != NULL), enable SCAP mode.
4.  Recover from Crypto RSA H/W failure:
    (1) Enable timed-out wait to escape from RSA H/W trap
    (2) On RSA H/W timeout, stop this RSA H/W operation
    (3) Fall back to S/W implementation on failure

NOTE: RSA 4096 key bits can fail with default mbedtls configuration MBEDTLS_MPI_MAX_SIZE.
      Enlarge MBEDTLS_MPI_MAX_SIZE to 1024 or larger if this feature is required.
NOTE: Fixed in BSP RSA driver, for non-CRT+SCAP mode, temporary buffer for MADDR6 requires to be key length plus 128 bits.
NOTE: Fixed in BSP RSA driver, DMA buffer must be 4-word aligned, or RSA H/W will trap.

* M467 Support crypto AES-CCM H/W with one-shot & cascade mode

* M467: Support Crypto ECC H/W in full-module replacement

1.  Replace ecp.c full-module, and other ec modules dependent on ecp.c (ecdh.c/ecdsa.c/ecjpake.c) will improve followingly.
2.  Recover from Crypto ECC H/W failure:
    (1) Enable timed-out wait to escape from ECC H/W trap
    (2) On ECC H/W timeout, stop this ECC H/W operation
    (3) Fall back to S/W implementation on failure
3.  Support Short Weierstrass curve
4.  Support Montgomery curve
    Montgomery curve has the form: B y^2 = x^3 + A x^2 + x
    (1) In S/W impl, A is used as (A + 2) / 4. Figure out its original value for engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L219-L220
    (2) In S/W impl, B is unused. Actually, B is 1 for Curve25519/Curve448 and needs to configure to engine.
        https://github.com/ARMmbed/mbed-os/blob/2eb06e76208588afc6cb7580a8dd64c5429a10ce/connectivity/mbedtls/include/mbedtls/ecp.h#L221-L222
    (3) In S/W impl, y-coord is absent, but engine needs it. Deduce it from x-coord following:
        https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html
        https://www.rieselprime.de/ziki/Modular_square_root
    NOTE: Fix Curve448 has wrong order value
          Mbed-TLS/mbedtls#5811

* M467: Disable SCAP in RSA H/W

This is to follow designer's resolution.

* M467: support fullspeed usb device

* M467: Fix mbedtls_ecp_point_cmp() call with null argument

Guard from null argument passed to mbedtls_ecp_point_cmp() in ECC H/W port

* M467: Make mbedtls H/W port removable

Some M460 chips don't support AES/SHA/ECC/RSA H/W.
Make them removable from mbedtls H/W port through '"target.macros_remove": ["MBEDTLS_CONFIG_HW_SUPPORT"]'.

* Added TMPM4NR Platform

New Platform for Toshiba Added

* Removed UTF8 Chars

* M467: I2C: Fix potential role switch failure

Fix in i2c_do_trsn(), interrupt doesn't change back to enabled due to premature return.

* M467: Exclude UNO SPI pins from FPGA CI Test Shield test

UNO D8/D9/D10/D11/D12/D13 can wire to on-board SPI flash.
Exclude these pins from FPGA CI Test Shield test.

* M467: Adjust UART pinmap to pass FPGA CI Test Shield test

* M467: Support NuMaker-IoT-M467 board

Pinout comparison between NuMaker-M467HJ and NuMaker-IoT-M467 boards:
1.  UNO are unchanged
2.  LEDs are unchanged
3.  Buttons are unchanged, except button names
4.  NuMaker-M467HJ has HBI but NuMaker-IoT-M467 does
5.  NuMaker-M467HJ doesn't have ESP8266 but NuMaker-IoT-M467 does
6.  SDHC are unchanged

* Nuvoton: I2C: Fix potential role switch failure

Fix in i2c_do_trsn(), interrupt doesn't change back to enabled due to premature return.

Fix targets:
-   NUMAKER_PFM_NANO130
-   NUMAKER_PFM_NUC472
-   NUMAKER_PFM_M453
-   NUMAKER_PFM_M487/NUMAKER_IOT_M487
-   NUMAKER_IOT_M252
-   NUMAKER_IOT_M263A
-   NU_M2354

* Update can_api.c

Modified comment as discussed.

* M467: Remove invalid UTF-8 byte sequence

* Replace MAX32660, MAX32670 I2C driver with final one in MSDK
- apply clang-format
- Fix i2c repeated start issue

Signed-off-by: Sadik.Ozer <sadik.ozer@analog.com>

* Add proper support for NUCLEO-H723ZG.

- add board specific EMAC setup to connectivity/drivers/emac/TARGET_STM/TARGET_STM32H7
  - stm32h7_eth_init.c was derived from the NUCLEO-H743ZI2 code whilst comparing to the output of STM32CubeIDE
- complete board specific code in targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H723xG
  - PeripheralPins.c and PinNames.h were created by targets/TARGET_STM/tools/STM32_gen_PeripheralPins.py
  - ST ZIO connector pins in PinNames.h have been adapted from NUCLEO-H743ZI2
  - CONSOLE_TX and CONSOLE_RX have been interchanged in PinNames.h to match the actual board layout
  - startup_stm32h723xx.S was derived from startup_stm32h743xx.S
  - stm32h723xg.ld was completely rewritten to match the actual MCU including:
    - split heap support
    - SRAM2 and SRAM4 support
    - crash dump support
    - proper use of DTCM as stack
  - system_clock.c has been changed to support the maximal main clock speed of 550 MHz
- fix handling of HS in FS mode for the target board in targets/TARGET_STM/USBPhy_STM32.cpp
- add board definition to targets/targets.json and correct linker setup for the chip

Signed-off-by: Daniel Starke <daniel-email@gmx.net>

* Fix I2C for MCU_STM32H723xG

Add I2C configuration to MCU_STM32H723xG in target.json as suggested by @jeromecoutant.

Signed-off-by: Daniel Starke <daniel-email@gmx.net>

* Correct MAX32620 boards macro for USB library.

* Limit NUCLEO_H723ZG toolchain to GCC_ARM

Limit NUCLEO_H723ZG toolchain to GCC_ARM only.
This is the only toolchain this target has been tested with yet.

Signed-off-by: Daniel Starke <daniel-email@gmx.net>

* M2354 support FS-USBD and update TF-M for USB PHY select

* Rethink STM32 I2C v2 HAL

* Add documentation for I2C_EVENT macros

* Add some additional I2C error codes

* Added TMPM4GR Platform

New Platform for Toshiba Added

* Resolve delimeter issues for target.json

* Fix compile error on static pinmap targets

* github: Fix click version

Signed-off-by: Martin Kojtal <martin.kojtal@arm.com>

Signed-off-by: Sadik.Ozer <sadik.ozer@analog.com>
Signed-off-by: Daniel Starke <daniel-email@gmx.net>
Signed-off-by: Martin Kojtal <martin.kojtal@arm.com>
Co-authored-by: chdelfs <109847651+chdelfs@users.noreply.github.com>
Co-authored-by: YannCharbon <yann.charbon@ik.me>
Co-authored-by: Chun-Chieh Li <ccli8@nuvoton.com>
Co-authored-by: cyliangtw <cyliang@nuvoton.com>
Co-authored-by: Deepak V. Shreshti <DeepakVS@TOSHIBA-TSIP.COM>
Co-authored-by: Martin Kojtal <martin.kojtal@arm.com>
Co-authored-by: Sadik.Ozer <sadik.ozer@analog.com>
Co-authored-by: Daniel Starke <daniel-email@gmx.net>
Co-authored-by: Ahmet Alincak <Ahmet.Alincak@maximintegrated.com>
Co-authored-by: Jamie Smith <smit109@usc.edu>
Co-authored-by: Jamie Smith <jsmith@crackofdawn.onmicrosoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports bug component-crypto Crypto primitives and low-level interfaces needs-backports Backports are missing or are pending review and approval. priority-medium Medium priority - this can be reviewed as time permits size-s Estimated task size: small (~2d)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Curve x448 has wrong order value
8 participants