Return-Path: Delivered-To: apmail-incubator-directory-cvs-archive@www.apache.org Received: (qmail 69323 invoked from network); 29 Sep 2004 13:41:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 29 Sep 2004 13:41:20 -0000 Received: (qmail 67734 invoked by uid 500); 29 Sep 2004 13:41:12 -0000 Delivered-To: apmail-incubator-directory-cvs-archive@incubator.apache.org Received: (qmail 67679 invoked by uid 500); 29 Sep 2004 13:41:11 -0000 Mailing-List: contact directory-cvs-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: directory-dev@incubator.apache.org Delivered-To: mailing list directory-cvs@incubator.apache.org Received: (qmail 67664 invoked by uid 99); 29 Sep 2004 13:41:10 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 29 Sep 2004 06:41:10 -0700 Received: (qmail 68862 invoked by uid 65534); 29 Sep 2004 13:41:09 -0000 Date: 29 Sep 2004 13:41:09 -0000 Message-ID: <20040929134109.68854.qmail@minotaur.apache.org> From: erodriguez@apache.org To: directory-cvs@incubator.apache.org Subject: svn commit: rev 47483 - incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: erodriguez Date: Wed Sep 29 06:41:08 2004 New Revision: 47483 Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/ChecksumEngine.java incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/ChecksumType.java incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/Crc32Checksum.java incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/RsaMd4Checksum.java incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/RsaMd5Checksum.java incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/Sha1Checksum.java Log: kerberos checksum package Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/ChecksumEngine.java ============================================================================== --- (empty file) +++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/ChecksumEngine.java Wed Sep 29 06:41:08 2004 @@ -0,0 +1,32 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed 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.kerberos.crypto.checksum; + +public interface ChecksumEngine { + + public ChecksumType checksumType(); + public int keyType(); + public int checksumSize(); + public int keySize(); + public int confounderSize(); + public boolean isSafe(); + public byte[] calculateChecksum(byte[] data); + public byte[] calculateKeyedChecksum(byte[] data, byte[] key); + public boolean verifyKeyedChecksum(byte[] data, byte[] key, byte[] checksum); + +} + Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/ChecksumType.java ============================================================================== --- (empty file) +++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/ChecksumType.java Wed Sep 29 06:41:08 2004 @@ -0,0 +1,82 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed 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.kerberos.crypto.checksum; + +import java.util.*; + +public final class ChecksumType implements Comparable { + + /** + * Enumeration elements are constructed once upon class loading. + * Order of appearance here determines the order of compareTo. + */ + public static final ChecksumType NULL = new ChecksumType("null"); + public static final ChecksumType CRC32 = new ChecksumType("CRC32"); + public static final ChecksumType RSA_MD4 = new ChecksumType("RSA MD4"); + public static final ChecksumType RSA_MD4_DES = new ChecksumType("RSA MD4 DES"); + public static final ChecksumType DES_MAC = new ChecksumType("DES MAC"); + public static final ChecksumType DES_MAC_K = new ChecksumType("DES MAC K"); + public static final ChecksumType RSA_MD4_DES_K = new ChecksumType("RSA MD4 DES K"); + public static final ChecksumType RSA_MD5 = new ChecksumType("RSA MD5"); + public static final ChecksumType RSA_MD5_DES = new ChecksumType("RSA MD5 DES"); + public static final ChecksumType RSA_MD5_DES3 = new ChecksumType("RSA MD5 DES3"); + public static final ChecksumType SHA1 = new ChecksumType("SHA1"); + public static final ChecksumType UNKNOWN11 = new ChecksumType("UNKNOWN 11"); + public static final ChecksumType HMAC_SHA1_DES3 = new ChecksumType("HMAC SHA1 DES3"); + + public String toString() { + return _fName; + } + + public int compareTo(Object that) { + return _fOrdinal - ((ChecksumType) that)._fOrdinal; + } + + public static ChecksumType getTypeByOrdinal(int type) { + for (int i = 0; i < fValues.length; i++) + if (fValues[i]._fOrdinal == type) + return fValues[i]; + return NULL; + } + + public int getOrdinal() { + return _fOrdinal; + } + + /// PRIVATE ///// + private final String _fName; + private static int fNextOrdinal = 0; + private final int _fOrdinal = fNextOrdinal++; + + /** + * Private constructor prevents construction outside of this class. + */ + private ChecksumType(String aName) { + _fName = aName; + } + + /** + * These two lines are all that's necessary to export a List of VALUES. + */ + private static final ChecksumType[] fValues = {NULL, CRC32, RSA_MD4, RSA_MD4_DES, + DES_MAC, DES_MAC_K, RSA_MD4_DES_K, RSA_MD5, RSA_MD5_DES, RSA_MD5_DES3, + SHA1, UNKNOWN11, HMAC_SHA1_DES3}; + // VALUES needs to be located here, otherwise illegal forward reference + public static final List VALUES = Collections.unmodifiableList(Arrays.asList(fValues)); + +} + Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/Crc32Checksum.java ============================================================================== --- (empty file) +++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/Crc32Checksum.java Wed Sep 29 06:41:08 2004 @@ -0,0 +1,66 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed 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.kerberos.crypto.checksum; + +import org.apache.kerberos.messages.value.*; +import org.apache.kerberos.util.*; + +import java.util.zip.*; + +public class Crc32Checksum implements ChecksumEngine { + + private static final CRC32 crc32 = new CRC32(); + + public ChecksumType checksumType() { + return ChecksumType.CRC32; + } + + public int keyType() { + return EncryptionKey.KEYTYPE_NULL; + } + + public int checksumSize() { + return 4; + } + + public int keySize() { + return 0; + } + + public int confounderSize() { + return 0; + } + + public boolean isSafe() { + return false; + } + + public synchronized byte[] calculateChecksum(byte[] data) { + crc32.reset(); + crc32.update(data); + return ConversionUtils.int2octet((int) crc32.getValue()); + } + + public byte[] calculateKeyedChecksum(byte[] data, byte[] key) { + return null; + } + + public boolean verifyKeyedChecksum(byte[] data, byte[] key, byte[] checksum) { + return false; + } +} + Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/RsaMd4Checksum.java ============================================================================== --- (empty file) +++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/RsaMd4Checksum.java Wed Sep 29 06:41:08 2004 @@ -0,0 +1,67 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed 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.kerberos.crypto.checksum; + +import org.apache.kerberos.messages.value.*; +import org.bouncycastle.crypto.*; +import org.bouncycastle.crypto.digests.*; + +public class RsaMd4Checksum implements ChecksumEngine { + + private static final Digest digester = new MD4Digest(); + + public ChecksumType checksumType() { + return ChecksumType.RSA_MD4; + } + + public int keyType() { + return EncryptionKey.KEYTYPE_NULL; + } + + public int checksumSize() { + return 16; + } + + public int keySize() { + return 0; + } + + public int confounderSize() { + return 0; + } + + public boolean isSafe() { + return false; + } + + public synchronized byte[] calculateChecksum(byte[] data) { + digester.reset(); + digester.update(data, 0, data.length); + byte[] returnValue = new byte[digester.getDigestSize()]; + digester.doFinal(returnValue, 0); + return returnValue; + } + + public byte[] calculateKeyedChecksum(byte[] data, byte[] key) { + return null; + } + + public boolean verifyKeyedChecksum(byte[] data, byte[] key, byte[] checksum) { + return false; + } +} + Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/RsaMd5Checksum.java ============================================================================== --- (empty file) +++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/RsaMd5Checksum.java Wed Sep 29 06:41:08 2004 @@ -0,0 +1,67 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed 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.kerberos.crypto.checksum; + +import org.apache.kerberos.messages.value.*; +import org.bouncycastle.crypto.*; +import org.bouncycastle.crypto.digests.*; + +public class RsaMd5Checksum implements ChecksumEngine { + + private static final Digest digester = new MD5Digest(); + + public ChecksumType checksumType() { + return ChecksumType.RSA_MD5; + } + + public int keyType() { + return EncryptionKey.KEYTYPE_NULL; + } + + public int checksumSize() { + return 16; + } + + public int keySize() { + return 0; + } + + public int confounderSize() { + return 0; + } + + public boolean isSafe() { + return false; + } + + public synchronized byte[] calculateChecksum(byte[] data) { + digester.reset(); + digester.update(data, 0, data.length); + byte[] returnValue = new byte[digester.getDigestSize()]; + digester.doFinal(returnValue, 0); + return returnValue; + } + + public byte[] calculateKeyedChecksum(byte[] data, byte[] key) { + return null; + } + + public boolean verifyKeyedChecksum(byte[] data, byte[] key, byte[] checksum) { + return false; + } +} + Added: incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/Sha1Checksum.java ============================================================================== --- (empty file) +++ incubator/directory/kerberos/trunk/source/main/org/apache/kerberos/crypto/checksum/Sha1Checksum.java Wed Sep 29 06:41:08 2004 @@ -0,0 +1,67 @@ +/* + * Copyright 2004 The Apache Software Foundation + * + * Licensed 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.kerberos.crypto.checksum; + +import org.apache.kerberos.messages.value.*; +import org.bouncycastle.crypto.*; +import org.bouncycastle.crypto.digests.*; + +public class Sha1Checksum implements ChecksumEngine { + + private static final Digest digester = new SHA1Digest(); + + public ChecksumType checksumType() { + return ChecksumType.SHA1; + } + + public int keyType() { + return EncryptionKey.KEYTYPE_NULL; + } + + public int checksumSize() { + return 20; + } + + public int keySize() { + return 0; + } + + public int confounderSize() { + return 0; + } + + public boolean isSafe() { + return false; + } + + public synchronized byte[] calculateChecksum(byte[] data) { + digester.reset(); + digester.update(data, 0, data.length); + byte[] returnValue = new byte[digester.getDigestSize()]; + digester.doFinal(returnValue, 0); + return returnValue; + } + + public byte[] calculateKeyedChecksum(byte[] data, byte[] key) { + return null; + } + + public boolean verifyKeyedChecksum(byte[] data, byte[] key, byte[] checksum) { + return false; + } +} +