How do I feed OpenSSL random data for use in ECDSA signing?

前端 未结 5 2092
无人共我
无人共我 2021-01-06 02:34

I want to feed OpenSSL specific data for use as random seed during the signing of data with an EC key. I\'m doing this to compare my application with another reference one (

5条回答
  •  攒了一身酷
    2021-01-06 03:08

    The reason you get different results despite the fact that you are clearing the pool and resetting it is that by default OpenSSL's RAND implementation will hash the pid into the output block (precisely to ensure that even applications that use the same seed do not get the same PRNG output, since 99.9% of the time that happening is a Bad Thing).

    In addition, even if this was not the case, it is unlikely that your reference application uses the same PRNG that OpenSSL uses to turn the seed file into a series of random bytes. (Unless your reference application actually uses OpenSSL as well, of course). What you would have to do is first figure out what kind of PRNG the reference app uses - this might be a standard PRNG design like the ones from X9.31 or FIPS-186, or might be something totally custom. Then reimplement that design for OpenSSL and plug it in via RAND_set_rand_method.

    As to verification: it looks like you need to transpose the lines:

       ecpoint = EC_POINT_new(ecgroup);
       ecgroup = EC_GROUP_new_by_curve_name(OBJ_sn2nid("sect163k1"));
    

    Otherwise ecpoint is set to NULL right from the start, and this causes EC_KEY_generate_key to fail, because the group is set to NULL. Quoting from openssl-0.9.8k's crypto/ec/ec_key.c:

    if (!eckey || !eckey->group)
       {
       ECerr(EC_F_EC_KEY_GENERATE_KEY, ERR_R_PASSED_NULL_PARAMETER);
       return 0;
       }
    

提交回复
热议问题