directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject [40/50] [abbrv] directory-kerberos git commit: Cleanup a bit
Date Mon, 12 Jan 2015 13:06:48 GMT
Cleanup a bit


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

Branch: refs/heads/master
Commit: e11e7f1b8167358617a495e1755a5a34216dac7c
Parents: 5224d81
Author: Drankye <drankye@gmail.com>
Authored: Fri Dec 26 10:21:59 2014 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Fri Dec 26 10:21:59 2014 +0800

----------------------------------------------------------------------
 .../org/apache/kerberos/kerb/crypto/Cmac.java   |  3 ++
 .../org/apache/kerberos/kerb/crypto/Hmac.java   | 30 +++++++++++++-------
 2 files changed, 23 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/e11e7f1b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Cmac.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Cmac.java
b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Cmac.java
index d59909d..7f7d333 100644
--- a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Cmac.java
+++ b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Cmac.java
@@ -5,6 +5,9 @@ import org.apache.kerberos.kerb.KrbException;
 
 import java.util.Arrays;
 
+/**
+ * Based on MIT krb5 cmac.c
+ */
 public class Cmac {
 
     private static byte[] constRb = {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/e11e7f1b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Hmac.java
----------------------------------------------------------------------
diff --git a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Hmac.java
b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Hmac.java
index 486f6e1..02e8567 100644
--- a/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Hmac.java
+++ b/haox-kerb/kerb-crypto/src/main/java/org/apache/kerberos/kerb/crypto/Hmac.java
@@ -3,6 +3,11 @@ package org.apache.kerberos.kerb.crypto;
 import org.apache.kerberos.kerb.crypto.cksum.HashProvider;
 import org.apache.kerberos.kerb.KrbException;
 
+import java.util.Arrays;
+
+/**
+ * Based on MIT krb5 hmac.c
+ */
 public class Hmac {
 
     public static byte[] hmac(HashProvider hashProvider, byte[] key,
@@ -28,23 +33,28 @@ public class Hmac {
                               byte[] key, byte[] data, int start, int len) throws KrbException
{
 
         int blockLen = hashProvider.blockSize();
-        byte[] ipad = new byte[blockLen];
-        byte[] opad = new byte[blockLen];
-
-        int ki;
-        for (int i = 0; i < blockLen; i++) {
-            ki = (i < key.length) ? key[i] : 0;
-            ipad[i] = (byte)(ki ^ 0x36);
-            opad[i] = (byte)(ki ^ 0x5c);
+        byte[] innerPaddedKey = new byte[blockLen];
+        byte[] outerPaddedKey = new byte[blockLen];
+
+        // Create the inner padded key
+        Arrays.fill(innerPaddedKey, (byte)0x36);
+        for (int i = 0; i < key.length; i++) {
+            innerPaddedKey[i] ^= key[i];
+        }
+
+        // Create the outer padded key
+        Arrays.fill(outerPaddedKey, (byte)0x5c);
+        for (int i = 0; i < key.length; i++) {
+            outerPaddedKey[i] ^= key[i];
         }
 
-        hashProvider.hash(ipad);
+        hashProvider.hash(innerPaddedKey);
 
         hashProvider.hash(data, start, len);
 
         byte[] tmp = hashProvider.output();
 
-        hashProvider.hash(opad);
+        hashProvider.hash(outerPaddedKey);
         hashProvider.hash(tmp);
 
         tmp = hashProvider.output();


Mime
View raw message