public void init(boolean forEncryption,CipherParameters params) throws IllegalArgumentException {
  if (!(params instanceof ParametersWithIV)) {
    throw new IllegalArgumentException("Grain-128 Init parameters must include an IV");
  }
  ParametersWithIV ivParams=(ParametersWithIV)params;
  byte[] iv=ivParams.getIV();
  if (iv == null || iv.length != 12) {
    throw new IllegalArgumentException("Grain-128  requires exactly 12 bytes of IV");
  }
  if (!(ivParams.getParameters() instanceof KeyParameter)) {
    throw new IllegalArgumentException("Grain-128 Init parameters must include a key");
  }
  KeyParameter key=(KeyParameter)ivParams.getParameters();
  workingIV=new byte[key.getKey().length];
  workingKey=new byte[key.getKey().length];
  lfsr=new int[STATE_SIZE];
  nfsr=new int[STATE_SIZE];
  out=new byte[4];
  System.arraycopy(iv,0,workingIV,0,iv.length);
  System.arraycopy(key.getKey(),0,workingKey,0,key.getKey().length);
  reset();
}

public void init ( boolean forEncryption , CipherParameters params ) throws IllegalArgumentException { if ( ! ( params instanceof ParametersWithIV ) ) { throw new IllegalArgumentException ( "Grain-128 Init parameters must include an IV" ) ; } ParametersWithIV ivParams = ( ParametersWithIV ) params ; byte [ ] iv = ivParams . getIV ( ) ; if ( iv == null || iv . length != 12 ) { throw new IllegalArgumentException ( "Grain-128  requires exactly 12 bytes of IV" ) ; } if ( ! ( ivParams . getParameters ( ) instanceof KeyParameter ) ) { throw new IllegalArgumentException ( "Grain-128 Init parameters must include a key" ) ; } KeyParameter key = ( KeyParameter ) ivParams . getParameters ( ) ; workingIV = new byte [ key . getKey ( ) . length ] ; workingKey = new byte [ key . getKey ( ) . length ] ; lfsr = new int [ STATE_SIZE ] ; nfsr = new int [ STATE_SIZE ] ; out = new byte [ 4 ] ; System . arraycopy ( iv , 0 , workingIV , 0 , iv . length ) ; System . arraycopy ( key . getKey ( ) , 0 , workingKey , 0 , key . getKey ( ) . length ) ; reset ( ) ; }
initialize a grain - 128 cipher .
