<p dir="ltr">Where is the memory for tag1 and tag2 allocated from? If on the the stack maybe the stack is being corrupted? </p>
<p dir="ltr">As an aside I would also pass on the size of the two buffers and/or use a #define in-place of the 16 to make it a bit for readable.</p>
<p dir="ltr">Cheers,</p>
<p dir="ltr">Jeremy</p>
<div class="gmail_quote">On 7 Sep 2015 19:24, "Deniz Erbilgin" <<a href="mailto:deniz.erbilgin@gmail.com">deniz.erbilgin@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I'm currently putting the AESGCM encryption libraries together for the arduino and have been getting some interesting behaviour from my tag checking function:<br>
<br>
static uint8_t checkTag(const uint8_t *tag1, const uint8_t *tag2)<br>
{<br>
uint8_t result;<br>
<br>
// compare tags. If any byte fails, will set bits in result<br>
for (uint8_t i = 0; i < 16; i++) {<br>
result |= *tag1 ^ *tag2;<br>
//Serial.print(result, HEX); // when this is uncommented, the function works correctly<br>
tag1++;<br>
tag2++;<br>
}<br>
return result;<br>
}<br>
<br>
<br>
The function just loops through an array and sets bits in result whenever there is a difference between bytes.<br>
<br>
I had all the functions visible externally while I was debugging another problem and it was working fine. However, when I made all the functions static again, the decrypt function started returning a failed tag check.<br>
<br>
I included the arduino headers in the library so that I could print from it to serial, and as long as I print 'result' to the console it works fine. I printed both tags from within the function just in case and they're both identical, whether or not the function fails.<br>
<br>
All I can think of is that the compiler is trying to optimise it in some strange way.<br>
<br>
Thanks,<br>
<br>
Deniz<br>
<br>
_______________________________________________<br>
OpenTRV-dev mailing list<br>
<a href="mailto:OpenTRV-dev@lists.opentrv.org.uk" target="_blank">OpenTRV-dev@lists.opentrv.org.uk</a><br>
<a href="http://lists.opentrv.org.uk/listinfo/opentrv-dev" rel="noreferrer" target="_blank">http://lists.opentrv.org.uk/listinfo/opentrv-dev</a><br>
</blockquote></div>