I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 592f2449 authored by zzz's avatar zzz
Browse files

ElGamal classes, from Bouncy Castle 1.53, for I2PProvider.

License: BSD
Encoding/decoding/sigs: todo.
parent cf3accb1
No related branches found
No related tags found
No related merge requests found
Showing
with 466 additions and 0 deletions
......@@ -40,6 +40,10 @@ Public domain except as listed below:
Copyright (c) 2000 - 2004 The Legion Of The Bouncy Castle
See licenses/LICENSE-SHA256.txt
ElGamal:
Copyright (c) 2000 - 2013 The Legion of the Bouncy Castle Inc. (http://www.bouncycastle.org)
See licenses/LICENSE-SHA256.txt
AES code:
Copyright (c) 1995-2005 The Cryptix Foundation Limited.
See licenses/LICENSE-Cryptix.txt
......
......@@ -34,6 +34,7 @@ import java.math.BigInteger;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.DSAParameterSpec;
import net.i2p.crypto.elgamal.spec.ElGamalParameterSpec;
import net.i2p.util.NativeBigInteger;
/**
......
package net.i2p.crypto.elgamal;
import javax.crypto.interfaces.DHKey;
import net.i2p.crypto.elgamal.spec.ElGamalParameterSpec;
public interface ElGamalKey
extends DHKey
{
public ElGamalParameterSpec getParameters();
}
package net.i2p.crypto.elgamal;
import java.math.BigInteger;
import javax.crypto.interfaces.DHPrivateKey;
public interface ElGamalPrivateKey
extends ElGamalKey, DHPrivateKey
{
public BigInteger getX();
}
package net.i2p.crypto.elgamal;
import java.math.BigInteger;
import javax.crypto.interfaces.DHPublicKey;
public interface ElGamalPublicKey
extends ElGamalKey, DHPublicKey
{
public BigInteger getY();
}
package net.i2p.crypto.elgamal.impl;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.math.BigInteger;
import javax.crypto.interfaces.DHPrivateKey;
import javax.crypto.spec.DHParameterSpec;
import javax.crypto.spec.DHPrivateKeySpec;
import net.i2p.crypto.elgamal.ElGamalPrivateKey;
import net.i2p.crypto.elgamal.spec.ElGamalParameterSpec;
import net.i2p.crypto.elgamal.spec.ElGamalPrivateKeySpec;
public class ElGamalPrivateKeyImpl
implements ElGamalPrivateKey, DHPrivateKey
{
static final long serialVersionUID = 4819350091141529678L;
BigInteger x;
ElGamalParameterSpec elSpec;
protected ElGamalPrivateKeyImpl()
{
}
ElGamalPrivateKeyImpl(
ElGamalPrivateKey key)
{
this.x = key.getX();
this.elSpec = key.getParameters();
}
ElGamalPrivateKeyImpl(
DHPrivateKey key)
{
this.x = key.getX();
this.elSpec = new ElGamalParameterSpec(key.getParams().getP(), key.getParams().getG());
}
ElGamalPrivateKeyImpl(
ElGamalPrivateKeySpec spec)
{
this.x = spec.getX();
this.elSpec = new ElGamalParameterSpec(spec.getParams().getP(), spec.getParams().getG());
}
ElGamalPrivateKeyImpl(
DHPrivateKeySpec spec)
{
this.x = spec.getX();
this.elSpec = new ElGamalParameterSpec(spec.getP(), spec.getG());
}
public String getAlgorithm()
{
return "ElGamal";
}
/**
* return the encoding format we produce in getEncoded().
*
* @return the string "PKCS#8"
*/
public String getFormat()
{
return "PKCS#8";
}
/**
* Return a PKCS8 representation of the key. The sequence returned
* represents a full PrivateKeyInfo object.
*
* @return a PKCS8 representation of the key.
*/
public byte[] getEncoded()
{
return null;
}
public ElGamalParameterSpec getParameters()
{
return elSpec;
}
public DHParameterSpec getParams()
{
return new DHParameterSpec(elSpec.getP(), elSpec.getG());
}
public BigInteger getX()
{
return x;
}
private void readObject(
ObjectInputStream in)
throws IOException, ClassNotFoundException
{
x = (BigInteger)in.readObject();
this.elSpec = new ElGamalParameterSpec((BigInteger)in.readObject(), (BigInteger)in.readObject());
}
private void writeObject(
ObjectOutputStream out)
throws IOException
{
out.writeObject(this.getX());
out.writeObject(elSpec.getP());
out.writeObject(elSpec.getG());
}
}
package net.i2p.crypto.elgamal.impl;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.math.BigInteger;
import javax.crypto.interfaces.DHPublicKey;
import javax.crypto.spec.DHParameterSpec;
import javax.crypto.spec.DHPublicKeySpec;
import net.i2p.crypto.elgamal.ElGamalPublicKey;
import net.i2p.crypto.elgamal.spec.ElGamalParameterSpec;
import net.i2p.crypto.elgamal.spec.ElGamalPublicKeySpec;
public class ElGamalPublicKeyImpl
implements ElGamalPublicKey, DHPublicKey
{
static final long serialVersionUID = 8712728417091216948L;
private BigInteger y;
private ElGamalParameterSpec elSpec;
ElGamalPublicKeyImpl(
ElGamalPublicKeySpec spec)
{
this.y = spec.getY();
this.elSpec = new ElGamalParameterSpec(spec.getParams().getP(), spec.getParams().getG());
}
ElGamalPublicKeyImpl(
DHPublicKeySpec spec)
{
this.y = spec.getY();
this.elSpec = new ElGamalParameterSpec(spec.getP(), spec.getG());
}
ElGamalPublicKeyImpl(
ElGamalPublicKey key)
{
this.y = key.getY();
this.elSpec = key.getParameters();
}
ElGamalPublicKeyImpl(
DHPublicKey key)
{
this.y = key.getY();
this.elSpec = new ElGamalParameterSpec(key.getParams().getP(), key.getParams().getG());
}
ElGamalPublicKeyImpl(
BigInteger y,
ElGamalParameterSpec elSpec)
{
this.y = y;
this.elSpec = elSpec;
}
public String getAlgorithm()
{
return "ElGamal";
}
public String getFormat()
{
return "X.509";
}
public byte[] getEncoded()
{
return null;
}
public ElGamalParameterSpec getParameters()
{
return elSpec;
}
public DHParameterSpec getParams()
{
return new DHParameterSpec(elSpec.getP(), elSpec.getG());
}
public BigInteger getY()
{
return y;
}
private void readObject(
ObjectInputStream in)
throws IOException, ClassNotFoundException
{
this.y = (BigInteger)in.readObject();
this.elSpec = new ElGamalParameterSpec((BigInteger)in.readObject(), (BigInteger)in.readObject());
}
private void writeObject(
ObjectOutputStream out)
throws IOException
{
out.writeObject(this.getY());
out.writeObject(elSpec.getP());
out.writeObject(elSpec.getG());
}
}
<html><body>
<p>
Implementation of ElGamal keys, used for I2PProvider.
Modified from Bouncy Castle 1.53.
See net.i2p.crypto.elgamal for license info.
</p><p>
Since 0.9.25.
</p>
</body></html>
<html><body>
<p>
Interfaces for ElGamal keys, used for I2PProvider.
Copied from Bouncy Castle 1.53.
</p><p>
Since 0.9.25.
</p><p><pre>
Copyright (c) 2000 - 2013 The Legion of the Bouncy Castle Inc. (http://www.bouncycastle.org)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</pre></p>
</body></html>
package net.i2p.crypto.elgamal.spec;
import java.security.spec.AlgorithmParameterSpec;
public class ElGamalGenParameterSpec
implements AlgorithmParameterSpec
{
private int primeSize;
/*
* @param primeSize the size (in bits) of the prime modulus.
*/
public ElGamalGenParameterSpec(
int primeSize)
{
this.primeSize = primeSize;
}
/**
* Returns the size in bits of the prime modulus.
*
* @return the size in bits of the prime modulus
*/
public int getPrimeSize()
{
return primeSize;
}
}
package net.i2p.crypto.elgamal.spec;
import java.security.spec.KeySpec;
public class ElGamalKeySpec
implements KeySpec
{
private ElGamalParameterSpec spec;
public ElGamalKeySpec(
ElGamalParameterSpec spec)
{
this.spec = spec;
}
public ElGamalParameterSpec getParams()
{
return spec;
}
}
package net.i2p.crypto;
/*
* Copyright (c) 2000 - 2013 The Legion of the Bouncy Castle Inc. (http://www.bouncycastle.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package net.i2p.crypto.elgamal.spec;
import java.math.BigInteger;
import java.security.spec.AlgorithmParameterSpec;
......
package net.i2p.crypto.elgamal.spec;
import java.math.BigInteger;
/**
* This class specifies an ElGamal private key with its associated parameters.
*
* @see ElGamalPublicKeySpec
*/
public class ElGamalPrivateKeySpec
extends ElGamalKeySpec
{
private BigInteger x;
public ElGamalPrivateKeySpec(
BigInteger x,
ElGamalParameterSpec spec)
{
super(spec);
this.x = x;
}
/**
* Returns the private value <code>x</code>.
*
* @return the private value <code>x</code>
*/
public BigInteger getX()
{
return x;
}
}
package net.i2p.crypto.elgamal.spec;
import java.math.BigInteger;
/**
* This class specifies an ElGamal public key with its associated parameters.
*
* @see ElGamalPrivateKeySpec
*/
public class ElGamalPublicKeySpec
extends ElGamalKeySpec
{
private BigInteger y;
public ElGamalPublicKeySpec(
BigInteger y,
ElGamalParameterSpec spec)
{
super(spec);
this.y = y;
}
/**
* Returns the public value <code>y</code>.
*
* @return the public value <code>y</code>
*/
public BigInteger getY()
{
return y;
}
}
<html><body>
<p>
Specs ElGamal keys, used for I2PProvider.
Copied from Bouncy Castle 1.53.
See net.i2p.crypto.elgamal for license info.
</p><p>
Since 0.9.25.
</p>
</body></html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment