001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.geronimo.util.crypto.params;
019
020 public class DESedeParameters
021 extends DESParameters
022 {
023 /*
024 * DES-EDE Key length in bytes.
025 */
026 static public final int DES_EDE_KEY_LENGTH = 24;
027
028 public DESedeParameters(
029 byte[] key)
030 {
031 super(key);
032
033 if (isWeakKey(key, 0, key.length))
034 {
035 throw new IllegalArgumentException("attempt to create weak DESede key");
036 }
037 }
038
039 /**
040 * return true if the passed in key is a DES-EDE weak key.
041 *
042 * @param key bytes making up the key
043 * @param offset offset into the byte array the key starts at
044 * @param length number of bytes making up the key
045 */
046 public static boolean isWeakKey(
047 byte[] key,
048 int offset,
049 int length)
050 {
051 for (int i = offset; i < length; i += DES_KEY_LENGTH)
052 {
053 if (DESParameters.isWeakKey(key, i))
054 {
055 return true;
056 }
057 }
058
059 return false;
060 }
061
062 /**
063 * return true if the passed in key is a DES-EDE weak key.
064 *
065 * @param key bytes making up the key
066 * @param offset offset into the byte array the key starts at
067 */
068 public static boolean isWeakKey(
069 byte[] key,
070 int offset)
071 {
072 return isWeakKey(key, offset, key.length - offset);
073 }
074 }