How to use sha256_update if buf is larger than 64 bytes?
#1
Question 
I'm trying to change the logic of one of the modules, adding sha256 instead of other hashing. The problem is that the data for the hash exceeds the buffer limit of 64 bytes.

I think there should be approximately such logic:

Code:
sha256_ctx_t ctx;
sha256_init(&ctx);

u32 st[21]

st[0] = k[0]
st[1] = k[1]
st[2] = k[2]
st[3] = k[3]
st[4] = ct[0]
st[5] = ct[1]
...
st[15] = ct[10]

sha256_update(&ctx, st, 64); // up to this point there will still be a correct result,
                            // because the 'st' buf contains 64 bytes;

st[16] = ct[11]
st[17] = ct[12]
st[18] = ct[13]
st[19] = ct[15]
st[20] = ct[16]

sha256_update(&ctx, st, 64); // I'm not sure what size I need here, tried different options;

sha256_final(&ctx);

for (int i = 0; i < 8; i++) {
  printf("\n%x\n", ctx.h[i])
}

I expect the correct result sha256(k, ct), but the result is wrong.
Reply


Messages In This Thread
How to use sha256_update if buf is larger than 64 bytes? - by otto3405 - 07-16-2024, 04:32 PM