org.bouncycastle.crypto.test
Class ConstantTimeUsageTest
java.lang.Object
org.bouncycastle.util.test.SimpleTest
org.bouncycastle.crypto.test.ConstantTimeUsageTest
- All Implemented Interfaces:
- Test
- public class ConstantTimeUsageTest
- extends SimpleTest
Checks that the code paths handling a secret scalar still reach for BouncyCastle's hardened
arithmetic rather than the variable-time defaults.
The substitutions guarded here - BigInteger.modInverse to BigIntegers.modOddInverse,
add([]).mod([]) to BigIntegers.modAdd, and the default point multiplier to the secure one -
all preserve the result, so no functional test can tell whether they are in place: the KAT
vectors and the round-trips pass either way, which is exactly why the substitutions can be
undone by an unrelated edit without anything going red. What is left to look at is the compiled
form, so this test reads each class file back and checks the symbols its constant pool must and
must not contain.
Note what this does and does not establish. It says a named call is still being made; it says
nothing about whether the surrounding code is constant time, and it cannot see a secret that
reaches a variable-time operation by some other route. It is a regression gate for four specific
call sites, not a proof.
A scan that quietly reads nothing would pass every "must not contain" check, so the controls in
#checkControls() are load bearing: they run the same scan over a class in this file that
deliberately calls BigInteger.modInverse, and fail if it is not flagged.
| Methods inherited from class org.bouncycastle.util.test.SimpleTest |
areEqual, areEqual, areEqual, fail, fail, fail, isEquals, isEquals, isEquals, isEquals, isEquals, isEquals, isEquals, isTrue, isTrue, perform, runTest, runTest, runTests, runTests, testException |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ConstantTimeUsageTest
public ConstantTimeUsageTest()
getName
public java.lang.String getName()
- Specified by:
getName in interface Test- Specified by:
getName in class SimpleTest
performTest
public void performTest()
throws java.lang.Exception
- Specified by:
performTest in class SimpleTest
- Throws:
java.lang.Exception
main
public static void main(java.lang.String[] args)