directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject directory-kerby git commit: DIRKRB-216 Implement prf function for KeKiCmacEnc. Thanks Yaning for the contribution
Date Thu, 23 Apr 2015 08:10:54 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 89f859357 -> a5d42a1c1


DIRKRB-216 Implement prf function for KeKiCmacEnc. Thanks Yaning for the contribution


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

Branch: refs/heads/master
Commit: a5d42a1c1f5fa3436ab28529b25fe3ec0170a23e
Parents: 89f8593
Author: Drankye <drankye@gmail.com>
Authored: Fri Apr 24 00:08:23 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Fri Apr 24 00:08:23 2015 +0800

----------------------------------------------------------------------
 .../kerb/crypto/enc/Camellia128CtsCmacEnc.java  | 16 +++++++---
 .../kerb/crypto/enc/Camellia256CtsCmacEnc.java  | 13 +++++---
 .../kerberos/kerb/crypto/enc/KeKiCmacEnc.java   | 31 +++++++++++++++-----
 .../kerby/kerberos/kerb/crypto/PrfTest.java     | 23 +++++++++++++++
 .../kerberos/kerb/crypto/PrfTest.java.orig      | 30 +++++++++++++++++++
 5 files changed, 98 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a5d42a1c/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/Camellia128CtsCmacEnc.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/Camellia128CtsCmacEnc.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/Camellia128CtsCmacEnc.java
index fb9ab9f..62b326c 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/Camellia128CtsCmacEnc.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/Camellia128CtsCmacEnc.java
@@ -6,28 +6,34 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License. 
- *  
+ *
  */
 package org.apache.kerby.kerberos.kerb.crypto.enc;
 
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.crypto.EncryptionHandler;
 import org.apache.kerby.kerberos.kerb.crypto.enc.provider.Camellia128Provider;
+import org.apache.kerby.kerberos.kerb.crypto.enc.provider.Camellia256Provider;
 import org.apache.kerby.kerberos.kerb.crypto.key.CamelliaKeyMaker;
+import org.apache.kerby.kerberos.kerb.crypto.key.DkKeyMaker;
+import org.apache.kerby.kerberos.kerb.crypto.util.Cmac;
 import org.apache.kerby.kerberos.kerb.spec.base.CheckSumType;
 import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
 
 public class Camellia128CtsCmacEnc extends KeKiCmacEnc {
 
     public Camellia128CtsCmacEnc() {
-        super(new Camellia128Provider());
+        super(new Camellia128Provider(), EncryptionType.CAMELLIA128_CTS_CMAC,
+                new CamelliaKeyMaker(new Camellia128Provider()));
         keyMaker(new CamelliaKeyMaker((Camellia128Provider) encProvider()));
     }
 
@@ -35,6 +41,8 @@ public class Camellia128CtsCmacEnc extends KeKiCmacEnc {
         return EncryptionType.CAMELLIA128_CTS_CMAC;
     }
 
+
+
     public CheckSumType checksumType() {
         return CheckSumType.CMAC_CAMELLIA128;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a5d42a1c/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/Camellia256CtsCmacEnc.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/Camellia256CtsCmacEnc.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/Camellia256CtsCmacEnc.java
index 8670ad2..b23d7e0 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/Camellia256CtsCmacEnc.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/Camellia256CtsCmacEnc.java
@@ -6,28 +6,33 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License. 
- *  
+ *
  */
 package org.apache.kerby.kerberos.kerb.crypto.enc;
 
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.crypto.EncryptionHandler;
+import org.apache.kerby.kerberos.kerb.crypto.enc.provider.Camellia128Provider;
 import org.apache.kerby.kerberos.kerb.crypto.enc.provider.Camellia256Provider;
 import org.apache.kerby.kerberos.kerb.crypto.key.CamelliaKeyMaker;
+import org.apache.kerby.kerberos.kerb.crypto.key.DkKeyMaker;
+import org.apache.kerby.kerberos.kerb.crypto.util.Cmac;
 import org.apache.kerby.kerberos.kerb.spec.base.CheckSumType;
 import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
 
 public class Camellia256CtsCmacEnc extends KeKiCmacEnc {
 
     public Camellia256CtsCmacEnc() {
-        super(new Camellia256Provider());
+        super(new Camellia256Provider(), EncryptionType.CAMELLIA256_CTS_CMAC, new CamelliaKeyMaker(new
Camellia256Provider()));
         keyMaker(new CamelliaKeyMaker((Camellia256Provider) encProvider()));
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a5d42a1c/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiCmacEnc.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiCmacEnc.java
b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiCmacEnc.java
index 84c328c..d652831 100644
--- a/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiCmacEnc.java
+++ b/kerby-kerb/kerb-crypto/src/main/java/org/apache/kerby/kerberos/kerb/crypto/enc/KeKiCmacEnc.java
@@ -6,26 +6,39 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- *  
+ *
  *    http://www.apache.org/licenses/LICENSE-2.0
- *  
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License. 
- *  
+ *
  */
 package org.apache.kerby.kerberos.kerb.crypto.enc;
 
+import org.apache.kerby.kerberos.kerb.crypto.EncTypeHandler;
+import org.apache.kerby.kerberos.kerb.crypto.EncryptionHandler;
+import org.apache.kerby.kerberos.kerb.crypto.enc.provider.Camellia128Provider;
+import org.apache.kerby.kerberos.kerb.crypto.key.CamelliaKeyMaker;
+import org.apache.kerby.kerberos.kerb.crypto.key.DkKeyMaker;
 import org.apache.kerby.kerberos.kerb.crypto.util.Cmac;
 import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey;
+import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
 
 public abstract class KeKiCmacEnc extends KeKiEnc {
 
-    public KeKiCmacEnc(EncryptProvider encProvider) {
+    private EncryptionType eType;
+    private DkKeyMaker km;
+    public KeKiCmacEnc(EncryptProvider encProvider,
+                       EncryptionType eType, DkKeyMaker km) {
         super(encProvider, null);
+        this.eType = eType;
+        this.km = km;
+
     }
 
     @Override
@@ -39,9 +52,13 @@ public abstract class KeKiCmacEnc extends KeKiEnc {
     }
 
     @Override
-    public byte[] prf(byte[] key, byte[] seed) {
-        // TODO: krb5int_dk_cmac_prf
-        return null;
+    public byte[] prf(byte[] key, byte[] seed) throws KrbException {
+        byte[] prfConst = "prf".getBytes();
+        byte[] kp;
+        if (EncryptionHandler.getEncHandler(this.eType()).prfSize() != encProvider().blockSize())
+            return null;
+        kp = km.dk(key, prfConst);
+        return Cmac.cmac(encProvider(), kp, seed);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a5d42a1c/kerby-kerb/kerb-crypto/src/test/java/org/apache/kerby/kerberos/kerb/crypto/PrfTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/test/java/org/apache/kerby/kerberos/kerb/crypto/PrfTest.java
b/kerby-kerb/kerb-crypto/src/test/java/org/apache/kerby/kerberos/kerb/crypto/PrfTest.java
index b7a2ad0..32b7771 100644
--- a/kerby-kerb/kerb-crypto/src/test/java/org/apache/kerby/kerberos/kerb/crypto/PrfTest.java
+++ b/kerby-kerb/kerb-crypto/src/test/java/org/apache/kerby/kerberos/kerb/crypto/PrfTest.java
@@ -27,6 +27,9 @@ import java.util.Arrays;
 
 import static org.assertj.core.api.Assertions.fail;
 
+/**
+ * Created by yaningxu on 4/13/2015.
+ */
 public class PrfTest {
     static class TestCase {
         EncryptionType encType;
@@ -103,6 +106,26 @@ public class PrfTest {
         ));
     }
 
+    @Test
+    public void testPrf_CAMELLIA128_CTS_CMAC() throws Exception {
+        performTest(new TestCase(
+                EncryptionType.CAMELLIA128_CTS_CMAC,
+                "key1",
+                "0161",
+                "e9bfccec1ec08740efcfdb020b48cf17"
+        ));
+    }
+
+    @Test
+    public void testPrf_CAMELLIA256_CTS_CMAC() throws Exception {
+        performTest(new TestCase(
+                EncryptionType.CAMELLIA256_CTS_CMAC,
+                "key1",
+                "0161",
+                "d0bb1a19fd311388dc2eeb67268ff90b"
+        ));
+    }
+
     private static void performTest(TestCase testCase) throws Exception {
         byte[] keyData = EncryptionHandler.getEncHandler(testCase.encType).str2key(testCase.keyData,
testCase.keyData, null);
         byte[] seed = HexUtil.hex2bytes(testCase.seed);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a5d42a1c/kerby-kerb/kerb-crypto/src/test/java/org/apache/kerby/kerberos/kerb/crypto/PrfTest.java.orig
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-crypto/src/test/java/org/apache/kerby/kerberos/kerb/crypto/PrfTest.java.orig
b/kerby-kerb/kerb-crypto/src/test/java/org/apache/kerby/kerberos/kerb/crypto/PrfTest.java.orig
index 739cc87..b7a2ad0 100644
--- a/kerby-kerb/kerb-crypto/src/test/java/org/apache/kerby/kerberos/kerb/crypto/PrfTest.java.orig
+++ b/kerby-kerb/kerb-crypto/src/test/java/org/apache/kerby/kerberos/kerb/crypto/PrfTest.java.orig
@@ -73,6 +73,36 @@ public class PrfTest {
         ));
     }
 
+    @Test
+    public void testPrf_AES128_CTS_HMAC_SHA1() throws Exception {
+        performTest(new TestCase(
+                EncryptionType.AES128_CTS_HMAC_SHA1_96,
+                "key1",
+                "0161",
+                "77b39a37a868920f2a51f9dd150c5717"
+        ));
+    }
+
+    @Test
+    public void testPrf_AES256_CTS_HMAC_SHA1() throws Exception {
+        performTest(new TestCase(
+                EncryptionType.AES256_CTS_HMAC_SHA1_96,
+                "key1",
+                "0161",
+                "b2628c788e2e9c4a9bb4644678c29f2f"
+        ));
+    }
+
+    @Test
+    public void testPrf_DES3_CBC_SHA1() throws Exception {
+        performTest(new TestCase(
+                EncryptionType.DES3_CBC_SHA1,
+                "key1",
+                "0161",
+                "bb6f4a7caa25fce1ee9baef36f1f9ee7"
+        ));
+    }
+
     private static void performTest(TestCase testCase) throws Exception {
         byte[] keyData = EncryptionHandler.getEncHandler(testCase.encType).str2key(testCase.keyData,
testCase.keyData, null);
         byte[] seed = HexUtil.hex2bytes(testCase.seed);


Mime
View raw message