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