org.bouncycastle.pqc.asn1.McEliecePublicKey Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-ext-jdk15on Show documentation
Show all versions of bcprov-ext-jdk15on Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.7. Note: this package includes the IDEA and NTRU encryption algorithms.
package org.bouncycastle.pqc.asn1;
import java.math.BigInteger;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.pqc.math.linearalgebra.GF2Matrix;
public class McEliecePublicKey
extends ASN1Object
{
private final int n;
private final int t;
private final GF2Matrix g;
public McEliecePublicKey(int n, int t, GF2Matrix g)
{
this.n = n;
this.t = t;
this.g = new GF2Matrix(g);
}
private McEliecePublicKey(ASN1Sequence seq)
{
BigInteger bigN = ((ASN1Integer)seq.getObjectAt(0)).getValue();
n = bigN.intValue();
BigInteger bigT = ((ASN1Integer)seq.getObjectAt(1)).getValue();
t = bigT.intValue();
g = new GF2Matrix(((ASN1OctetString)seq.getObjectAt(2)).getOctets());
}
public int getN()
{
return n;
}
public int getT()
{
return t;
}
public GF2Matrix getG()
{
return new GF2Matrix(g);
}
public ASN1Primitive toASN1Primitive()
{
ASN1EncodableVector v = new ASN1EncodableVector();
// encode
v.add(new ASN1Integer(n));
// encode
v.add(new ASN1Integer(t));
// encode
v.add(new DEROctetString(g.getEncoded()));
return new DERSequence(v);
}
public static McEliecePublicKey getInstance(Object o)
{
if (o instanceof McEliecePublicKey)
{
return (McEliecePublicKey)o;
}
else if (o != null)
{
return new McEliecePublicKey(ASN1Sequence.getInstance(o));
}
return null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy