public void init(boolean forSigning, CipherParameters param) { if (forSigning) { if (param instanceof ParametersWithRandom) { ParametersWithRandom rParam = (ParametersWithRandom)param; this.sr = rParam.getRandom(); this.key = (McEliecePublicKeyParameters)rParam.getParameters(); this.initCipherEncrypt((McEliecePublicKeyParameters)key); } else { this.sr = new SecureRandom(); this.key = (McEliecePublicKeyParameters)param; this.initCipherEncrypt((McEliecePublicKeyParameters)key); } } else { this.key = (McEliecePrivateKeyParameters)param; this.initCipherDecrypt((McEliecePrivateKeyParameters)key); } }
/** * 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 computeMessage(mVec);