public McEliecePKCS() { super(new McElieceCipher()); } }
protected void initCipherDecrypt(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException { CipherParameters param; param = McElieceKeysToParams.generatePrivateKeyParameter((PrivateKey)key); cipher.init(false, param); this.maxPlainTextSize = cipher.maxPlainTextSize; this.cipherTextSize = cipher.cipherTextSize; }
protected byte[] messageDecrypt(byte[] input) throws IllegalBlockSizeException, BadPaddingException { byte[] output = null; try { output = cipher.messageDecrypt(input); } catch (Exception e) { e.printStackTrace(); } return output; }
public void init(boolean forEncryption, CipherParameters param) { this.forEncryption = forEncryption; if (forEncryption) { if (param instanceof ParametersWithRandom) { ParametersWithRandom rParam = (ParametersWithRandom)param; this.sr = rParam.getRandom(); this.key = (McEliecePublicKeyParameters)rParam.getParameters(); this.initCipherEncrypt((McEliecePublicKeyParameters)key); } else { this.sr = CryptoServicesRegistrar.getSecureRandom(); this.key = (McEliecePublicKeyParameters)param; this.initCipherEncrypt((McEliecePublicKeyParameters)key); } } else { this.key = (McEliecePrivateKeyParameters)param; this.initCipherDecrypt((McEliecePrivateKeyParameters)key); } }
protected byte[] messageEncrypt(byte[] input) throws IllegalBlockSizeException, BadPaddingException { byte[] output = null; try { output = cipher.messageEncrypt(input); } catch (Exception e) { e.printStackTrace(); } return output; }
public int getKeySize(Key key) throws InvalidKeyException { McElieceKeyParameters mcElieceKeyParameters; if (key instanceof PublicKey) { mcElieceKeyParameters = (McElieceKeyParameters)McElieceKeysToParams.generatePublicKeyParameter((PublicKey)key); } else { mcElieceKeyParameters = (McElieceKeyParameters)McElieceKeysToParams.generatePrivateKeyParameter((PrivateKey)key); } return cipher.getKeySize(mcElieceKeyParameters); }
/** * 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(); }
protected void initCipherEncrypt(Key key, AlgorithmParameterSpec params, SecureRandom sr) throws InvalidKeyException, InvalidAlgorithmParameterException { CipherParameters param; param = McElieceKeysToParams.generatePublicKeyParameter((PublicKey)key); param = new ParametersWithRandom(param, sr); cipher.init(true, param); this.maxPlainTextSize = cipher.maxPlainTextSize; this.cipherTextSize = cipher.cipherTextSize; }