blob: 31bd6381c5b955e6a578a2d97e6e11adc0e8fb1c (
plain)
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
|
package org.spongycastle.crypto.ec;
import org.spongycastle.crypto.CipherParameters;
import org.spongycastle.crypto.params.ECPrivateKeyParameters;
import org.spongycastle.math.ec.ECPoint;
/**
* this does your basic decryption ElGamal style using EC
*/
public class ECElGamalDecryptor
implements ECDecryptor
{
private ECPrivateKeyParameters key;
/**
* initialise the decryptor.
*
* @param param the necessary EC key parameters.
*/
public void init(
CipherParameters param)
{
if (!(param instanceof ECPrivateKeyParameters))
{
throw new IllegalArgumentException("ECPrivateKeyParameters are required for decryption.");
}
this.key = (ECPrivateKeyParameters)param;
}
/**
* Decrypt an EC pair producing the original EC point.
*
* @param pair the EC point pair to process.
* @return the result of the Elgamal process.
*/
public ECPoint decrypt(ECPair pair)
{
if (key == null)
{
throw new IllegalStateException("ECElGamalDecryptor not initialised");
}
ECPoint tmp = pair.getX().multiply(key.getD());
return pair.getY().add(tmp.negate()).normalize();
}
}
|