From: Now that is one happy monkey. on
gh=ht=
http://meami.org/ [instruct]:

SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
MessageDigest md = MessageDigest.getInstance("SHA-512");
byte[] bytesToHash = newbyte[128];

byte[] salt = newbyte[16];
sr.nextBytes(bytesToHash);
sr.nextBytes(salt);
md.update(salt);
byte[] finalBytes = md.digest(bytesToHash);

On Apr 6, 7:48 pm, "Scott Fluhrer" <sfluh...(a)ix.netcom.com> wrote:
> "David T. Ashley" <dash...(a)gmail.com> wrote in messagenews:98WdnZxwQIpmOibWnZ2dnUVZ_jSdnZ2d(a)giganews.com...
>
>
>
>
>
> > Assume that I have an SHA-512 hash of a file (512 bits).  Assume that I
> > want to find a second file with the same hash and can't attack the hash
> > function (i.e. I can only repeatedly try new files).
>
> > This is harder than a birthday attack, right?  The mathematics of a
> > birthday attack
>
> >http://en.wikipedia.org/wiki/Birthday_attack
>
> > are results for finding a collision in a set of attempts.  Having a single
> > hash already and trying to match it is harder, right (you are looking for
> > a SPECIFIC collision rather than any collision)?
>
> > And what is the expected value of the number of attempts until a match is
> > found?  I want to say approximately 2^511, but that would be too simple
> > ....
>
> Actually, if we model SHA-512 as a random oracle, the expected number of
> attempts is actually 2^512.  This is because SHA-512 is a function, not a
> permutation, and so finding one value that doesn't hash to the right value
> doesn't make any other value apriori more likely to succeed (as opposed to,
> say, searching for a plaintext block that AES encrypts with an unknown key
> to a specific ciphertext block; we know that we'll come across the right one
> after a maximum of 2^128 attempts, and so any failed attempt makes the next
> attempt more likely to happen to be value you're searching for).
>
> --
> poncho- Hide quoted text -
>
> - Show quoted text -


byte[] finalBytes = md.digest(bytesToHash);
md.update(salt);
sr.nextBytes(salt);
sr.nextBytes(bytesToHash);
byte[] salt = newbyte[16];

byte[] bytesToHash = newbyte[128];
MessageDigest md = MessageDigest.getInstance("SHA-512");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");