<div dir="ltr">I don't know if this is the problem you are running into, but shouldn't result be initialised before entering the loop?<div class="gmail_extra"><br><div class="gmail_quote">On 7 September 2015 at 19:24, Deniz Erbilgin <span dir="ltr"><<a href="mailto:deniz.erbilgin@gmail.com" target="_blank">deniz.erbilgin@gmail.com</a>></span> wrote:<br><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></blockquote><div><br></div><div>replace the above line with</div><div> uint8_t result = 0;</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<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><br></div></div>