mp_div and mp_exptmod sometimes produce wrong calculation results
Originally disclosed on Mozilla
- Fixed in 23 days
- Paid in 9 months
- Disclosed after 23 days
Created attachment 8642239
sample c code showing mpi_div failure
Sometimes calculations with mp_div produce wrong results. An example is this:
0x10000000000000001000000000000000000000 / 0x10000000000000001001
(both numbers are hex)
This should produce
0xFFFFFFFFFFFFFFFFFF
However mp_div will produce
0xFFFFFFFFFFFFFFFFFE
I have attached a sample c code that will show this (compile libmpi.a and then compile with "gcc -I[path_to_freebl] [input] libmpi.a"). It will do a div calculation and then multiply the result with the divisor, add the modulus and then substract the original dividend. If the calculation would be correct this would always result in zero, no matter what the input values were.
While mp_div is not exposed via the nss api it is used within several crypto functions (rsa, dsa, diffie hellman), so this may have severe security impacts.
Here are some other values that will also result in wrong results:
801C4D3A9DE4691ADDBFC7D2D2DE2DA7114125A77FECE17FDA204B73FA3CDA4FF783AEE4453952BEF81DF7A9114125A700
801C4D3A9DE4691ADDBFC7D2D2DE2DA7114125A7CEF66E9B76BAC1
B7B7B7B7B7B7B7B7B7B7B7939393939393939393939393939393B7B7B7B7B7B70080FFFFC1B7BAB70001B7
B7B7B7B7B7B7B7B7B7B7C1B7BAB7DE00648B
BFC7D2E66986FFFCE1B4D2DEF82CBEF80000FADACE4B73F710AED25E000004001DE9BEF81DE91DE9A9556301F7A9551C
BFC7D2E66986FFFCE1B4D2DEF82CBEF81DE9A9556301F7A9551CBFC7D2E46986FFFCE1B4D2BAC1
I found these issues by comparing the results of openssl's bignum functions with the ones from nss. I then ran afl and fuzzed the inputs.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A high-severity security bug in Libraries. Mozilla made it public on 26 August 2015 as CVE-2016-1938.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.