MP-SPDZ icon indicating copy to clipboard operation
MP-SPDZ copied to clipboard

Calculation of sha256

Open seven072 opened this issue 3 months ago • 1 comments

I computes the sha256 value of '55504b4c4c4d' using the following code:

from circuit import sha256 
a = '55504b4c4c4d'
result = sbitvec.from_hex(a, reverse=False)
print_ln("%s", sha256(result).reveal())

The output is: 42270906609316389159836726310560887711266603166060461417510073264624989089288 Then I convert '55504b4c4c4d' to decimal for calculation,

from circuit import sha256
a = 93803349036109
a = sbitvec(sint(a), 64, 64)
a = a[::-1]
print_ln("%s", sha256(sbitvec.from_vec(a)).reveal())

the output is -31805551173941073440827515752749944970407769073724132554122411909160006518806 I don't know what caused the second result to be incorrect. Looking forward to your reply. Thank you!

seven072 avatar Oct 08 '25 16:10 seven072

If you study the from_hex function, you will find that it doesn't just reverse the bit order as your second code example does: https://github.com/mkskeller/spdz-bmr/blob/4e150af9815e495afbb38e9e4ac64c2c4da03886/Compiler/GC/types.py#L902

mkskeller avatar Oct 08 '25 23:10 mkskeller