/** * @return a human readable form of the key */ public String toString() { String result = "McEliecePublicKey:\n"; result += " length of the code : " + params.getN() + "\n"; result += " error correction capability: " + params.getT() + "\n"; result += " generator matrix : " + params.getG(); return result; }
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())); }
/** * @return the generator matrix */ public GF2Matrix getG() { return params.getG(); }
/** * @return the length of the code */ public int getN() { return params.getN(); }
/** * @return the dimension of the code */ public int getK() { return params.getK(); }
/** * @return the error correction capability of the code */ public int getT() { return params.getT(); }
return new BCMcEliecePublicKey(new McEliecePublicKeyParameters(key.getN(), key.getT(), key.getG()));
/** * Encrypt a plain text. * * @param input the plain text * @return the cipher text */ public byte[] messageEncrypt(byte[] input) { if (!forEncryption) { throw new IllegalStateException("cipher initialised for decryption"); } GF2Vector m = computeMessageRepresentative(input); GF2Vector z = new GF2Vector(n, t, sr); GF2Matrix g = ((McEliecePublicKeyParameters)key).getG(); Vector mG = g.leftMultiply(m); GF2Vector mGZ = (GF2Vector)mG.add(z); return mGZ.getEncoded(); }
/** * Return the key size of the given key object. * * @param key the McElieceKeyParameters object * @return the keysize of the given key object */ public int getKeySize(McElieceKeyParameters key) { if (key instanceof McEliecePublicKeyParameters) { return ((McEliecePublicKeyParameters)key).getN(); } if (key instanceof McEliecePrivateKeyParameters) { return ((McEliecePrivateKeyParameters)key).getN(); } throw new IllegalArgumentException("unsupported type"); }
McEliecePublicKeyParameters pubKey = new McEliecePublicKeyParameters(n, t, g); McEliecePrivateKeyParameters privKey = new McEliecePrivateKeyParameters(n, k, field, gp, p1, p2, matrixSandInverse[1]);
/** * Encrypt a plain text. * * @param input the plain text * @return the cipher text */ public byte[] messageEncrypt(byte[] input) { GF2Vector m = computeMessageRepresentative(input); GF2Vector z = new GF2Vector(n, t, sr); GF2Matrix g = ((McEliecePublicKeyParameters)key).getG(); Vector mG = g.leftMultiply(m); GF2Vector mGZ = (GF2Vector)mG.add(z); return mGZ.getEncoded(); }
/** * Return the key size of the given key object. * * @param key the McElieceKeyParameters object * @return the keysize of the given key object */ public int getKeySize(McElieceKeyParameters key) { if (key instanceof McEliecePublicKeyParameters) { return ((McEliecePublicKeyParameters)key).getN(); } if (key instanceof McEliecePrivateKeyParameters) { return ((McEliecePrivateKeyParameters)key).getN(); } throw new IllegalArgumentException("unsupported type"); }
/** * Compare this key with another object. * * @param other the other object * @return the result of the comparison */ public boolean equals(Object other) { if (other instanceof BCMcEliecePublicKey) { BCMcEliecePublicKey otherKey = (BCMcEliecePublicKey)other; return (params.getN() == otherKey.getN()) && (params.getT() == otherKey.getT()) && (params.getG().equals(otherKey.getG())); } return false; }
McEliecePublicKeyParameters pubKey = new McEliecePublicKeyParameters(OID, n, t, g, mcElieceParams.getParameters()); McEliecePrivateKeyParameters privKey = new McEliecePrivateKeyParameters(OID, n, k, field, gp, matrixSandInverse[1], p1, p2, h, sqRootMatrix, mcElieceParams.getParameters());
/** * 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; } }