Search code examples
c++openssladditionecdsamodular-arithmetic

Combining ECDSA keys


How can I combine two ECDSA private/public keypairs into one? I know it's done with modular addition in openssl, I just don't understand how that works. Can anyone explain that to me?


Solution

  • You can do that by adding two private keys

    privkey = privateA + privateB (mod order)
    

    or, in OpenSSL code:

    BN_mod_add_quick(privkey, privateA, privateB, order);
    

    Here order is the smallest number where order = s - j, such that sP = jP for a point P on the elliptic curve. The public key of your new private key is pubkey = privkey * G, or:

    EC_POINT_mul(group, pubkey, privkey, NULL, NULL, ctx);
    

    The values of order and generator point G are curve parameters and are set when creating and setting group(an EC_GROUP object).