DESedeParameters.java revision e6bf3e8dfa2804891a82075cb469b736321b4827
1package org.bouncycastle.crypto.params;
2
3public class DESedeParameters
4    extends DESParameters
5{
6    /*
7     * DES-EDE Key length in bytes.
8     */
9    static public final int DES_EDE_KEY_LENGTH = 24;
10
11    public DESedeParameters(
12        byte[]  key)
13    {
14        super(key);
15
16        if (isWeakKey(key, 0, key.length))
17        {
18            throw new IllegalArgumentException("attempt to create weak DESede key");
19        }
20    }
21
22    /**
23     * return true if the passed in key is a DES-EDE weak key.
24     *
25     * @param key bytes making up the key
26     * @param offset offset into the byte array the key starts at
27     * @param length number of bytes making up the key
28     */
29    public static boolean isWeakKey(
30        byte[]  key,
31        int     offset,
32        int     length)
33    {
34        for (int i = offset; i < length; i += DES_KEY_LENGTH)
35        {
36            if (DESParameters.isWeakKey(key, i))
37            {
38                return true;
39            }
40        }
41
42        return false;
43    }
44
45    /**
46     * return true if the passed in key is a DES-EDE weak key.
47     *
48     * @param key bytes making up the key
49     * @param offset offset into the byte array the key starts at
50     */
51    public static boolean isWeakKey(
52        byte[]  key,
53        int     offset)
54    {
55        return isWeakKey(key, offset, key.length - offset);
56    }
57}
58