private byte[] computeMessage(GF2Vector mr) throws Exception { byte[] mrBytes = mr.getEncoded(); // find first non-zero byte int index; for (index = mrBytes.length - 1; index >= 0 && mrBytes[index] == 0; index--) { ; } // check if padding byte is valid if (index<0 || mrBytes[index] != 0x01) { throw new Exception("Bad Padding: invalid ciphertext"); } // extract and return message byte[] mBytes = new byte[index]; System.arraycopy(mrBytes, 0, mBytes, 0, index); return mBytes; }
private byte[] computeMessage(GF2Vector mr) throws InvalidCipherTextException { byte[] mrBytes = mr.getEncoded(); // find first non-zero byte int index; for (index = mrBytes.length - 1; index >= 0 && mrBytes[index] == 0; index--) { ; } // check if padding byte is valid if (index<0 || mrBytes[index] != 0x01) { throw new InvalidCipherTextException("Bad Padding: invalid ciphertext"); } // extract and return message byte[] mBytes = new byte[index]; System.arraycopy(mrBytes, 0, mBytes, 0, index); return mBytes; }
/** * 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(); }
/** * 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(); }
byte[] rBytes = r.getEncoded(); .getEncoded();
byte[] rPrimeBytes = rPrime.getEncoded(); z).getEncoded();
c4Vec, z).getEncoded();
byte[] rPrimeBytes = rPrime.getEncoded(); z).getEncoded();
byte[] rBytes = r.getEncoded(); .getEncoded();
GF2Vector[] decC1 = McElieceCCA2Primitives.decryptionPrimitive((McElieceCCA2PrivateKeyParameters)key, hrmVec); byte[] rBytes = decC1[0].getEncoded();
byte[] c4 = c4z[0].getEncoded(); GF2Vector z = c4z[1];
GF2Vector[] c1Dec = McElieceCCA2Primitives.decryptionPrimitive((McElieceCCA2PrivateKeyParameters)key, c1Vec); byte[] rPrimeBytes = c1Dec[0].getEncoded();
byte[] rBytes = decC1[0].getEncoded();
GF2Vector[] c1Dec = McElieceCCA2Primitives.decryptionPrimitive((McElieceCCA2PrivateKeyParameters)key, c1Vec); byte[] rPrimeBytes = c1Dec[0].getEncoded();
byte[] c4 = c4z[0].getEncoded(); GF2Vector z = c4z[1];