directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject [2/3] directory-kerby git commit: DIRKRB-221 Fix rand2Key function in DesKeyMaker. Contributed by Yaning
Date Thu, 23 Apr 2015 09:13:24 GMT
DIRKRB-221 Fix rand2Key function in DesKeyMaker. Contributed by Yaning


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/d633b46a
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/d633b46a
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/d633b46a

Branch: refs/heads/master
Commit: d633b46a10a72a4cfbb4094f4e5fffe12ba17937
Parents: 984653a
Author: Drankye <drankye@gmail.com>
Authored: Fri Apr 24 01:07:32 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Fri Apr 24 01:07:32 2015 +0800

----------------------------------------------------------------------
 .../kerberos/kerb/crypto/key/DesKeyMaker.java   | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d633b46a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/DesKeyMaker.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/DesKeyMaker.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/DesKeyMaker.java
index d8e01d9..edc5b9c 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/DesKeyMaker.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/DesKeyMaker.java
@@ -139,6 +139,21 @@ public class DesKeyMaker extends AbstractKeyMaker {
     }
 
     /**
+     * To turn a 54-bit block into a 64-bit block, see
+     *  Ref. eighth_byte in random_to_key.c in MIT krb5
+     * @param bits56
+     * @return
+     */
+    private static byte[] getEightBits(byte[] bits56){
+        byte[] bits64 = new byte[8];
+        System.arraycopy(bits56, 0, bits64, 0, 7);
+        bits64[7] = (byte) (((bits56[0] & 1) << 1) | ((bits56[1] & 1) <<
2) | ((bits56[2] & 1) << 3) |
+                ((bits56[3] & 1) << 4) | ((bits56[4] & 1) << 5) | ((bits56[5]
& 1) << 6) |
+                ((bits56[6] & 1) << 7));
+        return bits64;
+    }
+
+    /**
      * Note this isn't hit any test yet, and very probably problematic
      */
     @Override
@@ -146,13 +161,14 @@ public class DesKeyMaker extends AbstractKeyMaker {
         if (randomBits.length != encProvider().keyInputSize()) {
             throw new KrbException("Invalid random bits, not of correct bytes size");
         }
-
-        byte[] keyBytes = addParityBits(randomBits);
+        byte[] keyBytes = getEightBits(randomBits);
+        addParity(keyBytes);
         keyCorrection(keyBytes);
 
         return keyBytes;
     }
 
+
     // Processing an 8bytesblock
     private static byte[] removeMSBits(byte[] bits56) {
         /**


Mime
View raw message