directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject [1/3] directory-kerby git commit: DIRKRB-220 Fix random2Key function in Des3KeyMaker. Contributed by Yaning
Date Thu, 23 Apr 2015 09:13:23 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 39ce32731 -> 7a1670bfd


DIRKRB-220 Fix random2Key function in Des3KeyMaker. 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/984653a2
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/984653a2
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/984653a2

Branch: refs/heads/master
Commit: 984653a23c2b2ba66cb388d089764d04f2dda20e
Parents: 39ce327
Author: Drankye <drankye@gmail.com>
Authored: Fri Apr 24 01:04:05 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Fri Apr 24 01:04:05 2015 +0800

----------------------------------------------------------------------
 .../kerberos/kerb/crypto/key/Des3KeyMaker.java  | 21 +++++++++++++++++++-
 .../kerberos/kerb/crypto/key/Rc4KeyMaker.java   |  2 +-
 2 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/984653a2/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/Des3KeyMaker.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/Des3KeyMaker.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/Des3KeyMaker.java
index 28c29ac..9c1ef68 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/Des3KeyMaker.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/Des3KeyMaker.java
@@ -38,6 +38,21 @@ public class Des3KeyMaker extends DkKeyMaker {
         return dk(tmpKey, KERBEROS_CONSTANT);
     }
 
+    /**
+     * 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;
+    }
+
     @Override
     public byte[] random2Key(byte[] randomBits) throws KrbException {
         if (randomBits.length != encProvider().keyInputSize()) {
@@ -49,10 +64,14 @@ public class Des3KeyMaker extends DkKeyMaker {
          * 8 key bytes, then compute the parity bits.  Do this three times.
          */
         byte[] key = new byte[encProvider().keySize()];
+        byte[] tmp1 = new byte[7];
+        byte[] tmp2;
         for (int i = 0; i < 3; i++) {
             System.arraycopy(randomBits, i * 7, key, i * 8, 7);
+            System.arraycopy(randomBits, i * 7, tmp1, 0, 7);
+            tmp2 = getEightBits(tmp1);
+            key[8 * (i + 1) - 1] = tmp2[7];
             int nthByte = i * 8;
-
             key[nthByte + 7] = (byte) (((key[nthByte + 0] & 1) << 1) |
                     ((key[nthByte + 1] & 1) << 2) |
                     ((key[nthByte + 2] & 1) << 3) |

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/984653a2/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/Rc4KeyMaker.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/Rc4KeyMaker.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/Rc4KeyMaker.java
index c362aad..237b510 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/Rc4KeyMaker.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/key/Rc4KeyMaker.java
@@ -56,4 +56,4 @@ public class Rc4KeyMaker extends AbstractKeyMaker {
         }
         return randomBits;
     }
-}
\ No newline at end of file
+}


Mime
View raw message