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

MicroBlaze does not return from mbedtls_pk_parse_key with MBEDTLS_HAVE_ASM defined #2020

Closed
IsaacJT opened this issue Sep 18, 2018 · 4 comments · Fixed by #4686
Closed

MicroBlaze does not return from mbedtls_pk_parse_key with MBEDTLS_HAVE_ASM defined #2020

IsaacJT opened this issue Sep 18, 2018 · 4 comments · Fixed by #4686
Labels
bug component-crypto Crypto primitives and low-level interfaces help-wanted This issue is not being actively worked on, but PRs welcome.

Comments

@IsaacJT
Copy link

IsaacJT commented Sep 18, 2018

Description

  • Type: Bug
  • Priority: Major

Bug

OS
FreeRTOS

mbed TLS build:
Version: 2.12.0
OS version: 10.0
Configuration:
mbedtls_freertos.txt
Compiler and options (if you used a pre-built binary, please indicate how you obtained it): GCC 7.2.0 from Xilinx SDK 2018.1. Compiled with: -O2 -mcpu=v10.0 -mxl-multiply-high -mno-xl-soft-div -mno-xl-soft-mul -mxl-barrel-shift -mxl-pattern-compare
Additional environment information: we are also using Mongoose web server. The MicroBlaze has been built with multiplier and divider hardware, branch prediction, and data and instruction caches.

Expected behavior
When parsing a buffer with mbedtls_pk_parse_key, the function should return.

Actual behavior
The mbedtls_pk_parse_key never returns, and is stuck performing the multiplication in bignum.c.

The function executes and returns correctly when compiling without MBEDTLS_HAVE_ASM defined.

Steps to reproduce
Attempt to parse a key with mbedtls_pk_parse_key on a MicroBlaze with MBEDTLS_HAVE_ASM defined.

@IsaacJT
Copy link
Author

IsaacJT commented Sep 18, 2018

The application gets stuck in the do while loop here: https://github.com/ARMmbed/mbedtls/blob/6c34268e203d23bbfbfda3f7362dac8b9b9382bc/library/bignum.c#L1407

The mbedtls_mpi_cmp_mpi function always returns 1.

@IsaacJT IsaacJT changed the title MicroBlaze does not return from multiplication function with MBEDTLS_HAVE_ASM defined MicroBlaze does not return from mbedtls_pk_parse_key with MBEDTLS_HAVE_ASM defined Sep 18, 2018
@simonbutcher simonbutcher added bug tracking component-crypto Crypto primitives and low-level interfaces labels Sep 21, 2018
@ciarmcom
Copy link

ARM Internal Ref: IOTSSL-2540

@Patater Patater added the help-wanted This issue is not being actively worked on, but PRs welcome. label Oct 11, 2018
@Patater
Copy link
Contributor

Patater commented Oct 11, 2018

Hi @IsaacJT

Thanks for your bug report. We unfortunately don't have a way to reproduce this issue, so I've marked this as open for community contribution.

Thanks!

@RonEld RonEld removed the tracking label Jun 11, 2019
Kazuyuki-Kimura pushed a commit to Kazuyuki-Kimura/mbedtls that referenced this issue May 31, 2021
Fixed a bug that the little-endian Microblaze does not work when MBEDTLS_HAVE_ASM is defined.
Kazuyuki-Kimura pushed a commit to Kazuyuki-Kimura/mbedtls that referenced this issue May 31, 2021
Fixed a bug that the little-endian Microblaze does not work when MBEDTLS_HAVE_ASM is defined.

Signed-off-by: Kazuyuki-kimura <[email protected]>
Kazuyuki-Kimura pushed a commit to Kazuyuki-Kimura/mbedtls that referenced this issue Jun 1, 2021
Fixed a bug that the little-endian Microblaze does not work when MBEDTLS_HAVE_ASM is defined.

Signed-off-by: Kazuyuki-kimura <[email protected]>
Signed-off-by: Kazuyuki Kimura <[email protected]>
Kazuyuki-Kimura pushed a commit to Kazuyuki-Kimura/mbedtls that referenced this issue Jun 1, 2021
Fixed a bug that the little-endian Microblaze does not work when MBEDTLS_HAVE_ASM is defined.

Signed-off-by: Kazuyuki Kimura <[email protected]>
Kazuyuki-Kimura pushed a commit to Kazuyuki-Kimura/mbedtls that referenced this issue Jul 9, 2021
Fixed a bug that the little-endian Microblaze does not work when MBEDTLS_HAVE_ASM is defined.

Signed-off-by: Kazuyuki Kimura <[email protected]>
@Eurecam-Benjamin
Copy link

I also runned into this issue when using mbedtls on a microblaze.
I am no microblaze guru but I further analyse the code by comparing it to the default C fallback :

  • There is indeed a little/big endian problem when using "lhui" instruction -> I replaced it with "lwi" and masking / shifting value to upper and lower bits
  • To me, there are also some typo with r0 register confused with 0 number.
  • And last, some registers where swapped.

The attached diff file fixes include/mbedtls/nb_mul.h in branche 2.16
The lines number doesn't match but it works also with 2.28 and almost certainly with the newer 3.1 as they share the code.

fix_bn_mul.txt

daverodgman pushed a commit to Kazuyuki-Kimura/mbedtls that referenced this issue May 30, 2022
Fixed a bug that the little-endian Microblaze does not work when MBEDTLS_HAVE_ASM is defined.

Signed-off-by: Kazuyuki Kimura <[email protected]>
Signed-off-by: Dave Rodgman <[email protected]>
daverodgman pushed a commit to daverodgman/mbedtls that referenced this issue Jul 29, 2022
Fixed a bug that the little-endian Microblaze does not work when MBEDTLS_HAVE_ASM is defined.

Signed-off-by: Kazuyuki Kimura <[email protected]>
Signed-off-by: Dave Rodgman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug component-crypto Crypto primitives and low-level interfaces help-wanted This issue is not being actively worked on, but PRs welcome.
Projects
None yet
7 participants