Arithmetic bug on ARM (STM 32 F4)

Titouan Coladon titouan.coladon at gmail.com
Fri Jan 22 10:59:43 UTC 2021


Thanks for your answer,

it's indeed, gcc that must have a bug.

The older bare metal version: gcc-arm-none-eabi-7-2017-q4-major-linux is
working properly.

Then the latest version : gcc-arm-none-eabi-8-2018-q4-major-linux,
gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux and
gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux all have the issue.

Thanks for your help,

Titouan Coladon

Le 21/01/2021 à 17:52, Titouan Coladon a écrit :
> Hi,
>
> I will try to describe as good as possible.
>
> The bug itself is really simple: The "mod" operation below gives a wrong
> result on stm32F4
>
>     mpz_t t; mpz_init(t);
>     mpz_t tt; mpz_init(tt);
>     mpz_t ttt; mpz_init(ttt);
>     mpz_set_str(tt,
> "25975415027868818028037643145183730078267964363630309107863975221668725232906664910091356673487591948237515304861352649057814029879720636142810833722202669061030484458925649047021859875730105532595466846094449735851132072400310565642",
> 10);
>     mpz_set_str(t,
> "6864797660130609714981900799081393217269435300143305409394463459185543183397655394245057746333217197532963996371363321113864768612440380340372808892707005449",
> 10);
>     mpz_mod(ttt, tt, t);
>     printf("tt = "); gmp_printf("%Zd", tt); printf("\n");
>     printf("t = "); gmp_printf("%Zd", t); printf("\n");
>     printf("ttt = "); gmp_printf("%Zd", ttt); printf("\n");
>     mpz_clear(t);
>     mpz_clear(tt);
>     mpz_clear(ttt);
>
>
> The result is:
>
> tt =
> 25975415027868818028037643145183730078267964363630309107863975221668725232906664910091356673487591948237515304861352649057814029879720636142810833722202669061030484458925649047021859875730105532595466846094449735851132072400310565642
> t =
> 6864797660130609714981900799081393217269435300143305409394463459185543183397655394245057746333217197532963996371363321113864768612440380340372808892707005449
> ttt =
> 3578942983869995381409279381784954092773488221200587338717407747084074518600438737913956360066709506626656635118978526559637095289631190671071178702312877654
>
> but ttt should be
> 5247183143879283565064056089869553515440215252945038779070795247972433237341511292686962488915110675351673985513318500576097977116134885013371639187873069514
>
>
> I give the code to reproduce the bug in attachment.
>
> GMP is built with the options:
> CC=/home/titouan/Softs/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc
> ../configure CFLAGS="-nostartfiles --specs=nosys.specs -mcpu=cortex-m4"
> --host=arm-none-eabi --disable-assembly --prefix=YOUR_CHOICE
>
> You also must change the PATHS variables at the beggining of the Makefile.
>
> Then classically burn on the stm32 board using openocd...
>
>
> The bug appears only with this size of number, based on arithmetic over
> the nist521 EC.
>
>
> Best regards,
>
>
> Titouan Coladon
>
>
>


More information about the gmp-bugs mailing list