commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject commons-crypto git commit: Centralise AES_BLOCK_SIZE definition
Date Wed, 06 Jul 2016 08:57:56 GMT
Repository: commons-crypto
Updated Branches:
  refs/heads/master e045c163d -> 1ef0752c4


Centralise AES_BLOCK_SIZE definition

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/1ef0752c
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/1ef0752c
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/1ef0752c

Branch: refs/heads/master
Commit: 1ef0752c48876550229caca584ed5aad6f2a0e56
Parents: e045c16
Author: Sebb <sebb@apache.org>
Authored: Wed Jul 6 09:57:51 2016 +0100
Committer: Sebb <sebb@apache.org>
Committed: Wed Jul 6 09:57:51 2016 +0100

----------------------------------------------------------------------
 .../commons/crypto/cipher/CryptoCipherFactory.java     |  9 ++++++++-
 .../apache/commons/crypto/cipher/OpenSslCipher.java    |  4 +---
 .../apache/commons/crypto/jna/OpenSslJnaCipher.java    |  5 ++---
 .../commons/crypto/stream/CtrCryptoInputStream.java    | 13 +++----------
 4 files changed, 14 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/1ef0752c/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
index 08eea45..7f63376 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/CryptoCipherFactory.java
@@ -111,13 +111,20 @@ public class CryptoCipherFactory {
     }
 
     /**
+     * For AES, the algorithm block is fixed size of 128 bits.
+     *
+     * @see <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard">
+     *      http://en.wikipedia.org/wiki/Advanced_Encryption_Standard</a>
+     */
+    public static final int AES_BLOCK_SIZE = 16;
+
+    /**
      * The default value (OPENSSL,JCE) for crypto cipher.
      */
     private static final String CLASSES_DEFAULT =
             CipherProvider.OPENSSL.getClassName()
             .concat(",")
             .concat(CipherProvider.JCE.getClassName());
-
     /**
      * The private Constructor of {@link CryptoCipherFactory}.
      */

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/1ef0752c/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java b/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java
index af25df3..c8fe0b5 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java
@@ -41,8 +41,6 @@ class OpenSslCipher implements CryptoCipher {
 
     private final String transformation;
 
-    private final static int AES_BLOCK_SIZE = 16;
-
     /**
      * Constructs a {@link CryptoCipher} using JNI into OpenSSL
      *
@@ -72,7 +70,7 @@ class OpenSslCipher implements CryptoCipher {
      */
     @Override
     public final int getBlockSize() {
-        return AES_BLOCK_SIZE;
+        return CryptoCipherFactory.AES_BLOCK_SIZE;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/1ef0752c/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
index 1c8863b..6824230 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
@@ -35,6 +35,7 @@ import javax.crypto.ShortBufferException;
 import javax.crypto.spec.IvParameterSpec;
 
 import org.apache.commons.crypto.cipher.CryptoCipher;
+import org.apache.commons.crypto.cipher.CryptoCipherFactory;
 import org.apache.commons.crypto.utils.Utils;
 
 import com.sun.jna.NativeLong;
@@ -45,8 +46,6 @@ import com.sun.jna.ptr.PointerByReference;
  */
 class OpenSslJnaCipher implements CryptoCipher {
 
-    private final static int AES_BLOCK_SIZE = 16;
-    
     private PointerByReference algo;
     private final PointerByReference context;
     private final AlgorithmMode algMode;
@@ -318,7 +317,7 @@ class OpenSslJnaCipher implements CryptoCipher {
 
     @Override
     public int getBlockSize() {
-        return AES_BLOCK_SIZE;
+        return CryptoCipherFactory.AES_BLOCK_SIZE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/1ef0752c/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java
index 56ad048..0766807 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java
@@ -32,6 +32,7 @@ import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.commons.crypto.cipher.CryptoCipher;
+import org.apache.commons.crypto.cipher.CryptoCipherFactory;
 import org.apache.commons.crypto.stream.input.ChannelInput;
 import org.apache.commons.crypto.stream.input.Input;
 import org.apache.commons.crypto.stream.input.StreamInput;
@@ -80,14 +81,6 @@ public class CtrCryptoInputStream extends CryptoInputStream {
     private boolean cipherReset = false;
 
     /**
-     * For AES, the algorithm block is fixed size of 128 bits.
-     *
-     * @see <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard">
-     *      http://en.wikipedia.org/wiki/Advanced_Encryption_Standard</a>
-     */
-    private static final int AES_BLOCK_SIZE = 16;
-
-    /**
      * Constructs a {@link CtrCryptoInputStream}.
      *
      * @param props The <code>Properties</code> class represents a set of
@@ -653,8 +646,8 @@ public class CtrCryptoInputStream extends CryptoInputStream {
      * @param IV the IV for input stream position
      */
     static void calculateIV(byte[] initIV, long counter, byte[] IV) {
-        Utils.checkArgument(initIV.length == CtrCryptoInputStream.AES_BLOCK_SIZE);
-        Utils.checkArgument(IV.length == CtrCryptoInputStream.AES_BLOCK_SIZE);
+        Utils.checkArgument(initIV.length == CryptoCipherFactory.AES_BLOCK_SIZE);
+        Utils.checkArgument(IV.length == CryptoCipherFactory.AES_BLOCK_SIZE);
     
         int i = IV.length; // IV length
         int j = 0; // counter bytes index


Mime
View raw message