use of com.github.zhenwei.core.pqc.asn1.McEliecePublicKey in project jmulticard by ctt-gob-es.
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() + ".");
}
use of com.github.zhenwei.core.pqc.asn1.McEliecePublicKey in project jmulticard by ctt-gob-es.
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()));
}
use of com.github.zhenwei.core.pqc.asn1.McEliecePublicKey in project LinLong-Java by zhenwei1108.
the class BCMcEliecePublicKey method getEncoded.
/**
* Return the keyData to encode in the SubjectPublicKeyInfo structure.
* <p>
* The ASN.1 definition of the key structure is
* </p>
* <pre>
* McEliecePublicKey ::= SEQUENCE {
* n Integer -- length of the code
* t Integer -- error correcting capability
* matrixG OctetString -- generator matrix as octet string
* }
* </pre>
*
* @return the keyData to encode in the SubjectPublicKeyInfo structure
*/
public byte[] getEncoded() {
McEliecePublicKey key = new McEliecePublicKey(params.getN(), params.getT(), params.getG());
AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PQCObjectIdentifiers.mcEliece);
try {
SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algorithmIdentifier, key);
return subjectPublicKeyInfo.getEncoded();
} catch (IOException e) {
return null;
}
}
use of com.github.zhenwei.core.pqc.asn1.McEliecePublicKey in project LinLong-Java by zhenwei1108.
the class BCMcElieceCCA2PublicKey method getEncoded.
/**
* Return the keyData to encode in the SubjectPublicKeyInfo structure.
* <p>
* The ASN.1 definition of the key structure is
* <pre>
* McEliecePublicKey ::= SEQUENCE {
* n Integer -- length of the code
* t Integer -- error correcting capability
* matrixG OctetString -- generator matrix as octet string
* }
* </pre>
*
* @return the keyData to encode in the SubjectPublicKeyInfo structure
*/
public byte[] getEncoded() {
McElieceCCA2PublicKey key = new McElieceCCA2PublicKey(params.getN(), params.getT(), params.getG(), Utils.getDigAlgId(params.getDigest()));
AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PQCObjectIdentifiers.mcElieceCca2);
try {
SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algorithmIdentifier, key);
return subjectPublicKeyInfo.getEncoded();
} catch (IOException e) {
return null;
}
}
use of com.github.zhenwei.core.pqc.asn1.McEliecePublicKey in project jmulticard by ctt-gob-es.
the class BCMcEliecePublicKey method getEncoded.
/**
* Return the keyData to encode in the SubjectPublicKeyInfo structure.
* <p>
* The ASN.1 definition of the key structure is
* </p>
* <pre>
* McEliecePublicKey ::= SEQUENCE {
* n Integer -- length of the code
* t Integer -- error correcting capability
* matrixG OctetString -- generator matrix as octet string
* }
* </pre>
* @return the keyData to encode in the SubjectPublicKeyInfo structure
*/
public byte[] getEncoded() {
McEliecePublicKey key = new McEliecePublicKey(params.getN(), params.getT(), params.getG());
AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PQCObjectIdentifiers.mcEliece);
try {
SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algorithmIdentifier, key);
return subjectPublicKeyInfo.getEncoded();
} catch (IOException e) {
return null;
}
}
Aggregations