01: package org.bouncycastle.jce.provider.symmetric;
02:
03: import org.bouncycastle.crypto.CipherKeyGenerator;
04: import org.bouncycastle.crypto.engines.SEEDEngine;
05: import org.bouncycastle.crypto.engines.SEEDWrapEngine;
06: import org.bouncycastle.crypto.modes.CBCBlockCipher;
07: import org.bouncycastle.jce.provider.JCEBlockCipher;
08: import org.bouncycastle.jce.provider.JCEKeyGenerator;
09: import org.bouncycastle.jce.provider.JDKAlgorithmParameterGenerator;
10: import org.bouncycastle.jce.provider.JDKAlgorithmParameters;
11: import org.bouncycastle.jce.provider.WrapCipherSpi;
12:
13: import javax.crypto.spec.IvParameterSpec;
14: import java.security.AlgorithmParameters;
15: import java.security.InvalidAlgorithmParameterException;
16: import java.security.SecureRandom;
17: import java.security.spec.AlgorithmParameterSpec;
18:
19: public final class SEED {
20: private SEED() {
21: }
22:
23: public static class ECB extends JCEBlockCipher {
24: public ECB() {
25: super (new SEEDEngine());
26: }
27: }
28:
29: public static class CBC extends JCEBlockCipher {
30: public CBC() {
31: super (new CBCBlockCipher(new SEEDEngine()));
32: }
33: }
34:
35: public static class Wrap extends WrapCipherSpi {
36: public Wrap() {
37: super (new SEEDWrapEngine());
38: }
39: }
40:
41: public static class KeyGen extends JCEKeyGenerator {
42: public KeyGen() {
43: super ("SEED", 128, new CipherKeyGenerator());
44: }
45: }
46:
47: public static class AlgParamGen extends
48: JDKAlgorithmParameterGenerator {
49: protected void engineInit(AlgorithmParameterSpec genParamSpec,
50: SecureRandom random)
51: throws InvalidAlgorithmParameterException {
52: throw new InvalidAlgorithmParameterException(
53: "No supported AlgorithmParameterSpec for AES parameter generation.");
54: }
55:
56: protected AlgorithmParameters engineGenerateParameters() {
57: byte[] iv = new byte[16];
58:
59: if (random == null) {
60: random = new SecureRandom();
61: }
62:
63: random.nextBytes(iv);
64:
65: AlgorithmParameters params;
66:
67: try {
68: params = AlgorithmParameters.getInstance("SEED", "BC");
69: params.init(new IvParameterSpec(iv));
70: } catch (Exception e) {
71: throw new RuntimeException(e.getMessage());
72: }
73:
74: return params;
75: }
76: }
77:
78: public static class AlgParams extends
79: JDKAlgorithmParameters.IVAlgorithmParameters {
80: protected String engineToString() {
81: return "SEED IV";
82: }
83: }
84: }
|