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#
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#
pub struct Ripemd160A streaming RIPEMD-160 state that returns a 20-byte digest. It does not allocate.
Implementation Ripemd160#
impl Ripemd160Associated function make#
pub fn make() -> SelfReturns a state for an empty message.
Method update#
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#
pub fn finish(self: Self) -> [u8; 20]Consumes the state and returns its 20-byte digest.
Associated function hash#
pub fn hash(bytes: &[u8]) -> [u8; 20]Returns the 20-byte RIPEMD-160 digest of bytes. It does not allocate.
Implementation Digest for Ripemd160#
impl Digest for Ripemd160Operation make#
make: Ripemd160.makeReturns a RIPEMD-160 state for an empty message.
Operation update#
update: Ripemd160.updateAdds bytes to the end of the message.
Operation blockLength#
fn blockLength(self: &Self) -> usizeReturns 64, the RIPEMD-160 block length in bytes.
Operation digestLength#
fn digestLength(self: &Self) -> usizeReturns 20, the RIPEMD-160 digest length in bytes.
Operation objectIdentifier#
fn objectIdentifier(self: &Self) -> &[u8]Returns the content bytes of the RIPEMD-160 object identifier, 1.3.36.3.2.1.
Operation copy#
fn copy(self: &Self) -> SelfReturns an independent copy of the state.
Operation finishInto#
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.