<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Hi, </div><div><br></div><div>I've been investigating a feasibility of saving of <font class="Apple-style-span" face="'Courier New'" style="font-size: 13px; "><i>hash_state() -- </i></font>used as a part of erlang:md5_init/md5_update/md5_final and/or their functional equivalents in crypto library; so it could be used later to implicitly reinitialize hash calculations.</div><div>Well, (duh!) of course it is feasible; however, my concern was that the structure of this opaque value may change between different versions of Erlang run-time, and I was interested to see how these functions would behave when <i>fake</i> values for <font class="Apple-style-span" face="'Courier New'" style="font-size: 13px; "><i>hash_state() </i></font> are given.</div><div><br></div><div>The results are interesting.</div></div><div><br></div><div>A call to, say, <font class="Apple-style-span" face="'Courier New'" style="font-size: 13px; ">erlang:md5_final( <<0:<b>88</b>/unsigned_integer-unit:8>> )</font> (*), or </div><div> <font class="Apple-style-span" face="'Courier New'" style="font-size: 13px; ">erlang:md5_final( <<1212312312:<b>88</b>/unsigned_integer-unit:8>> )</font>, or, indeed</div><div><font class="Apple-style-span" face="'Courier New'" style="font-size: 13px; ">crypto:hash_final( {md5, <<0:<b>92</b>/unsigned-integer-unit:8>>} )</font></div><div><br></div><div>will all produce:</div><div><br></div><div style="font-size: 13px; "><font class="Apple-style-span" face="'Courier New'"><<176,230,65,201,152,204,62,174,111,162,248,114,109,152,205,221>></font></div><div><br></div><div>Presumably this may be due to some default value that has been used for all invalid values for <i><font class="Apple-style-span" face="'Courier New'" style="font-size: 13px; ">hash_sate()</font>.</i></div><div><br></div><div>However, a call using a <i>fake</i> (yet "non-zero") value in <font class="Apple-style-span" face="'Courier New'" style="font-size: 13px; ">crypto:hash_final( {md5, <<<b>1</b>:92/unsigned-integer-unit:8>>} )</font> results in run-time crashing and reporting segmentation fault (and this cannot be a good thing, right?).</div><div><br></div><div>As it appears that some internal tests are performed in order to verify the <i style="font-size: 13px; "><font class="Apple-style-span" face="'Courier New'">hash_state()</font></i> value, would it possible to extend these test to cover other values without imposing unnecessary performance penalty?</div><div><br></div><div>Or, alternatively, is there any way that this test could be performed externally (e.g. when in doubt and before calling a function that may crash the run-time)… in other words, is it possible to publish descriptions (e.g. structure) of various hash_state() values?</div><div><br></div><div>Kind regards</div><div><br></div><div>V/</div><div><br></div><div>(*) <b>88</b> corresponds to a size (in octets) of the erlang:md5_xxx hash_state() value, and conversely, <b>92</b> is a number of octets in md5 hash_state() equivalent used by crypto library.</div><div><br></div></body></html>