```{index} single: Digest::SHA1 ``` # Digest::SHA1 ```{pperl-module-badges} Digest::SHA1 ``` Compute SHA-1 message digests through the interface of Digest::SHA1, the CPAN module older code uses where newer code uses Digest::SHA. The **functional interface** (`sha1`, `sha1_hex`, `sha1_base64`) hashes its arguments in one call. The **object interface** (`Digest::SHA1->new`, `add`, `addfile`, `digest`) takes the data in pieces. Every digest comes as raw bytes (20), lowercase hex (40) or unpadded Base64 (27). `sha1_transform` is the bare SHA-1 compression of one block, for the FIPS 186 random-number construction. The digests are computed by the engine of the built-in Digest::SHA, which uses the processor's SHA instructions where it has them, so the two modules always agree. This is a native implementation of Digest::SHA1 2.13's `SHA1.xs`; its `Digest/SHA1.pm` is used unchanged. ## Synopsis ```perl use Digest::SHA1 qw(sha1_hex sha1_base64); print sha1_hex('abc'), "\n"; # a9993e364706816aba3e25717850c26c9cd0d89d print sha1_base64('abc'), "\n"; # qZk+NkcGgWq6PiVxeFDCbJzQ2J0 my $ctx = Digest::SHA1->new; $ctx->add('a', 'b'); $ctx->add('c'); print $ctx->hexdigest, "\n"; # the same as sha1_hex('abc') ``` ## Differences from upstream Two, each where perl 5.44 with SHA1.xs fails (t/81-xs-native/Digest-SHA1/150-or-better.t): - `sha1_transform` given more than 64 bytes uses the first 64. perl5 copies the whole string into a 64-byte buffer and aborts with "buffer overflow detected". - A method called on the class name instead of an object (`Digest::SHA1->add($data)`) dies "Not a reference to a Digest::SHA1 object". perl5 crashes. ## Functions ### Functional digests #### [`sha1`](SHA1/sha1) Compute the SHA-1 digest of the concatenated arguments in one call. Also available as `Digest::SHA1::sha1_base64`, `Digest::SHA1::sha1_hex`. #### [`sha1_transform`](SHA1/sha1_transform) The SHA-1 compression function over one 64-byte block, from the standard initial state: the 20-byte result, with no padding and no length. ### OO lifecycle #### [`new`](SHA1/new) Create a Digest::SHA1 object, or reset an existing one. #### `clone` Copy a Digest::SHA1 object, the data added so far included, into a new object of the same class. **Synopsis** ```perl my $so_far = $ctx->clone->hexdigest; # $ctx keeps going ``` ### OO input #### [`add`](SHA1/add) Append data to the message being hashed. #### [`addfile`](SHA1/addfile) Append everything that can be read from a filehandle to the message. ### OO output #### [`b64digest`](SHA1/b64digest) Finish the message and return its digest, then reset the object to the empty message. Also available as `Digest::SHA1::digest`, `Digest::SHA1::hexdigest`. ```{toctree} :hidden: :maxdepth: 1 SHA1/new SHA1/add SHA1/addfile SHA1/b64digest SHA1/sha1 SHA1/sha1_transform ```