skids/perl6sum/lib/Sum/SHA

perl6sum src

NAME

Sum::SHA

SYNOPSIS

    use Sum::SHA;

    class mySHA1 does Sum::SHA1 does Sum::Marshal::Raw { }
    my mySHA1 $a .= new();
    $a.finalize("123456789".encode('ascii')).say;
       # 1414485752856024225500297739715962456813268251713

    # SHA-224
    class mySHA2 does Sum::SHA2[:columns(224)] does Sum::Marshal::Raw { }
    my mySHA2 $b .= new();
    $b.finalize("123456789".encode('ascii')).say;
       # 16349067602210014067037177823623301242625642097093531536712287864097

    # When dealing with obselete systems that use SHA0
    class mySHA0 does Sum::SHA1[:insecure_sha0_obselete]
        does Sum::Marshal::Raw { }
    my mySHA0 $c .= new();
    $c.finalize("123456789".encode('ascii')).say;
       # 1371362676478658660830737973868471486175721482632


 

DESCRIPTION

    Using C<Sum::SHA> defines roles for generating types of C<Sum> that
    implement the widely used SHA1 and SHA2 cryptographic hash function
    families.  It is also possible to calculate legacy SHA0 checksums,
    which are obselete and not cryptographically secure.

    SHA sums can be computationally intense.  They also require a small
    but significant memory profile while not finalized, so care must be
    taken when huge numbers of concurrent instances are used.

    NOTE: This implementation is unaudited and is for experimental
    use only.  When audits will be performed will depend on the maturation
    of individual Perl6 implementations, and should be considered
    on an implementation-by-implementation basis.

 

ROLES

(head2) role Sum::SHA1 [ :$insecure_sha0_old = False ] does Sum::MDPad
    The C<Sum::SHA1> parametric role is used to create a type of C<Sum>
    that calculates a SHA1 message digest.  A SHA0 may be calculated
    instead if C<:insecure_sha0_old> is specified.

    Classes using these roles behave as described in C<Sum::MDPad>,
    which means they have rather restrictive rules as to the type
    and number of provided addends when used with C<Sum::Marshal::Raw>.
    The block size used is 64 bytes.

    Mixing a C<Sum::Marshal::Block> role is recommended except for
    implementations that wish to optimize performance.

 
(head2) role Sum::SHA2 [ :$columns = 256 ] does Sum::MDPad
    The C<Sum::SHA2> parametric role is used to create a type of C<Sum>
    that calculates a SHA2 message digest.

    The C<$columns> parameter selects the SHA2 hash variant, and may
    be 224, 256, 384, or 512, yielding SHA-224, SHA-256, SHA-384, or
    SHA-512 respectively.

    Classes using these roles behave as described in C<Sum::MDPad>,
    which means they have rather restrictive rules as to the type
    and number of provided addends when used with C<Sum::Marshal::Raw>.
    The block size used is 64 bytes, or 128 when C<$columns> is 384 or 512.

    Mixing a C<Sum::Marshal::Block> role is recommended except for
    implementations that wish to optimize performance.

 

AUTHOR

    Written by Brian S. Julin

 

COPYRIGHT

    Copyright (c) 2012 Brian S. Julin. All rights reserved.  This program is
    free software; you can redistribute it and/or modify it under the terms
    of the Perl Artistic License 2.0.

 

REFERENCES

SEE ALSO

    C<Sum::(pm3)>

 

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: