I noticed some possible issues with this code

Only the first character of strings will take part in your entropy pool:

$old_mix = $Hash->(pack "LaaaaLLLLaL" , $rand, $old_mix, "#" , $Host, '#', $$, $time, $ms, $count , $salt, $old_rand);

The "a" format specifier alone will only copy over the first character of the source string. To copy over the whole source string, use "a*".

my $ret = encode_base64( $Hash->( pack "aL", $old_mix, $old_rand ) );

Note that this "pack" also suffers the same problem, so only the first character from $old_mix gets used for hashing to a result. This entropy loss is made even more stunning given:

our $Hash = \&Digest::MD5::md5_base64;

So $old_mix is the result of a base64 encoding, thus its first character retains only a fraction of a byte of entropy.

Also, $ret is being assigned a doubly-base64-encoded hashed value, so it will be longer than necessary, and its entropy density will be less than expected. This problem is benign from a security standpoint, unless $Truncate gets used:

$ret = substr( $ret, 0, $Truncate )

So truncation will cause a greater than expected loss of entropy in the result.

As for using MD5, in this context I don't think its weaknesses are a liability -- it is being used for mixing a secret key, so even if an attacker can concoct a collision for this secret, this pseudo-secret key will be useless. However, I would personally choose a newer hashing algorithm, due to unjustified paranoia.


In reply to Re: Session id generation with Perl once more by coicles
in thread Session id generation with Perl once more by Dallaylaen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.