I'm getting a bus violation after my NIF code is run. The code is pretty straightforward: I'm extending crypto:aes_ctr_encrypt/3 to allow for real streaming encryption. Unfortunately, something is unhappy because after I return from the BIF, I get the bus violation.  I figure I'm either missing something stupid-obvious or there are some side-effects I'm not aware of in some of the enif_* functions.<div>

<br></div><div>I've included my function (aes_ctr_encrypt_with_state as well as the original aes_ctr_encrypt.  State is an arity-4 tuple containing the key (an iolist or binary), the IV (a binary of length 16), ECount (a binary of length 16 initialized to all zeros), and Num (an integer set to 0). There is another function that (correctly) initializes that (it is Erlang code and working fine). (Code also available at <a href="http://pastebin.com/fPs7SgiR">http://pastebin.com/fPs7SgiR</a>)<br clear="all">

<br></div><div>Any ideas or thoughts would be much appreciated.</div><div><meta charset="utf-8"><span class="Apple-style-span" style="color: rgb(24, 24, 24); font-family: monospace; font-size: 12px; line-height: 19px; "><ol>

<li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

<span class="kw4" style="color: rgb(153, 51, 51); ">static</span> ERL_NIF_TERM aes_ctr_encrypt_with_state<span class="br0" style="color: rgb(0, 153, 0); ">(</span>ErlNifEnv<span class="sy0" style="color: rgb(51, 153, 51); ">*</span> env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw4" style="color: rgb(153, 51, 51); ">int</span> argc<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw4" style="color: rgb(153, 51, 51); ">const</span> ERL_NIF_TERM argv<span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

<span class="br0" style="color: rgb(0, 153, 0); ">{</span><span class="coMULTI" style="color: rgb(128, 128, 128); font-style: italic; ">/* ({Key, IVec, ECount, Num}, Data) */</span>    </div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    ErlNifBinary key_bin<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ivec_bin<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> text_bin<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ecount_bin<span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    AES_KEY aes_key<span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw4" style="color: rgb(153, 51, 51); ">unsigned</span> <span class="kw4" style="color: rgb(153, 51, 51); ">int</span> num <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="nu0" style="color: rgb(0, 0, 221); ">0</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    ERL_NIF_TERM ret<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> num2_term<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> cipher_term<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ivec2_term<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ecount2_term<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> new_state_term<span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw4" style="color: rgb(153, 51, 51); ">int</span> state_arity<span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw4" style="color: rgb(153, 51, 51); ">const</span> ERL_NIF_TERM <span class="sy0" style="color: rgb(51, 153, 51); ">*</span>state_term<span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div></li>

<li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw4" style="color: rgb(153, 51, 51); ">unsigned</span> <span class="kw4" style="color: rgb(153, 51, 51); ">char</span> <span class="sy0" style="color: rgb(51, 153, 51); ">*</span> ivec2_buf<span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw4" style="color: rgb(153, 51, 51); ">unsigned</span> <span class="kw4" style="color: rgb(153, 51, 51); ">char</span> <span class="sy0" style="color: rgb(51, 153, 51); ">*</span> ecount2_buf<span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

 </div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw1" style="color: rgb(177, 177, 0); ">if</span> <span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="sy0" style="color: rgb(51, 153, 51); ">!</span>enif_get_tuple<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> argv<span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="nu0" style="color: rgb(0, 0, 221); ">0</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>state_arity<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>state_term<span class="br0" style="color: rgb(0, 153, 0); ">)</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

        <span class="sy0" style="color: rgb(51, 153, 51); ">||</span> state_arity <span class="sy0" style="color: rgb(51, 153, 51); ">!=</span> <span class="nu0" style="color: rgb(0, 0, 221); ">4</span></div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

        <span class="sy0" style="color: rgb(51, 153, 51); ">||</span> <span class="sy0" style="color: rgb(51, 153, 51); ">!</span>enif_inspect_iolist_as_binary<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> state_term<span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="nu0" style="color: rgb(0, 0, 221); ">0</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>key_bin<span class="br0" style="color: rgb(0, 153, 0); ">)</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

        <span class="sy0" style="color: rgb(51, 153, 51); ">||</span> AES_set_encrypt_key<span class="br0" style="color: rgb(0, 153, 0); ">(</span>key_bin.<span class="me1" style="color: rgb(32, 32, 32); ">data</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> key_bin.<span class="me1" style="color: rgb(32, 32, 32); ">size</span><span class="sy0" style="color: rgb(51, 153, 51); ">*</span><span class="nu0" style="color: rgb(0, 0, 221); ">8</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>aes_key<span class="br0" style="color: rgb(0, 153, 0); ">)</span> <span class="sy0" style="color: rgb(51, 153, 51); ">!=</span> <span class="nu0" style="color: rgb(0, 0, 221); ">0</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

        <span class="sy0" style="color: rgb(51, 153, 51); ">||</span> <span class="sy0" style="color: rgb(51, 153, 51); ">!</span>enif_inspect_binary<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> state_term<span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="nu0" style="color: rgb(0, 0, 221); ">1</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>ivec_bin<span class="br0" style="color: rgb(0, 153, 0); ">)</span> <span class="sy0" style="color: rgb(51, 153, 51); ">||</span> ivec_bin.<span class="me1" style="color: rgb(32, 32, 32); ">size</span> <span class="sy0" style="color: rgb(51, 153, 51); ">!=</span> <span class="nu0" style="color: rgb(0, 0, 221); ">16</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

        <span class="sy0" style="color: rgb(51, 153, 51); ">||</span> <span class="sy0" style="color: rgb(51, 153, 51); ">!</span>enif_inspect_binary<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> state_term<span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="nu0" style="color: rgb(0, 0, 221); ">2</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>ecount_bin<span class="br0" style="color: rgb(0, 153, 0); ">)</span> <span class="sy0" style="color: rgb(51, 153, 51); ">||</span> ecount_bin.<span class="me1" style="color: rgb(32, 32, 32); ">size</span> <span class="sy0" style="color: rgb(51, 153, 51); ">!=</span> AES_BLOCK_SIZE</div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

        <span class="sy0" style="color: rgb(51, 153, 51); ">||</span> <span class="sy0" style="color: rgb(51, 153, 51); ">!</span>enif_get_uint<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> state_term<span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="nu0" style="color: rgb(0, 0, 221); ">3</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>num<span class="br0" style="color: rgb(0, 153, 0); ">)</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

        <span class="sy0" style="color: rgb(51, 153, 51); ">||</span> <span class="sy0" style="color: rgb(51, 153, 51); ">!</span>enif_inspect_iolist_as_binary<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> argv<span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="nu0" style="color: rgb(0, 0, 221); ">1</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>text_bin<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span> <span class="br0" style="color: rgb(0, 153, 0); ">{</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

        <span class="kw1" style="color: rgb(177, 177, 0); ">return</span> enif_make_badarg<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="br0" style="color: rgb(0, 153, 0); ">}</span></div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

 </div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    ivec2_buf <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> enif_make_new_binary<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ivec_bin.<span class="me1" style="color: rgb(32, 32, 32); ">size</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>ivec2_term<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    ecount2_buf <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> enif_make_new_binary<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ecount_bin.<span class="me1" style="color: rgb(32, 32, 32); ">size</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>ecount2_term<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

   </div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw3" style="color: rgb(0, 0, 102); ">memcpy</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span>ivec2_buf<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ivec_bin.<span class="me1" style="color: rgb(32, 32, 32); ">data</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="nu0" style="color: rgb(0, 0, 221); ">16</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw3" style="color: rgb(0, 0, 102); ">memcpy</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span>ecount2_buf<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ecount_bin.<span class="me1" style="color: rgb(32, 32, 32); ">data</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ecount_bin.<span class="me1" style="color: rgb(32, 32, 32); ">size</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

 </div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    AES_ctr128_encrypt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="kw4" style="color: rgb(153, 51, 51); ">unsigned</span> <span class="kw4" style="color: rgb(153, 51, 51); ">char</span> <span class="sy0" style="color: rgb(51, 153, 51); ">*</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span> text_bin.<span class="me1" style="color: rgb(32, 32, 32); ">data</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

                       enif_make_new_binary<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> text_bin.<span class="me1" style="color: rgb(32, 32, 32); ">size</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>cipher_term<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

                       text_bin.<span class="me1" style="color: rgb(32, 32, 32); ">size</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>aes_key<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ivec2_buf<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ecount2_buf<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>num<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

 </div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    num2_term <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> enif_make_uint<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> num<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    new_state_term <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> enif_make_tuple4<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> key_bin<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ivec2_term<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ecount2_term<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> num2_term<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    ret <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> enif_make_tuple2<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> new_state_term<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> cipher_term<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw1" style="color: rgb(177, 177, 0); ">return</span> ret<span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

<span class="br0" style="color: rgb(0, 153, 0); ">}</span></div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

 </div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

 </div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

<span class="kw4" style="color: rgb(153, 51, 51); ">static</span> ERL_NIF_TERM aes_ctr_encrypt<span class="br0" style="color: rgb(0, 153, 0); ">(</span>ErlNifEnv<span class="sy0" style="color: rgb(51, 153, 51); ">*</span> env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw4" style="color: rgb(153, 51, 51); ">int</span> argc<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw4" style="color: rgb(153, 51, 51); ">const</span> ERL_NIF_TERM argv<span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

<span class="br0" style="color: rgb(0, 153, 0); ">{</span><span class="coMULTI" style="color: rgb(128, 128, 128); font-style: italic; ">/* (Key, IVec, Data) */</span>    </div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    ErlNifBinary key<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ivec<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> text<span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div></li>

<li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    AES_KEY aes_key<span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw4" style="color: rgb(153, 51, 51); ">unsigned</span> <span class="kw4" style="color: rgb(153, 51, 51); ">char</span> ivec_clone<span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="nu0" style="color: rgb(0, 0, 221); ">16</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span> <span class="coMULTI" style="color: rgb(128, 128, 128); font-style: italic; ">/* writable copy */</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw4" style="color: rgb(153, 51, 51); ">unsigned</span> <span class="kw4" style="color: rgb(153, 51, 51); ">char</span> ecount_buf<span class="br0" style="color: rgb(0, 153, 0); ">[</span>AES_BLOCK_SIZE<span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw4" style="color: rgb(153, 51, 51); ">unsigned</span> <span class="kw4" style="color: rgb(153, 51, 51); ">int</span> num <span class="sy0" style="color: rgb(51, 153, 51); ">=</span> <span class="nu0" style="color: rgb(0, 0, 221); ">0</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    ERL_NIF_TERM ret<span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

 </div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw1" style="color: rgb(177, 177, 0); ">if</span> <span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="sy0" style="color: rgb(51, 153, 51); ">!</span>enif_inspect_iolist_as_binary<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> argv<span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="nu0" style="color: rgb(0, 0, 221); ">0</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>key<span class="br0" style="color: rgb(0, 153, 0); ">)</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

        <span class="sy0" style="color: rgb(51, 153, 51); ">||</span> AES_set_encrypt_key<span class="br0" style="color: rgb(0, 153, 0); ">(</span>key.<span class="me1" style="color: rgb(32, 32, 32); ">data</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> key.<span class="me1" style="color: rgb(32, 32, 32); ">size</span><span class="sy0" style="color: rgb(51, 153, 51); ">*</span><span class="nu0" style="color: rgb(0, 0, 221); ">8</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>aes_key<span class="br0" style="color: rgb(0, 153, 0); ">)</span> <span class="sy0" style="color: rgb(51, 153, 51); ">!=</span> <span class="nu0" style="color: rgb(0, 0, 221); ">0</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

        <span class="sy0" style="color: rgb(51, 153, 51); ">||</span> <span class="sy0" style="color: rgb(51, 153, 51); ">!</span>enif_inspect_binary<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> argv<span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="nu0" style="color: rgb(0, 0, 221); ">1</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>ivec<span class="br0" style="color: rgb(0, 153, 0); ">)</span> <span class="sy0" style="color: rgb(51, 153, 51); ">||</span> ivec.<span class="me1" style="color: rgb(32, 32, 32); ">size</span> <span class="sy0" style="color: rgb(51, 153, 51); ">!=</span> <span class="nu0" style="color: rgb(0, 0, 221); ">16</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

        <span class="sy0" style="color: rgb(51, 153, 51); ">||</span> <span class="sy0" style="color: rgb(51, 153, 51); ">!</span>enif_inspect_iolist_as_binary<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> argv<span class="br0" style="color: rgb(0, 153, 0); ">[</span><span class="nu0" style="color: rgb(0, 0, 221); ">2</span><span class="br0" style="color: rgb(0, 153, 0); ">]</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>text<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span> <span class="br0" style="color: rgb(0, 153, 0); ">{</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

        <span class="kw1" style="color: rgb(177, 177, 0); ">return</span> enif_make_badarg<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="br0" style="color: rgb(0, 153, 0); ">}</span></div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw3" style="color: rgb(0, 0, 102); ">memcpy</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span>ivec_clone<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ivec.<span class="me1" style="color: rgb(32, 32, 32); ">data</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="nu0" style="color: rgb(0, 0, 221); ">16</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span>    </div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw3" style="color: rgb(0, 0, 102); ">memset</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span>ecount_buf<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="nu0" style="color: rgb(0, 0, 221); ">0</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="kw4" style="color: rgb(153, 51, 51); ">sizeof</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span>ecount_buf<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    AES_ctr128_encrypt<span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="br0" style="color: rgb(0, 153, 0); ">(</span><span class="kw4" style="color: rgb(153, 51, 51); ">unsigned</span> <span class="kw4" style="color: rgb(153, 51, 51); ">char</span> <span class="sy0" style="color: rgb(51, 153, 51); ">*</span><span class="br0" style="color: rgb(0, 153, 0); ">)</span> text.<span class="me1" style="color: rgb(32, 32, 32); ">data</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

                       enif_make_new_binary<span class="br0" style="color: rgb(0, 153, 0); ">(</span>env<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> text.<span class="me1" style="color: rgb(32, 32, 32); ">size</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>ret<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span></div>

</li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

                       text.<span class="me1" style="color: rgb(32, 32, 32); ">size</span><span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>aes_key<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ivec_clone<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> ecount_buf<span class="sy0" style="color: rgb(51, 153, 51); ">,</span> <span class="sy0" style="color: rgb(51, 153, 51); ">&</span>num<span class="br0" style="color: rgb(0, 153, 0); ">)</span><span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div>

</li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

 </div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="coMULTI" style="color: rgb(128, 128, 128); font-style: italic; ">/* To do an incremental {en|de}cryption, the state to to keep between calls</span></div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

<span class="coMULTI" style="color: rgb(128, 128, 128); font-style: italic; ">        must include ivec_clone, ecount_buf and num. */</span></div></li><li class="li1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial; ">

<div class="de1" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

    <span class="kw1" style="color: rgb(177, 177, 0); ">return</span> ret<span class="sy0" style="color: rgb(51, 153, 51); ">;</span></div></li><li class="li2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(248, 248, 248); background-position: initial initial; background-repeat: initial initial; ">

<div class="de2" style="font: normal normal normal 1em/1.2em monospace; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; background-image: none; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; vertical-align: top; line-height: 19px; background-position: initial initial; background-repeat: initial initial; ">

<span class="br0" style="color: rgb(0, 153, 0); ">}</span></div></li></ol></span>-- <br><b><span style="font-size:large">Travis Jensen</span></b><div><b></b><span style="font-size:large"><b><br></b></span>Read the Software Maven @ <a href="http://softwaremaven.innerbrane.com/" target="_blank">http://softwaremaven.innerbrane.com/</a><br>

Read my LinkedIn profile @ <a href="http://www.linkedin.com/in/travisjensen" target="_blank">http://www.linkedin.com/in/travisjensen</a><br>Read my Twitter mumblings @ <a href="http://twitter.com/SoftwareMaven" target="_blank">http://twitter.com/SoftwareMaven</a><br>

Send me email @ <a href="mailto:travis.jensen@gmail.com" target="_blank">travis.jensen@gmail.com</a><div><br></div><div><i>*What kind of guy calls himself the Software Maven???*</i></div></div><br>
</div>