![JAR search and dependency download from the Maven repository](/logo.png)
nl.open.jwtdependency.org.bouncycastle.pqc.asn1.McElieceCCA2PrivateKey Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-jwt-nodependencies Show documentation
Show all versions of java-jwt-nodependencies Show documentation
This is a drop in replacement for the auth0 java-jwt library (see https://github.com/auth0/java-jwt). This jar makes sure there are no external dependencies (e.g. fasterXml, Apacha Commons) needed. This is useful when deploying to an application server (e.g. tomcat with Alfreso or Pega).
The newest version!
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.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.pqc.math.linearalgebra.GF2mField;
import org.bouncycastle.pqc.math.linearalgebra.Permutation;
import org.bouncycastle.pqc.math.linearalgebra.PolynomialGF2mSmallM;
/**
* Return the keyData to encode in the PrivateKeyInfo structure.
*
* The ASN.1 definition of the key structure is
*
* McElieceCCA2PrivateKey ::= SEQUENCE {
* m INTEGER -- extension degree of the field
* k INTEGER -- dimension of the code
* field OCTET STRING -- field polynomial
* goppaPoly OCTET STRING -- irreducible Goppa polynomial
* p OCTET STRING -- permutation vector
* digest AlgorithmIdentifier -- algorithm identifier for CCA2 digest
* }
*
*
*/
public class McElieceCCA2PrivateKey
extends ASN1Object
{
private int n;
private int k;
private byte[] encField;
private byte[] encGp;
private byte[] encP;
private AlgorithmIdentifier digest;
public McElieceCCA2PrivateKey(int n, int k, GF2mField field, PolynomialGF2mSmallM goppaPoly, Permutation p, AlgorithmIdentifier digest)
{
this.n = n;
this.k = k;
this.encField = field.getEncoded();
this.encGp = goppaPoly.getEncoded();
this.encP = p.getEncoded();
this.digest = digest;
}
private McElieceCCA2PrivateKey(ASN1Sequence seq)
{
BigInteger bigN = ((ASN1Integer)seq.getObjectAt(0)).getValue();
n = bigN.intValue();
BigInteger bigK = ((ASN1Integer)seq.getObjectAt(1)).getValue();
k = bigK.intValue();
encField = ((ASN1OctetString)seq.getObjectAt(2)).getOctets();
encGp = ((ASN1OctetString)seq.getObjectAt(3)).getOctets();
encP = ((ASN1OctetString)seq.getObjectAt(4)).getOctets();
digest = AlgorithmIdentifier.getInstance(seq.getObjectAt(5));
}
public int getN()
{
return n;
}
public int getK()
{
return k;
}
public GF2mField getField()
{
return new GF2mField(encField);
}
public PolynomialGF2mSmallM getGoppaPoly()
{
return new PolynomialGF2mSmallM(this.getField(), encGp);
}
public Permutation getP()
{
return new Permutation(encP);
}
public AlgorithmIdentifier getDigest()
{
return digest;
}
public ASN1Primitive toASN1Primitive()
{
ASN1EncodableVector v = new ASN1EncodableVector();
// encode
v.add(new ASN1Integer(n));
// encode
v.add(new ASN1Integer(k));
// encode
v.add(new DEROctetString(encField));
// encode
v.add(new DEROctetString(encGp));
// encode
v.add(new DEROctetString(encP));
v.add(digest);
return new DERSequence(v);
}
public static McElieceCCA2PrivateKey getInstance(Object o)
{
if (o instanceof McElieceCCA2PrivateKey)
{
return (McElieceCCA2PrivateKey)o;
}
else if (o != null)
{
return new McElieceCCA2PrivateKey(ASN1Sequence.getInstance(o));
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy