static byte[] hash_df(Digest digest,byte[] seedMaterial,int seedLength){
  byte[] temp=new byte[(seedLength + 7) / 8];
  int len=temp.length / digest.getDigestSize();
  int counter=1;
  byte[] dig=new byte[digest.getDigestSize()];
  for (int i=0; i <= len; i++) {
    digest.update((byte)counter);
    digest.update((byte)(seedLength >> 24));
    digest.update((byte)(seedLength >> 16));
    digest.update((byte)(seedLength >> 8));
    digest.update((byte)seedLength);
    digest.update(seedMaterial,0,seedMaterial.length);
    digest.doFinal(dig,0);
    int bytesToCopy=((temp.length - i * dig.length) > dig.length) ? dig.length : (temp.length - i * dig.length);
    System.arraycopy(dig,0,temp,i * dig.length,bytesToCopy);
    counter++;
  }
  if (seedLength % 8 != 0) {
    int shift=8 - (seedLength % 8);
    int carry=0;
    for (int i=0; i != temp.length; i++) {
      int b=temp[i] & 0xff;
      temp[i]=(byte)((b >>> shift) | (carry << (8 - shift)));
      carry=b;
    }
  }
  return temp;
}

static byte [ ] hash_df ( Digest digest , byte [ ] seedMaterial , int seedLength ) { byte [ ] temp = new byte [ ( seedLength + 7 ) / 8 ] ; int len = temp . length / digest . getDigestSize ( ) ; int counter = 1 ; byte [ ] dig = new byte [ digest . getDigestSize ( ) ] ; for ( int i = 0 ; i <= len ; i ++ ) { digest . update ( ( byte ) counter ) ; digest . update ( ( byte ) ( seedLength > > 24 ) ) ; digest . update ( ( byte ) ( seedLength > > 16 ) ) ; digest . update ( ( byte ) ( seedLength > > 8 ) ) ; digest . update ( ( byte ) seedLength ) ; digest . update ( seedMaterial , 0 , seedMaterial . length ) ; digest . doFinal ( dig , 0 ) ; int bytesToCopy = ( ( temp . length - i * dig . length ) > dig . length ) ? dig . length : ( temp . length - i * dig . length ) ; System . arraycopy ( dig , 0 , temp , i * dig . length , bytesToCopy ) ; counter ++ ; } if ( seedLength % 8 != 0 ) { int shift = 8 - ( seedLength % 8 ) ; int carry = 0 ; for ( int i = 0 ; i != temp . length ; i ++ ) { int b = temp [ i ] & 0xff ; temp [ i ] = ( byte ) ( ( b > > > shift ) | ( carry << ( 8 - shift ) ) ) ; carry = b ; } } return temp ; }
used by both dual ec and hash .
