directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: rev 57017 - in incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos: crypto crypto/checksum util
Date Tue, 09 Nov 2004 11:22:19 GMT
Author: erodriguez
Date: Tue Nov  9 03:22:16 2004
New Revision: 57017

Removed:
   incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/util/OctetUtils.java
Modified:
   incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/crypto/CryptoService.java
   incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/crypto/checksum/Crc32Checksum.java
Log:
Split OctetUtils to where they were used.

Modified: incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/crypto/CryptoService.java
==============================================================================
--- incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/crypto/CryptoService.java
(original)
+++ incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/crypto/CryptoService.java
Tue Nov  9 03:22:16 2004
@@ -21,7 +21,6 @@
 import org.apache.kerberos.kdc.KerberosException;
 import org.apache.kerberos.messages.value.EncryptedData;
 import org.apache.kerberos.messages.value.EncryptionKey;
-import org.apache.kerberos.util.OctetUtils;
 
 import java.util.Date;
 import java.util.HashMap;
@@ -68,7 +67,7 @@
 	public static byte[] getEncryptedTimestamp(EncryptionKey key, Date date)
 			throws KerberosException {
 		EncryptionEngine encryptionEngine = getInstance(key.getKeyType());
-		byte[] plaintext = OctetUtils.long2octet(date.getTime());
+		byte[] plaintext = long2octet(date.getTime());
 		return encryptionEngine.encrypt(plaintext, key.getKeyValue());
 	}
 	
@@ -106,7 +105,15 @@
 		
 		return new EncryptedData(type.encryptionType(), key.getKeyVersion(), encryptedData);
 	}
-	
+
+    private static byte[] long2octet(long input) {
+		byte[] output = new byte[8];
+		for (int i = 0; i < 8; i++) {
+			output[i] =	(byte)((input >>> ((7 - i) * 8)) & 0xffL);
+		}
+		return output;
+	}
+
 	// TODO - The classes below are key production util code and I can picture them moving
 	//        to a key production base class when I add DES3 and/or AES support.
 	

Modified: incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/crypto/checksum/Crc32Checksum.java
==============================================================================
--- incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/crypto/checksum/Crc32Checksum.java
(original)
+++ incubator/directory/kerberos/trunk/kerberos/src/java/org/apache/kerberos/crypto/checksum/Crc32Checksum.java
Tue Nov  9 03:22:16 2004
@@ -16,51 +16,69 @@
  */
 package org.apache.kerberos.crypto.checksum;
 
-import org.apache.kerberos.crypto.encryption.*;
-import org.apache.kerberos.util.*;
+import org.apache.kerberos.crypto.encryption.CipherType;
 
-import java.util.zip.*;
+import java.util.zip.CRC32;
 
-public class Crc32Checksum implements ChecksumEngine {
+public class Crc32Checksum implements ChecksumEngine
+{
+	private final CRC32 crc32 = new CRC32();
 
-	private static final CRC32 crc32 = new CRC32();
-
-	public ChecksumType checksumType() {
+	public ChecksumType checksumType()
+    {
 		return ChecksumType.CRC32;
 	}
 
-	public CipherType keyType() {
+	public CipherType keyType()
+    {
 		return CipherType.NULL;
 	}
 
-	public int checksumSize() {
-		return 4;
+	public int checksumSize()
+    {
+        return 4;
 	}
 
-	public int keySize() {
+	public int keySize()
+    {
 		return 0;
 	}
 
-	public int confounderSize() {
+	public int confounderSize()
+    {
 		return 0;
 	}
 
-	public boolean isSafe() {
+	public boolean isSafe()
+    {
 		return false;
 	}
 
-	public synchronized byte[] calculateChecksum(byte[] data) {
+	public synchronized byte[] calculateChecksum( byte[] data )
+    {
 		crc32.reset();
-		crc32.update(data);
-		return OctetUtils.int2octet((int) crc32.getValue());
+		crc32.update( data );
+		return int2octet( (int)crc32.getValue() );
 	}
 
-	public byte[] calculateKeyedChecksum(byte[] data, byte[] key) {
+	public byte[] calculateKeyedChecksum( byte[] data, byte[] key )
+    {
 		return null;
 	}
 
-	public boolean verifyKeyedChecksum(byte[] data, byte[] key, byte[] checksum) {
+	public boolean verifyKeyedChecksum( byte[] data, byte[] key, byte[] checksum )
+    {
 		return false;
+	}
+
+    private byte[] int2octet( int value )
+    {
+		byte[] bytes = new byte[4];
+		int i, shift;
+
+		for (i = 0, shift = 24; i < 4; i++, shift -= 8)
+			bytes[i] = (byte) (0xFF & (value >> shift));
+		return bytes;
 	}
 }
 

Mime
View raw message