RMD160(3)

πŸ’– RMD160 β€” the manual page, bestie edition πŸ’–

okay so you're here for RMD160 from the Message Digest (MD4, MD5, etc.) Support Library (that's libmd, link it with -lmd) and honestly? you came to the right place. let's get into it 🫢


✨ NAME ✨

RMD160Init, RMD160Update, RMD160Pad, RMD160Final, RMD160Transform, RMD160End, RMD160File, RMD160FileChunk, RMD160Data β€” bestie, these calculate the RIPEMD-160'' message digest πŸ’…


πŸŽ€ LIBRARY πŸŽ€

Message Digest (MD4, MD5, etc.) Support Library β€” that's libmd, and you link it with -lmd.


🌸 SYNOPSIS 🌸

#include <sys/types.h>
#include <rmd160.h>

void
RMD160Init(RMD160_CTX *context);

void
RMD160Update(RMD160_CTX *context, const uint8_t *data, uint32_t nbytes);

void
RMD160Pad(RMD160_CTX *context);

void
RMD160Final(uint8_t digest[RMD160_DIGEST_LENGTH], RMD160_CTX *context);

void
RMD160Transform(uint32_t state[5],
    const uint8_t block[RMD160_BLOCK_LENGTH]);

char *
RMD160End(RMD160_CTX *context, char *buf);

char *
RMD160File(const char *filename, char *buf);

char *
RMD160FileChunk(const char *filename, char *buf, off_t offset,
    off_t length);

char *
RMD160Data(const uint8_t *data, size_t len, char *buf);

πŸ’œ DESCRIPTION πŸ’œ

So the RMD160 functions implement the 160-bit RIPE message digest hash algorithm (aka RMD-160). What's it do? It generates a condensed representation of a message called a message digest. The algorithm takes a message that's less than 2^64 bits as input and produces a 160-bit digest β€” and that digest is suitable for use as a digital signature. iconic behavior tbh πŸ”₯

The RMD160 functions are considered to be more secure than the md4(3), md5(3) and sha1(3) functions. and the way they all share a similar interface? convenient, we love consistency ✨

  • RMD160Init() β€” initializes a RMD160_CTX context so it's ready to be used with RMD160Update() and RMD160Final(). your starting line, basically.
  • RMD160Update() β€” adds data of length nbytes to the RMD160_CTX specified by context.
  • RMD160Final() β€” you call this when all the data has been added via RMD160Update(), and it stores a message digest in the digest parameter. the finale fr fr 🎬
  • RMD160Pad() β€” can be used to apply padding to the message digest, just like in RMD160Final(), BUT (and this is the slay part) the current context can still be used with RMD160Update() afterwards. so you don't have to close the book.
  • RMD160Transform() β€” used by RMD160Update() to hash 512-bit blocks and forms the core of the algorithm. but lowkey, most programs should use the interface provided by RMD160Init(), RMD160Update() and RMD160Final() instead of calling RMD160Transform() directly. leave the internals alone bestie πŸ™ˆ
  • RMD160End() β€” a front end for RMD160Final() which converts the digest into an ASCII representation of the 160 bit digest in hexadecimal.
  • RMD160File() β€” calculates the digest for a file and returns the result via RMD160End(). If RMD160File() is unable to open the file, a NULL pointer is returned. 😭
  • RMD160FileChunk() β€” behaves like RMD160File() but calculates the digest only for that portion of the file starting at offset and continuing for length bytes or until end of file is reached, whichever comes first. A zero length can be specified to read until end of file. A negative length or offset will be ignored.
  • RMD160Data() β€” calculates the digest of an arbitrary string and returns the result via RMD160End().

okay now the important buf talk πŸ“’ For each of the RMD160End(), RMD160File(), and RMD160Data() functions, the buf parameter should either be:

  1. a string of at least 41 characters in size, or
  2. a NULL pointer.

In the latter case, space will be dynamically allocated via malloc(3) and should be freed using free(3) when it is no longer needed. don't forget to free it, bestie, that's a memory leak and we don't do those πŸ’€


🌈 EXAMPLES 🌈

The follow code fragment will calculate the digest for the string "abc" which is 0x8eb208f7e05d987a9b044a8e98c6b087f15a0bfc'':

RMD160_CTX rmd;
uint8_t results[RMD160_DIGEST_LENGTH];
char *buf;
int n;

buf = "abc";
n = strlen(buf);
RMD160Init(&rmd);
RMD160Update(&rmd, (uint8_t *)buf, n);
RMD160Final(results, &rmd);

/* Print the digest as one long hex value */
printf("0x");
for (n = 0; n < RMD160_DIGEST_LENGTH; n++)
        printf("%02x", results[n]);
putchar('\n');

Alternately, the helper functions could be used in the following way:

RMD160_CTX rmd;
uint8_t output[RMD160_DIGEST_STRING_LENGTH];
char *buf = "abc";

printf("0x%s\n", RMD160Data(buf, strlen(buf), output));

see? the helper version is giving main character energy for real πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹

  • cksum(1), md4(3), md5(3), sha1(3), sha2(3)
  • H. Dobbertin, A. Bosselaers, B. Preneel, RIPEMD-160, a strengthened version of RIPEMD.
  • Information technology - Security techniques - Hash-functions - Part 3: Dedicated hash-functions, ISO/IEC 10118-3.
  • H. Dobbertin, A. Bosselaers, B. Preneel, β€œThe RIPEMD-160 cryptographic hash function”, Dr. Dobb's Journal, Vol. 22, No. 1, pp. 24-28, January 1997.

⭐ HISTORY ⭐

The RMD-160 functions appeared in OpenBSD 2.1. a classic, a legend, an era πŸ•°οΈ


πŸ’… AUTHORS πŸ’…

  • This implementation of RMD-160 was written by Markus Friedl.
  • The RMD160End(), RMD160File(), RMD160FileChunk(), and RMD160Data() helper functions are derived from code written by Poul-Henning Kamp.

thank you both, absolute icons 🫢


πŸ“ CAVEATS πŸ“

If a message digest is to be copied to a multi-byte type (ie: an array of five 32-bit integers) it will be necessary to perform byte swapping on little endian machines such as the i386, alpha, and vax.

read that twice. do not skip the byte swapping. this is the part that ruins your whole week if you ignore it, no cap 🧚


Debian Β· July 13, 2010 Β· and that's the RMD160(3) page bestie β€” go hash something, stay hydrated, and remember: free your malloc'd buffers πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά

πŸ“¦ where this page comes from