One could say: There is a family of crypt() functions parameterised by the embedded function (DES, Blowfish, MD5, SHA-256, etc.) that realises the desired one-way (hash) property.

The early version of crypt() used DES to simulate a one-way (trapdoor-)function. Since the same password produces always the same crypt()-output, it would be too easy to pre-compute a lookup table (rainbow table) for a given crypt()-value to reveal the original password. Thus, as zentara said, a salt was added to the input to make lookups harder since that would require bigger tables. AFAIR, there were also some DES-related export restriction issues, that would make a non-DES version attractive.

SHA-256 is a digest-function of its own. The SHA-256-crypt() uses this hash-function as a replacement for DES (or MD5) - and adds some more rounds, etc. to take into account, that modern computers are faster than 30 years ago.

Recently, bcrypt() has been introduced using another embedded cryptographic function (Blowfish) with a salt and several iterations.

In order to allow various crypt()-functions the $type$salt$crypt notation was introduced (see /etc/shadow).

My short CPAN-research yield no implementation of SHA-256-Crypt(), but it should be feasible to implement a (not too fast) pure Perl implementation based on the modules that AM has suggested. Alternatively, it might be more useful to create an XS-wrapper around the reference implementation.

P.S. I used the terms hash-function and one-way/trapdoor-function a little bit sloppy, real cryptographers may pardon me that.

Update: First pure Perl draft implementation ready. Needs 15s to complete ;-) (slow as predicted)


In reply to Re^5: pure Perl SHA-256 crypt() by Perlbotics
in thread pure Perl SHA-256 crypt() by autocesco

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.