-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCVE-2016-1938-nss-mp_exptmod.c
56 lines (45 loc) · 1.28 KB
/
CVE-2016-1938-nss-mp_exptmod.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* 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;
}