The RMD160 functions are considered to be more secure than the md4(3), md5(3) and sha1(3) functions. All share a similar interface.
The Fn RMD160Init function initializes a RMD160_CTX context for use with Fn RMD160Update , and Fn RMD160Final . The Fn RMD160Update function adds data of length nbytes to the RMD160_CTX specified by context Fn RMD160Final is called when all data has been added via Fn RMD160Update and stores a message digest in the digest parameter.
The Fn RMD160Pad function can be used to apply padding to the message digest as in Fn RMD160Final , but the current context can still be used with Fn RMD160Update .
The Fn RMD160Transform function is used by Fn RMD160Update to hash 512-bit blocks and forms the core of the algorithm. Most programs should use the interface provided by Fn RMD160Init , Fn RMD160Update and Fn RMD160Final instead of calling Fn RMD160Transform directly.
The Fn RMD160End function is a front end for Fn RMD160Final which converts the digest into an ASCII representation of the 160 bit digest in hexadecimal.
The Fn RMD160File function calculates the digest for a file and returns the result via Fn RMD160End . If Fn RMD160File is unable to open the file a NULL pointer is returned.
Fn RMD160FileChunk behaves like Fn RMD160File but calculates the digest only for that portion of the file starting at Fa offset and continuing for Fa length bytes or until end of file is reached, whichever comes first. A zero Fa length can be specified to read until end of file. A negative Fa length or Fa offset will be ignored.
The Fn RMD160Data function calculates the digest of an arbitrary string and returns the result via Fn RMD160End .
For each of the Fn RMD160End , Fn RMD160File , and Fn RMD160Data functions the buf parameter should either be a string of at least 41 characters in size or 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.
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));
The Fn RMD160End , Fn RMD160File , Fn RMD160FileChunk , and Fn RMD160Data helper functions are derived from code written by Poul-Henning Kamp.