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:
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%xn", ctx.h[i])
}
I expect the correct result sha256(k, ct), but the result is wrong.
New contributor
First Second is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.