I came across a SHA-256 implementation that seems not to conform to the standard and because I can't change the implementation I would like to know if it's safe for use or can be a potential weakness.
For the last 32 byte block instead of performing this: (As copied from wikipedia)
Add the compressed chunk to the current hash value:
h0 := h0 + a
h1 := h1 + b
h2 := h2 + c
h3 := h3 + d
h4 := h4 + e
h5 := h5 + f
h6 := h6 + g
h7 := h7 + h
It overwrites the current hash value:
h0 := a
h1 := b
h2 := c
h3 := d
h4 := e
h5 := f
h6 := g
h7 := h
Aside from this difference, the implementation in question is equivalent to the pseudo code in wikipedia. It does not produce equivalent output to a correct implementation of SHA-256.
16: 0xca,0xc1,0xd7,0x2d,0x8c,0x58,0x59,0x29,0x95,0xf2,0x83,0x1e,0xe8,0xb5,0x91,0xca,0x49,0xf7,0xd1,0x85,0xd3,0x19,0xad,0xd5,0xd5,0x82,0xa0,0xa1,0x4d,0x4,0x4c,0x5b
0: 0x4,0xd3,0xce,0xbb,0x5b,0x8d,0xc9,0x65,0xea,0xcf,0x31,0x18,0xc0,0x81,0xca,0xf2,0x28,0x16,0x74,0x14,0x51,0x27,0x36,0x60,0x13,0xcc,0x44,0x25,0x35,0x2a,0x4b,0x4
– Gu1234 Jul 02 '18 at 08:45