silk.crypto.ripemd160.

Compute RIPEMD-160 digests for formats that name them, such as Bitcoin addresses.

When to use#

Use Ripemd160 only where a format requires RIPEMD-160. Use SHA-256 for new protocols.

Details#

The streaming state does not allocate. Call make, update, and finish, or use hash. The digest is 20 bytes.

Examples#

Hash a message in parts#

silk
import silk.crypto.ripemd160 { Ripemd160 }

pub fn main() -> i32 {
  let mut state = Ripemd160.make()
  state.update(b"a")
  state.update(b"bc")
  let digest = state.finish()
  // RIPEMD-160("abc") is 8eb208f7...0bfc.
  if digest[0] != 0x8e || digest[19] != 0xfc {
    return 1
  }
  return 0
}

See also#

The RIPEMD-160 page defines the algorithm and its test vectors.

Import as Ripemd160 with import silk.crypto.ripemd160 { Ripemd160 }.

Public declarations: 1.

Ripemd160#

silk
pub struct Ripemd160

A streaming RIPEMD-160 state that returns a 20-byte digest. It does not allocate.

Implementation Ripemd160#

silk
impl Ripemd160

Associated function make#

silk
pub fn make() -> Self

Returns a state for an empty message.

Method update#

silk
pub fn update(self: &mut Self, bytes: &[u8]) -> ()

Adds bytes to the message. The length in bits wraps modulo 2^64, as RIPEMD-160 requires.

Method finish#

silk
pub fn finish(self: Self) -> [u8; 20]

Consumes the state and returns its 20-byte digest.

Associated function hash#

silk
pub fn hash(bytes: &[u8]) -> [u8; 20]

Returns the 20-byte RIPEMD-160 digest of bytes. It does not allocate.

Implementation Digest for Ripemd160#

silk
impl Digest for Ripemd160

Operation make#

silk
make: Ripemd160.make

Returns a RIPEMD-160 state for an empty message.

Operation update#

silk
update: Ripemd160.update

Adds bytes to the end of the message.

Operation blockLength#

silk
fn blockLength(self: &Self) -> usize

Returns 64, the RIPEMD-160 block length in bytes.

Operation digestLength#

silk
fn digestLength(self: &Self) -> usize

Returns 20, the RIPEMD-160 digest length in bytes.

Operation objectIdentifier#

silk
fn objectIdentifier(self: &Self) -> &[u8]

Returns the content bytes of the RIPEMD-160 object identifier, 1.3.36.3.2.1.

Operation copy#

silk
fn copy(self: &Self) -> Self

Returns an independent copy of the state.

Operation finishInto#

silk
fn finishInto(self: Self, output: &mut [u8]) -> ()

Writes the 20-byte RIPEMD-160 digest to the start of output and consumes the state.

Category: Cryptography.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.

View the source of this page