1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
package org.bouncycastle.jcajce.provider.symmetric;
import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.spec.IvParameterSpec;
import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
import org.bouncycastle.crypto.BufferedBlockCipher;
import org.bouncycastle.crypto.CipherKeyGenerator;
import org.bouncycastle.crypto.engines.GOST28147Engine;
import org.bouncycastle.crypto.macs.GOST28147Mac;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.modes.GCFBBlockCipher;
import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
import org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameterGenerator;
import org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher;
import org.bouncycastle.jcajce.provider.symmetric.util.BaseKeyGenerator;
import org.bouncycastle.jcajce.provider.symmetric.util.BaseMac;
import org.bouncycastle.jcajce.provider.symmetric.util.IvAlgorithmParameters;
import org.bouncycastle.jcajce.provider.util.AlgorithmProvider;
public final class GOST28147
{
private GOST28147()
{
}
public static class ECB
extends BaseBlockCipher
{
public ECB()
{
super(new GOST28147Engine());
}
}
public static class CBC
extends BaseBlockCipher
{
public CBC()
{
super(new CBCBlockCipher(new GOST28147Engine()), 64);
}
}
public static class GCFB
extends BaseBlockCipher
{
public GCFB()
{
super(new BufferedBlockCipher(new GCFBBlockCipher(new GOST28147Engine())), 64);
}
}
/**
* GOST28147
*/
public static class Mac
extends BaseMac
{
public Mac()
{
super(new GOST28147Mac());
}
}
public static class KeyGen
extends BaseKeyGenerator
{
public KeyGen()
{
this(256);
}
public KeyGen(int keySize)
{
super("GOST28147", keySize, new CipherKeyGenerator());
}
}
public static class AlgParamGen
extends BaseAlgorithmParameterGenerator
{
protected void engineInit(
AlgorithmParameterSpec genParamSpec,
SecureRandom random)
throws InvalidAlgorithmParameterException
{
throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for GOST28147 parameter generation.");
}
protected AlgorithmParameters engineGenerateParameters()
{
byte[] iv = new byte[16];
if (random == null)
{
random = new SecureRandom();
}
random.nextBytes(iv);
AlgorithmParameters params;
try
{
params = createParametersInstance("GOST28147");
params.init(new IvParameterSpec(iv));
}
catch (Exception e)
{
throw new RuntimeException(e.getMessage());
}
return params;
}
}
public static class AlgParams
extends IvAlgorithmParameters
{
protected String engineToString()
{
return "GOST IV";
}
}
public static class Mappings
extends AlgorithmProvider
{
private static final String PREFIX = GOST28147.class.getName();
public Mappings()
{
}
public void configure(ConfigurableProvider provider)
{
provider.addAlgorithm("Cipher.GOST28147", PREFIX + "$ECB");
provider.addAlgorithm("Alg.Alias.Cipher.GOST", "GOST28147");
provider.addAlgorithm("Alg.Alias.Cipher.GOST-28147", "GOST28147");
provider.addAlgorithm("Cipher." + CryptoProObjectIdentifiers.gostR28147_gcfb, PREFIX + "$GCFB");
provider.addAlgorithm("KeyGenerator.GOST28147", PREFIX + "$KeyGen");
provider.addAlgorithm("Alg.Alias.KeyGenerator.GOST", "GOST28147");
provider.addAlgorithm("Alg.Alias.KeyGenerator.GOST-28147", "GOST28147");
provider.addAlgorithm("Alg.Alias.KeyGenerator." + CryptoProObjectIdentifiers.gostR28147_gcfb, "GOST28147");
provider.addAlgorithm("Mac.GOST28147MAC", PREFIX + "$Mac");
provider.addAlgorithm("Alg.Alias.Mac.GOST28147", "GOST28147MAC");
}
}
}
|