The AVR simulator result does not match the result in C code file

Comments

12 comments

  • Avatar
    Michael Johnson

    unsigned int is a 16-bit number on an AVR, it's a 32-bit number on a PC. Try changing to use unsigned long or #include <stdint.h> and use uint32

    0
    Comment actions Permalink
  • Avatar
    Sarah

    I changed it to unsigned long hash[], but I am still getting different result,

    for example in sample.s the result is :


    MSG = 7dc50fb6c26ff172bf8baf9c2a1e71c47926defb180968570fb191a22f2f5773bfbd43bfbd
    4779d3145128591dfffffffe77992f6d77992b653bfb4c77992631f89130fa003bfb5c771c0cf5f8
    9130fa03bfb74f76e73f89130fa0f76e7e8e4763633bfba03bfba0

     

     

    while in the simulator, the result is:

    MSG = 487effffa917ffff92bffffffd47454effff950e4be2ffffaadc000000000000000000000000

     

     

     

     

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    You need to change all uses of unsigned int to unsigned long.

    0
    Comment actions Permalink
  • Avatar
    Sarah

    In the code two variables are in unsigned int type (concat2 and hash), changing them still gave me different results.

    In AVR:

    MSG = ffff94c3ffffde37ffffc402ffffff180000000000000000000000000000

    In sample.c: the same as in the above comment.

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    And the code in

     

    #include "sha256/sha256.c"
    #include "sha256/sha2_small_common.c"

    0
    Comment actions Permalink
  • Avatar
    Sarah

    Do I have to change these types also uint8_t, uint32_t and uint64_t?

    When I tried o change for example (lb) value in sha2_small_commmon.c file from uint8_t to uint32_t, no result is displayed.

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    No the types uint8_t etc should be fine - just the uses of unsigned int. If the sha code using uint32_t you should do the same.

    0
    Comment actions Permalink
  • Avatar
    Sarah

    I changed the unsigned int data type to long data type for the two values (hash and concat2). In the sha256.c and sha2_small_common.c there is no unsigned int data type there; and I am still getting two different result.

    In AVR:

    MSG = 50fbffffff17ffffbaf9ffffe71c6defffff9685191afffff577000000000000000000000000

    In PC C file:

    MSG = 7dc50fb6c26ff172bf8baf9c2a1e71c47926defb180968570fb191a22f2f
    577000000000000000000000000

     

    0
    Comment actions Permalink
  • Avatar
    Sarah

    I can see that there are a match between the two results as shown here:

    In AVR:

    MSG = 50fbffffff17ffffbaf9ffffe71c6defffff9685191afffff577000000000000000000000000

    In PC C file:

    MSG = 7dc50fb6c26ff172bf8baf9c2a1e71c47926defb180968570fb191a22f2f
    577000000000000000000000000

    But why there are different values between the matched numbers?

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    Not sure can you attach sha2_small_common.h

    0
    Comment actions Permalink
  • Avatar
    Sarah

    Here is the file attached

    0
    Comment actions Permalink
  • Avatar
    Michael Johnson

    The attached works for me

    MSG = 7dc50fb6c26ff172bf8baf9c2a1e71c47926defb180968570fb191a22f2f577000000000000000000000000

    0
    Comment actions Permalink

Please sign in to leave a comment.