bitcoin core improvement – Questions on secp256k1_pubkey_load/save() implementation

0
64


I am a beginner who has simply began studying Bitcoin Core code. I’ve a number of questions on seemingly trivial code. Proper now, I’ve two questions.

  1. When branching to an if assertion, why is the buffer s used as a substitute of copying instantly from the pubkey to the parameter ge (and vice versa) within the secp256k1_pubkey_load/save perform?

Would not the code beneath work simply as properly?

// secp256k1.c
static int secp256k1_pubkey_load(const secp256k1_context* ctx, secp256k1_ge* ge, const secp256k1_pubkey* pubkey) {
    if (sizeof(secp256k1_ge_storage) == 64) {
        /* When the secp256k1_ge_storage kind is strictly 64 byte, use its
         * illustration inside secp256k1_pubkey, as conversion could be very quick.
         * Observe that secp256k1_pubkey_save should use the identical illustration. */
#if (0)
        secp256k1_ge_storage s;
        memcpy(&s, &pubkey->information[0], sizeof(s));
        secp256k1_ge_from_storage(ge, &s);
#else
        secp256k1_ge_from_storage(ge, (secp256k1_ge_storage *)&pubkey->information[0]);
#endif /* (0) */
    } else {
        /* In any other case, fall again to 32-byte massive endian for X and Y. */
        secp256k1_fe x, y;
        secp256k1_fe_set_b32(&x, pubkey->information);
        secp256k1_fe_set_b32(&y, pubkey->information + 32);
        secp256k1_ge_set_xy(ge, &x, &y);
    }
    ARG_CHECK(!secp256k1_fe_is_zero(&ge->x));
    return 1;
}
  1. Is it potential to department to else?

Wanting on the construction beneath, it appears inconceivable.

// group.h
typedef struct {
    secp256k1_fe_storage x;
    secp256k1_fe_storage y;
} secp256k1_ge_storage;

// field_5x52.h
typedef struct {
    uint64_t n[4];
} secp256k1_fe_storage;

// field_10x26.h
typedef struct {
    uint32_t n[8];
} secp256k1_fe_storage;

LEAVE A REPLY

Please enter your comment!
Please enter your name here