01: package org.bouncycastle.crypto.params;
02:
03: public class DESedeParameters extends DESParameters {
04: /*
05: * DES-EDE Key length in bytes.
06: */
07: static public final int DES_EDE_KEY_LENGTH = 24;
08:
09: public DESedeParameters(byte[] key) {
10: super (key);
11:
12: if (isWeakKey(key, 0, key.length)) {
13: throw new IllegalArgumentException(
14: "attempt to create weak DESede key");
15: }
16: }
17:
18: /**
19: * return true if the passed in key is a DES-EDE weak key.
20: *
21: * @param key bytes making up the key
22: * @param offset offset into the byte array the key starts at
23: * @param length number of bytes making up the key
24: */
25: public static boolean isWeakKey(byte[] key, int offset, int length) {
26: for (int i = offset; i < length; i += DES_KEY_LENGTH) {
27: if (DESParameters.isWeakKey(key, i)) {
28: return true;
29: }
30: }
31:
32: return false;
33: }
34:
35: /**
36: * return true if the passed in key is a DES-EDE weak key.
37: *
38: * @param key bytes making up the key
39: * @param offset offset into the byte array the key starts at
40: */
41: public static boolean isWeakKey(byte[] key, int offset) {
42: return isWeakKey(key, offset, key.length - offset);
43: }
44: }
|