Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (45 sloc) 1.28 KB
/* 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;
}
You can’t perform that action at this time.