Changeset f816324


Ignore:
Timestamp:
Oct 9, 2015 4:35:00 PM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
eec87bd
Parents:
6a0d421
Message:

NBI test improvements:

  • Try to prevent not-coprime errors
  • Minor cleanups
  • Javadoc fix

Fix build script typo

Location:
core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/c/jbigi/build_jbigi.sh

    r6a0d421 rf816324  
    6262
    6363[ $BITS -eq 32 ] && COMPILEFLAGS="-m32 $COMPILEFLAGS" && LINKFLAGS="-m32 $LINKFLAGS"
    64 [ $BITS -eq 64 ] && COMPILEFLAGS="-m64 $COMPILEFLAGS" && LINKFLqAGS="-m64 $LINKFLAGS"
     64[ $BITS -eq 64 ] && COMPILEFLAGS="-m64 $COMPILEFLAGS" && LINKFLAGS="-m64 $LINKFLAGS"
    6565
    6666echo "Compiling C code..."
  • core/java/src/net/i2p/util/NativeBigInteger.java

    r6a0d421 rf816324  
    794794
    795795    /**
    796      *  @parm mode 1: modPow; 2: modPowCT 3: modInverse
     796     *  @param mode 1: modPow; 2: modPowCT 3: modInverse
    797797     */
    798798    private static void runModPowTest(int numRuns, int mode, boolean nativeOnly) {
    799799        SecureRandom rand = RandomSource.getInstance();
    800800        /* the sample numbers are elG generator/prime so we can test with reasonable numbers */
    801         byte[] _sampleGenerator = CryptoConstants.elgg.toByteArray();
    802         byte[] _samplePrime = CryptoConstants.elgp.toByteArray();
    803 
    804         BigInteger jg = new BigInteger(_sampleGenerator);
    805         NativeBigInteger ng = new NativeBigInteger(_sampleGenerator);
    806         BigInteger jp = new BigInteger(_samplePrime);
     801        byte[] sampleGenerator = CryptoConstants.elgg.toByteArray();
     802        byte[] samplePrime = CryptoConstants.elgp.toByteArray();
     803
     804        BigInteger jg = new BigInteger(sampleGenerator);
     805        NativeBigInteger ng = CryptoConstants.elgg;
     806        BigInteger jp = new BigInteger(samplePrime);
    807807
    808808        long totalTime = 0;
     
    812812        for (int i = 0; i < 1000; i++) {
    813813            // JIT warmup
    814             BigInteger bi = new NativeBigInteger(16, rand);
     814            BigInteger bi;
     815            do {
     816                bi = new BigInteger(16, rand);
     817            } while (bi.signum() == 0);
    815818            if (mode == 1)
    816819                jg.modPow(bi, jp);
     
    821824        }
    822825        BigInteger myValue = null, jval;
     826        final NativeBigInteger g = CryptoConstants.elgg;
     827        final NativeBigInteger p = CryptoConstants.elgp;
     828        // Our ElG prime P is 1061 bits, so make K smaller so there's
     829        // no chance of it being equal to or a multiple of P, i.e. not coprime,
     830        // so the modInverse test won't fail
     831        final int numBits = (mode == 3) ? 1060 : 2048;
    823832        for (runsProcessed = 0; runsProcessed < numRuns; runsProcessed++) {
    824             BigInteger bi = new BigInteger(2048, rand); // 2048, rand); //
    825             NativeBigInteger g = new NativeBigInteger(_sampleGenerator);
    826             NativeBigInteger p = new NativeBigInteger(_samplePrime);
     833            // 0 is not coprime with anything
     834            BigInteger bi;
     835            do {
     836                bi = new BigInteger(numBits, rand);
     837            } while (bi.signum() == 0);
    827838            NativeBigInteger k = new NativeBigInteger(1, bi.toByteArray());
    828839            //// Native
Note: See TracChangeset for help on using the changeset viewer.