supranational / blst

Multilingual BLS12-381 signature library
Apache License 2.0
458 stars 175 forks source link

Expose SHA-256 functions #146

Closed jtraglia closed 1 year ago

jtraglia commented 1 year ago

This PR exposes the blst sha256 functions in the auxiliary header. This is for c-kzg-4844 which currently patches blst to expose these functions. It would beneficial to us if these functions were exported. This PR only makes these functions available from C and not any of the other bindings. This is all we want/need at the moment.

henridf commented 1 year ago

A couple other repos that would benefit from this change are nim-blscurve (current workaround to expose sha256 at https://github.com/status-im/nim-blscurve/blob/master/blscurve/blst/blst_sha256.c) and the in-progress nim-kzg-4844 repo.

dot-asm commented 1 year ago

I don't see a compelling need for exposing the CTX structure. I mean why not instead of exposing init/update/final expose single-shot subroutine? One that simply takes data and emits its hash... With private CTX allocated on stack...

dot-asm commented 1 year ago

I mean

void blst_sha256(unsigned char md[32], const void *msg, size_t len)
{
    SHA256_CTX ctx;

    sha256_init(&ctx);
    sha256_update(&ctx, msg, len);
    sha256_final(md, &ctx);
}

for src/exports.c.

jtraglia commented 1 year ago

That's a good idea too. I like that approach. Will make the change.

dot-asm commented 1 year ago

Any hard objections, @henridf?

henridf commented 1 year ago

nope, I think this should work fine on my end too

dot-asm commented 1 year ago

Thanks!