Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
/* Example code for bug CVE-2016-1938 in mp_exptmod()
* author: Hanno Böck, license: CC0 / public domain
*
* This shows that a bug in the mp_div() function of nss can also produce wrong results
* in mp_exptmod().
* Two calculations are compared: Directly calling mp_exptmod() and calling mp_expt()
* and mp_mod() separately. A correct implementation should always produce the same
* result.
*/
#define MP_IOFUNC 1
#include <mpi/mpi.h>
#define MI "0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0EED0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F7C000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
#define AI "80"
#define BI "fc"
int main()
{
mp_int an, bn, mn, r1, r2, xn;
mp_init(&an);
mp_init(&bn);
mp_init(&mn);
mp_init(&r1);
mp_init(&xn);
mp_init(&r2);
mp_read_radix(&an, AI, 16);
mp_read_radix(&bn, BI, 16);
mp_read_radix(&mn, MI, 16);
mp_exptmod(&an, &bn, &mn, &r2);
mp_expt(&an, &bn, &xn);
mp_mod(&xn, &mn, &r1);
mp_print(&r1, stdout);
printf("\n");
mp_print(&r2, stdout);
printf("\n");
if (mp_cmp(&r1, &r2) != 0)
printf("results don't match\n");
else
printf("results match\n");
mp_clear(&an);
mp_clear(&bn);
mp_clear(&mn);
mp_clear(&r1);
mp_clear(&r2);
mp_clear(&xn);
return 0;
}