Search in sources :

Example 1 with McEliecePublicKeyParameters

use of com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePublicKeyParameters in project LinLong-Java by zhenwei1108.

the class McElieceKeyFactorySpi method generatePublic.

public PublicKey generatePublic(SubjectPublicKeyInfo pki) throws IOException {
    // get the inner type inside the BIT STRING
    ASN1Primitive innerType = pki.parsePublicKey();
    McEliecePublicKey key = McEliecePublicKey.getInstance(innerType);
    return new BCMcEliecePublicKey(new McEliecePublicKeyParameters(key.getN(), key.getT(), key.getG()));
}
Also used : McEliecePublicKeyParameters(com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePublicKeyParameters) ASN1Primitive(com.github.zhenwei.core.asn1.ASN1Primitive) McEliecePublicKey(com.github.zhenwei.core.pqc.asn1.McEliecePublicKey)

Example 2 with McEliecePublicKeyParameters

use of com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePublicKeyParameters in project LinLong-Java by zhenwei1108.

the class McElieceKeyFactorySpi method engineGeneratePublic.

/**
 * Converts, if possible, a key specification into a {@link BCMcEliecePublicKey}.  {@link
 * X509EncodedKeySpec}.
 *
 * @param keySpec the key specification
 * @return the McEliece public key
 * @throws InvalidKeySpecException if the key specification is not supported.
 */
protected PublicKey engineGeneratePublic(KeySpec keySpec) throws InvalidKeySpecException {
    if (keySpec instanceof X509EncodedKeySpec) {
        // get the DER-encoded Key according to X.509 from the spec
        byte[] encKey = ((X509EncodedKeySpec) keySpec).getEncoded();
        // decode the SubjectPublicKeyInfo data structure to the pki object
        SubjectPublicKeyInfo pki;
        try {
            pki = SubjectPublicKeyInfo.getInstance(ASN1Primitive.fromByteArray(encKey));
        } catch (IOException e) {
            throw new InvalidKeySpecException(e.toString());
        }
        try {
            if (PQCObjectIdentifiers.mcEliece.equals(pki.getAlgorithm().getAlgorithm())) {
                McEliecePublicKey key = McEliecePublicKey.getInstance(pki.parsePublicKey());
                return new BCMcEliecePublicKey(new McEliecePublicKeyParameters(key.getN(), key.getT(), key.getG()));
            } else {
                throw new InvalidKeySpecException("Unable to recognise OID in McEliece public key");
            }
        } catch (IOException cce) {
            throw new InvalidKeySpecException("Unable to decode X509EncodedKeySpec: " + cce.getMessage());
        }
    }
    throw new InvalidKeySpecException("Unsupported key specification: " + keySpec.getClass() + ".");
}
Also used : X509EncodedKeySpec(java.security.spec.X509EncodedKeySpec) McEliecePublicKeyParameters(com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePublicKeyParameters) IOException(java.io.IOException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) SubjectPublicKeyInfo(com.github.zhenwei.core.asn1.x509.SubjectPublicKeyInfo) McEliecePublicKey(com.github.zhenwei.core.pqc.asn1.McEliecePublicKey)

Example 3 with McEliecePublicKeyParameters

use of com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePublicKeyParameters in project LinLong-Java by zhenwei1108.

the class McElieceKeyPairGeneratorSpi method generateKeyPair.

public KeyPair generateKeyPair() {
    AsymmetricCipherKeyPair generateKeyPair = kpg.generateKeyPair();
    McEliecePrivateKeyParameters sk = (McEliecePrivateKeyParameters) generateKeyPair.getPrivate();
    McEliecePublicKeyParameters pk = (McEliecePublicKeyParameters) generateKeyPair.getPublic();
    return new KeyPair(new BCMcEliecePublicKey(pk), new BCMcEliecePrivateKey(sk));
}
Also used : McEliecePrivateKeyParameters(com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePrivateKeyParameters) KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair) McEliecePublicKeyParameters(com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePublicKeyParameters) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Aggregations

McEliecePublicKeyParameters (com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePublicKeyParameters)3 McEliecePublicKey (com.github.zhenwei.core.pqc.asn1.McEliecePublicKey)2 ASN1Primitive (com.github.zhenwei.core.asn1.ASN1Primitive)1 SubjectPublicKeyInfo (com.github.zhenwei.core.asn1.x509.SubjectPublicKeyInfo)1 AsymmetricCipherKeyPair (com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)1 McEliecePrivateKeyParameters (com.github.zhenwei.core.pqc.crypto.mceliece.McEliecePrivateKeyParameters)1 IOException (java.io.IOException)1 KeyPair (java.security.KeyPair)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)1