Changeset 3411a7c


Ignore:
Timestamp:
Oct 17, 2015 12:55:39 PM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
4e6ddfc
Parents:
70921a2
Message:

Crypto: Consolidate duplicate unlimited strength crypto check code

Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/crypto/CryptixAESEngine.java

    r70921a2 r3411a7c  
    4545    /** see test results below */
    4646    private static final int MIN_SYSTEM_AES_LENGTH = 704;
    47     private static final boolean USE_SYSTEM_AES;
    48     static {
    49         boolean systemOK = false;
    50         if (hasAESNI()) {
    51             try {
    52                 systemOK = Cipher.getMaxAllowedKeyLength("AES") >= 256;
    53             } catch (GeneralSecurityException gse) {
    54                 // a NoSuchAlgorithmException
    55             } catch (NoSuchMethodError nsme) {
    56                 // JamVM, gij
    57                 try {
    58                     Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
    59                     SecretKeySpec key = new SecretKeySpec(new byte[32], "AES");
    60                     cipher.init(Cipher.ENCRYPT_MODE, key);
    61                     systemOK = true;
    62                 } catch (GeneralSecurityException gse) {
    63                 }
    64             }
    65         }
    66         USE_SYSTEM_AES = systemOK;
    67         //System.out.println("Using system AES? " + systemOK);
    68     }
     47    private static final boolean USE_SYSTEM_AES = hasAESNI() && CryptoCheck.isUnlimited();
    6948
    7049    /**
  • router/java/src/net/i2p/router/tasks/CryptoChecker.java

    r70921a2 r3411a7c  
    66import javax.crypto.spec.SecretKeySpec;
    77
     8import net.i2p.crypto.CryptoCheck;
    89import net.i2p.crypto.SigType;
    910import net.i2p.router.RouterContext;
     
    5859                System.out.println(s);
    5960            }
    60             if (!isUnlimited()) {
     61            if (!CryptoCheck.isUnlimited()) {
    6162                s = "Please consider installing the Java Cryptography Unlimited Strength Jurisdiction Policy Files from ";
    6263                //if (SystemVersion.isJava8())
     
    8081    }
    8182
    82     /**
    83      *  Copied from CryptixAESEngine
    84      */
    85     private static boolean isUnlimited() {
    86         try {
    87             if (Cipher.getMaxAllowedKeyLength("AES") < 256)
    88                 return false;
    89         } catch (NoSuchAlgorithmException e) {
    90             return false;
    91         } catch (NoSuchMethodError e) {
    92             // JamVM, gij
    93             try {
    94                 Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
    95                 SecretKeySpec key = new SecretKeySpec(new byte[32], "AES");
    96                 cipher.init(Cipher.ENCRYPT_MODE, key);
    97             } catch (GeneralSecurityException gse) {
    98                 return false;
    99             }
    100         }
    101         return true;
    102     }
    103 
    10483    public static void main(String[] args) {
    10584        warnUnavailableCrypto(null);
Note: See TracChangeset for help on using the changeset viewer.