Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.jce.provider;
Generator for PBE derived keys and ivs as defined by IEEE P1363a
This implementation is based on draft 9 of IEEE P1363a. Note: as this is still a draft the output of this generator may change, don't use it for anything that might be subject to long term storage.
     implements DerivationFunction
     private Digest  digest;
     private byte[]  shared;
     private byte[]  iv;

Construct a KDF2 Parameters generator. Generates key material according to IEEE P1363a - if you want orthodox results you should use a digest specified in the standard.

Note: IEEE P1363a standard is still a draft standard, if the standard changes this function, the output of this function will change as well. Don't use this routine for anything subject to long term storage.

digest the digest to be used as the source of derived keys.
     public BrokenKDF2BytesGenerator(
         Digest  digest)
         this. = digest;
     public void init(
         DerivationParameters    param)
         if (!(param instanceof KDFParameters))
             throw new IllegalArgumentException("KDF parameters required for KDF2Generator");
         KDFParameters   p = (KDFParameters)param;
          = p.getSharedSecret();
          = p.getIV();

return the underlying digest.
     public Digest getDigest()
         return ;

fill len bytes of the output buffer with bytes generated from the derivation function.

java.lang.IllegalArgumentException if the size of the request will cause an overflow.
org.bouncycastle.crypto.DataLengthException if the out buffer is too small.
     public int generateBytes(
         byte[]  out,
         int     outOff,
         int     len)
         if ((out.length - len) < outOff)
             throw new DataLengthException("output buffer too small");
         long    oBits = len * 8;
         // this is at odds with the standard implementation, the
         // maximum value should be hBits * (2^23 - 1) where hBits
         // is the digest output size in bits. We can't have an
         // array with a long index at the moment...
         if (oBits > (.getDigestSize() * 8 * (2L^32 - 1)))
             new IllegalArgumentException("Output length to large");
         int cThreshold = (int)(oBits / .getDigestSize());
         byte[] dig = null;
         dig = new byte[.getDigestSize()];
         for (int counter = 1; counter <= cThresholdcounter++)
            .update(, 0, .);
            .update((byte)(counter & 0xff));
            .update((byte)((counter >> 8) & 0xff));
            .update((byte)((counter >> 16) & 0xff));
            .update((byte)((counter >> 24) & 0xff));
            .update(, 0, .);
            .doFinal(dig, 0);
            if ((len - outOff) > dig.length)
                System.arraycopy(dig, 0, outoutOffdig.length);
                outOff += dig.length;
                System.arraycopy(dig, 0, outoutOfflen - outOff);
        return len;
New to GrepCode? Check out our FAQ X