Module crypto::sha1 [] [src]

An implementation of the SHA-1 cryptographic hash algorithm.

To use this module, first create a Sha1 object using the Sha1 constructor, then feed it an input message using the input or input_str methods, which may be called any number of times; they will buffer the input until there is enough to call the block algorithm.

After the entire input has been fed to the hash read the result using the result or result_str methods. The first will return bytes, and the second will return a String object of the same bytes represented in hexadecimal form.

The Sha1 object may be reused to create multiple hashes by calling the reset() method. These traits are implemented by all hash digest algorithms that implement the Digest trait. An example of use is:

use self::crypto::digest::Digest;
use self::crypto::sha1::Sha1;

// create a Sha1 object
let mut hasher = Sha1::new();

// write input message
hasher.input_str("hello world");

// read hash digest
let hex = hasher.result_str();

assert_eq!(hex, "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed");

Mathematics

The mathematics of the SHA-1 algorithm are quite interesting. In its definition, The SHA-1 algorithm uses:

  • 1 binary operation on bit-arrays:
    • "exclusive or" (XOR)
  • 2 binary operations on integers:
    • "addition" (ADD)
    • "rotate left" (ROL)
  • 3 ternary operations on bit-arrays:
    • "choose" (CH)
    • "parity" (PAR)
    • "majority" (MAJ)

Some of these functions are commonly found in all hash digest algorithms, but some, like "parity" is only found in SHA-1.

Structs

Sha1

Structure representing the state of a Sha1 computation

Functions

sha1_digest_block

Process a block with the SHA-1 algorithm. (See more...)

sha1_digest_block_u32

Process a block with the SHA-1 algorithm.

sha1_digest_round_x4

Emulates llvm.x86.sha1rnds4 intrinsic. Performs 4 rounds of the message block digest.

sha1_first

Not an intrinsic, but gets the first element of a vector.

sha1_first_add

Not an intrinsic, but adds a word to the first element of a vector.

sha1_first_half

Emulates llvm.x86.sha1nexte intrinsic.

sha1_schedule_x4

Performs 4 rounds of the message schedule update.