RMD160(3) NetBSD Library Functions Manual RMD160(3) NNAAMMEE RRMMDD116600IInniitt, RRMMDD116600UUppddaattee, RRMMDD116600FFiinnaall, RRMMDD116600TTrraannssffoorrmm, RRMMDD116600EEnndd, RRMMDD116600FFiillee, RRMMDD116600DDaattaa - calculate the ``RIPEMD-160'' message digest SSYYNNOOPPSSIISS ##iinncclluuddee <> ##iinncclluuddee <> _v_o_i_d RRMMDD116600IInniitt(_R_M_D_1_6_0___C_T_X _*_c_o_n_t_e_x_t); _v_o_i_d RRMMDD116600UUppddaattee(_R_M_D_1_6_0___C_T_X _*_c_o_n_t_e_x_t, _c_o_n_s_t _u___c_h_a_r _*_d_a_t_a, _u___i_n_t _n_b_y_t_e_s); _v_o_i_d RRMMDD116600FFiinnaall(_u___c_h_a_r _d_i_g_e_s_t_[_2_0_], _R_M_D_1_6_0___C_T_X _*_c_o_n_t_e_x_t); _v_o_i_d RRMMDD116600TTrraannssffoorrmm(_u___i_n_t_3_2___t _s_t_a_t_e_[_5_], _c_o_n_s_t _u___i_n_t_3_2___t _b_l_o_c_k_[_1_6_]); _c_h_a_r _* RRMMDD116600EEnndd(_R_M_D_1_6_0___C_T_X _*_c_o_n_t_e_x_t, _c_h_a_r _*_b_u_f); _c_h_a_r _* RRMMDD116600FFiillee(_c_h_a_r _*_f_i_l_e_n_a_m_e, _c_h_a_r _*_b_u_f); _c_h_a_r _* RRMMDD116600DDaattaa(_u___c_h_a_r _*_d_a_t_a, _s_i_z_e___t _l_e_n, _c_h_a_r _*_b_u_f); DDEESSCCRRIIPPTTIIOONN The RMD160 functions implement the 160-bit RIPE message digest hash algo- rithm (RMD-160). RMD-160 is used to generate a condensed representation of a message called a message digest. The algorithm takes a message less than 2^64 bits as input and produces a 160-bit digest suitable for use as a digital signature. The RMD160 functions are considered to be more secure than the md4(3) and md5(3) functions and at least as secure as the sha1(3) function. All share a similar interface. The RRMMDD116600IInniitt() function initializes a RMD160_CTX _c_o_n_t_e_x_t for use with RRMMDD116600UUppddaattee(), and RRMMDD116600FFiinnaall(). The RRMMDD116600UUppddaattee() function adds _d_a_t_a of length _n_b_y_t_e_s to the RMD160_CTX specified by _c_o_n_t_e_x_t. RRMMDD116600FFiinnaall() is called when all data has been added via RRMMDD116600UUppddaattee() and stores a message digest in the _d_i_g_e_s_t parameter. When a null pointer is passed to RRMMDD116600FFiinnaall() as first argument only the final padding will be applied and the current context can still be used with RRMMDD116600UUppddaattee(). The RRMMDD116600TTrraannssffoorrmm() function is used by RRMMDD116600UUppddaattee() to hash 512-bit blocks and forms the core of the algorithm. Most programs should use the interface provided by RRMMDD116600IInniitt(), RRMMDD116600UUppddaattee() and RRMMDD116600FFiinnaall() instead of calling RRMMDD116600TTrraannssffoorrmm() directly. The RRMMDD116600EEnndd() function is a front end for RRMMDD116600FFiinnaall() which converts the digest into an ASCII representation of the 160 bit digest in hexadec- imal. The RRMMDD116600FFiillee() function calculates the digest for a file and returns the result via RRMMDD116600EEnndd(). If RRMMDD116600FFiillee() is unable to open the file a NULL pointer is returned. The RRMMDD116600DDaattaa() function calculates the digest of an arbitrary string and returns the result via RRMMDD116600EEnndd(). For each of the RRMMDD116600EEnndd(), RRMMDD116600FFiillee(), and RRMMDD116600DDaattaa() functions the _b_u_f 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 allo- cated via malloc(3) and should be freed using free(3) when it is no longer needed. EEXXAAMMPPLLEESS The follow code fragment will calculate the digest for the string "abc" which is ``0x8eb208f7e05d987a9b044a8e98c6b087f15a0bfc''. RMD160_CTX rmd; u_char results[20]; char *buf; int n; buf = "abc"; n = strlen(buf); RMD160Init(&rmd); RMD160Update(&rmd, (u_char *)buf, n); RMD160Final(results, &rmd); /* Print the digest as one long hex value */ printf("0x"); for (n = 0; n < 20; n++) printf("%02x", results[n]); putchar('\n'); Alternately, the helper functions could be used in the following way: RMD160_CTX rmd; u_char output[41]; char *buf = "abc"; printf("0x%s\n", RMD160Data(buf, strlen(buf), output)); SSEEEE AALLSSOO rmd160(1), md4(3), md5(3), sha1(3) H. Dobbertin, A. Bosselaers, B. Preneel, _R_I_P_E_M_D_-_1_6_0_, _a _s_t_r_e_n_g_t_h_e_n_e_d _v_e_r_s_i_o_n _o_f _R_I_P_E_M_D. _I_n_f_o_r_m_a_t_i_o_n _t_e_c_h_n_o_l_o_g_y _- _S_e_c_u_r_i_t_y _t_e_c_h_n_i_q_u_e_s _- _H_a_s_h_-_f_u_n_c_t_i_o_n_s _- _P_a_r_t _3_: _D_e_d_i_c_a_t_e_d _h_a_s_h_-_f_u_n_c_t_i_o_n_s, ISO/IEC 10118-3. H. Dobbertin, A. Bosselaers, B. Preneel, "The RIPEMD-160 cryptographic hash function", _D_r_. _D_o_b_b_'_s _J_o_u_r_n_a_l, Vol. 22, No. 1, pp. 24-28, January 1997. HHIISSTTOORRYY The RMD-160 functions appeared in OpenBSD 2.1. AAUUTTHHOORRSS This implementation of RMD-160 was written by Antoon Bosselaers. The RRMMDD116600EEnndd(), RRMMDD116600FFiillee(), and RRMMDD116600DDaattaa() helper functions are derived from code written by Poul-Henning Kamp. BBUUGGSS 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. NetBSD 2.1 July 16, 1997 NetBSD 2.1