silk.crypto.md5_sha1.
Compute the 36-byte MD5-SHA1 digest that TLS 1.0 and 1.1 use: MD5 followed by SHA-1.
When to use#
Use Md5Sha1 only where a legacy format names it, such as Node's md5-sha1 hash or the
TLS 1.0 and 1.1 RSA signatures. Use SHA-256 elsewhere.
Details#
The digest is the 16-byte MD5 digest of the message followed by its 20-byte SHA-1 digest. The
streaming state does not allocate. Call make, update, and finish, or use hash.
Gotchas#
MD5 and SHA-1 both permit deliberate collisions, so the pair does not protect data against
tampering. The hash has no object identifier, so Digest.objectIdentifier returns an empty
slice.
Examples#
Hash a message#
import silk.crypto.md5_sha1 { Md5Sha1 }
pub fn main() -> i32 {
let digest = Md5Sha1.hash(b"abc")
// MD5("abc") starts with 90 and SHA-1("abc") with a9.
if digest[0] != 0x90 || digest[16] != 0xa9 || digest[35] != 0x9d {
return 1
}
return 0
}Import as Md5Sha1 with import silk.crypto.md5_sha1 { Md5Sha1 }.
Public declarations: 1.
Md5Sha1#
pub struct Md5Sha1A streaming MD5-SHA1 state that returns a 36-byte digest. It does not allocate.
Implementation Md5Sha1#
impl Md5Sha1Associated 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.
Method finish#
pub fn finish(self: Self) -> [u8; 36]Consumes the state and returns the MD5 digest followed by the SHA-1 digest.
Associated function hash#
pub fn hash(bytes: &[u8]) -> [u8; 36]Returns the 36-byte MD5-SHA1 digest of bytes. It does not allocate.
Implementation Digest for Md5Sha1#
impl Digest for Md5Sha1Operation make#
make: Md5Sha1.makeReturns an MD5-SHA1 state for an empty message.
Operation update#
update: Md5Sha1.updateAdds bytes to the end of the message.
Operation blockLength#
fn blockLength(self: &Self) -> usizeReturns 64, the block length of both MD5 and SHA-1 in bytes.
Operation digestLength#
fn digestLength(self: &Self) -> usizeReturns 36, the MD5-SHA1 digest length in bytes.
Operation objectIdentifier#
fn objectIdentifier(self: &Self) -> &[u8]Returns an empty slice, because MD5-SHA1 has no object identifier.
Operation copy#
fn copy(self: &Self) -> SelfReturns an independent copy of the state.
Operation finishInto#
fn finishInto(self: Self, output: &mut [u8]) -> ()Writes the 36-byte MD5-SHA1 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.