Search in sources :

Example 6 with McEliecePrivateKey

use of com.github.zhenwei.core.pqc.asn1.McEliecePrivateKey in project LinLong-Java by zhenwei1108.

the class BCMcElieceCCA2PrivateKey method getEncoded.

/**
 * Return the keyData to encode in the SubjectPublicKeyInfo structure.
 * <p>
 * The ASN.1 definition of the key structure is
 * <pre>
 *   McEliecePrivateKey ::= 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
 *     matrixH       OCTET STRING             -- canonical check matrix
 *     sqRootMatrix  SEQUENCE OF OCTET STRING -- square root matrix
 *   }
 * </pre>
 *
 * @return the keyData to encode in the SubjectPublicKeyInfo structure
 */
public byte[] getEncoded() {
    PrivateKeyInfo pki;
    try {
        McElieceCCA2PrivateKey privateKey = new McElieceCCA2PrivateKey(getN(), getK(), getField(), getGoppaPoly(), getP(), Utils.getDigAlgId(params.getDigest()));
        AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PQCObjectIdentifiers.mcElieceCca2);
        pki = new PrivateKeyInfo(algorithmIdentifier, privateKey);
        return pki.getEncoded();
    } catch (IOException e) {
        return null;
    }
}
Also used : McElieceCCA2PrivateKey(com.github.zhenwei.core.pqc.asn1.McElieceCCA2PrivateKey) IOException(java.io.IOException) PrivateKeyInfo(com.github.zhenwei.core.asn1.pkcs.PrivateKeyInfo) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Example 7 with McEliecePrivateKey

use of com.github.zhenwei.core.pqc.asn1.McEliecePrivateKey in project LinLong-Java by zhenwei1108.

the class BCMcEliecePrivateKey method getEncoded.

/**
 * Return the key data to encode in the SubjectPublicKeyInfo structure.
 * <p>
 * The ASN.1 definition of the key structure is
 * </p>
 * <pre>
 *   McEliecePrivateKey ::= SEQUENCE {
 *     n          INTEGER                   -- length of the code
 *     k          INTEGER                   -- dimension of the code
 *     fieldPoly  OCTET STRING              -- field polynomial defining GF(2&circ;m)
 *     getGoppaPoly()  OCTET STRING              -- irreducible Goppa polynomial
 *     sInv       OCTET STRING              -- matrix S&circ;-1
 *     p1         OCTET STRING              -- permutation P1
 *     p2         OCTET STRING              -- permutation P2
 *     h          OCTET STRING              -- canonical check matrix
 *     qInv       SEQUENCE OF OCTET STRING  -- matrix used to compute square roots
 *   }
 * </pre>
 *
 * @return the key data to encode in the SubjectPublicKeyInfo structure
 */
public byte[] getEncoded() {
    McEliecePrivateKey privateKey = new McEliecePrivateKey(params.getN(), params.getK(), params.getField(), params.getGoppaPoly(), params.getP1(), params.getP2(), params.getSInv());
    PrivateKeyInfo pki;
    try {
        AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PQCObjectIdentifiers.mcEliece);
        pki = new PrivateKeyInfo(algorithmIdentifier, privateKey);
    } catch (IOException e) {
        return null;
    }
    try {
        byte[] encoded = pki.getEncoded();
        return encoded;
    } catch (IOException e) {
        return null;
    }
}
Also used : IOException(java.io.IOException) McEliecePrivateKey(com.github.zhenwei.core.pqc.asn1.McEliecePrivateKey) PrivateKeyInfo(com.github.zhenwei.core.asn1.pkcs.PrivateKeyInfo) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Aggregations

IOException (java.io.IOException)5 PrivateKeyInfo (com.github.zhenwei.core.asn1.pkcs.PrivateKeyInfo)3 McEliecePrivateKey (com.github.zhenwei.core.pqc.asn1.McEliecePrivateKey)3 McEliecePrivateKey (org.bouncycastle.pqc.asn1.McEliecePrivateKey)3 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)2 McEliecePrivateKeyParameters (com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePrivateKeyParameters)2 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)2 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)2 PrivateKeyInfo (org.bouncycastle.asn1.pkcs.PrivateKeyInfo)2 McEliecePrivateKeyParameters (org.bouncycastle.pqc.crypto.mceliece.McEliecePrivateKeyParameters)2 ASN1Primitive (com.github.zhenwei.core.asn1.ASN1Primitive)1 McElieceCCA2PrivateKey (com.github.zhenwei.core.pqc.asn1.McElieceCCA2PrivateKey)1 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)1 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)1