001: package org.bouncycastle.jce.provider.symmetric;
002:
003: import org.bouncycastle.crypto.CipherKeyGenerator;
004: import org.bouncycastle.crypto.engines.CamelliaEngine;
005: import org.bouncycastle.crypto.engines.CamelliaWrapEngine;
006: import org.bouncycastle.crypto.engines.RFC3211WrapEngine;
007: import org.bouncycastle.crypto.modes.CBCBlockCipher;
008: import org.bouncycastle.jce.provider.JCEBlockCipher;
009: import org.bouncycastle.jce.provider.JCEKeyGenerator;
010: import org.bouncycastle.jce.provider.JDKAlgorithmParameterGenerator;
011: import org.bouncycastle.jce.provider.JDKAlgorithmParameters;
012: import org.bouncycastle.jce.provider.WrapCipherSpi;
013:
014: import javax.crypto.spec.IvParameterSpec;
015: import java.security.AlgorithmParameters;
016: import java.security.InvalidAlgorithmParameterException;
017: import java.security.SecureRandom;
018: import java.security.spec.AlgorithmParameterSpec;
019:
020: public final class Camellia {
021: private Camellia() {
022: }
023:
024: public static class ECB extends JCEBlockCipher {
025: public ECB() {
026: super (new CamelliaEngine());
027: }
028: }
029:
030: public static class CBC extends JCEBlockCipher {
031: public CBC() {
032: super (new CBCBlockCipher(new CamelliaEngine()));
033: }
034: }
035:
036: public static class Wrap extends WrapCipherSpi {
037: public Wrap() {
038: super (new CamelliaWrapEngine());
039: }
040: }
041:
042: public static class RFC3211Wrap extends WrapCipherSpi {
043: public RFC3211Wrap() {
044: super (new RFC3211WrapEngine(new CamelliaEngine()), 16);
045: }
046: }
047:
048: public static class KeyGen extends JCEKeyGenerator {
049: public KeyGen() {
050: this (256);
051: }
052:
053: public KeyGen(int keySize) {
054: super ("Camellia", keySize, new CipherKeyGenerator());
055: }
056: }
057:
058: public static class KeyGen128 extends KeyGen {
059: public KeyGen128() {
060: super (128);
061: }
062: }
063:
064: public static class KeyGen192 extends KeyGen {
065: public KeyGen192() {
066: super (192);
067: }
068: }
069:
070: public static class KeyGen256 extends KeyGen {
071: public KeyGen256() {
072: super (256);
073: }
074: }
075:
076: public static class AlgParamGen extends
077: JDKAlgorithmParameterGenerator {
078: protected void engineInit(AlgorithmParameterSpec genParamSpec,
079: SecureRandom random)
080: throws InvalidAlgorithmParameterException {
081: throw new InvalidAlgorithmParameterException(
082: "No supported AlgorithmParameterSpec for AES parameter generation.");
083: }
084:
085: protected AlgorithmParameters engineGenerateParameters() {
086: byte[] iv = new byte[16];
087:
088: if (random == null) {
089: random = new SecureRandom();
090: }
091:
092: random.nextBytes(iv);
093:
094: AlgorithmParameters params;
095:
096: try {
097: params = AlgorithmParameters.getInstance("Camellia",
098: "BC");
099: params.init(new IvParameterSpec(iv));
100: } catch (Exception e) {
101: throw new RuntimeException(e.getMessage());
102: }
103:
104: return params;
105: }
106: }
107:
108: public static class AlgParams extends
109: JDKAlgorithmParameters.IVAlgorithmParameters {
110: protected String engineToString() {
111: return "Camellia IV";
112: }
113: }
114: }
|