relic-toolkit / relic

Code
Other
452 stars 179 forks source link

Error on sha256 #299

Closed TheYangCode closed 2 months ago

TheYangCode commented 3 months ago

Hello, I used the following code:

void printHex(const uint8_t *str) {
    while (*str) {
        printf("%02X", (unsigned char)*str);
        str++;
    }
    printf("\n");
}

uint8_t m[RLC_MD_LEN_SH256] = "helloworld";
uint8_t m_hash[RLC_MD_LEN_SH256];
size_t m_size = sizeof(m) / sizeof(uint8_t);
md_map_sh256(m_hash, m, m_size);
printHex(m_hash);

Hash result:07116C344512DC38D960BBFAF305B0D1020484C77DD3EFE6E06C38066A92D495C0099A54FE7F But the true sha256 hash result is :936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb944412bb6f8f8f07af

I want to know why?Thank you.

dfaranha commented 3 months ago

Value m_size should be the length of m, not its size.

TheYangCode commented 2 months ago
    bn_t output
    uint8_t output_hash[RLC_MD_LEN_SH256];
    md_map_sh256(output_hash, input, input_len);
    bn_read_bin(output, output_hash, RLC_MD_LEN_SH256);
    bn_mod_basic(output, output, q);

Hello, I have modified my code, but I am encountering this error here. ERROR in dv_zero() at /home/yang/relic-main/src/dv/relic_dv_util.c,57: insufficient precision.

dfaranha commented 2 months ago

You should initialize output with bn_new() and finalize it too. Have you initialized q as well with some group order?

TheYangCode commented 2 months ago

Thank you for your answer. My question has been resolved

TheYangCode commented 2 months ago

Another question, does the current Relic library support Merkle tree generation calculation?

dfaranha commented 2 months ago

Nope, not implemented!