I've got a negative number in a BIGNUM:

    BN_hex2bn(&a, "00afd72b...bd3ae65d");
    BN_dec2bn(&n, "-1");
    ...

    BN_mul(r, a, n, ctx);

I then convert it to an ASN1 INTEGER, and then fetch the ASN1 integer:

    ASN1_INTEGER* x = BN_to_ASN1_INTEGER(r, NULL);

    const unsigned char* ptr = x->data;
    long len = x->length;
    int tag = 0, cls = 0;

    ASN1_get_object(&ptr, &len, &tag, &cls, len);

When I print the integer:

    for(long i = 0; i < len; i++)
        cout << std::hex << (((int)ptr[i]) & 0xFF);
    cout << endl;

The integer is *not* a 2's compliment of 'r'. Rather, its a positive
'r' (in fact, its the same positive 'a' I started with).

Does BN_to_ASN1_INTEGER drop the sign of the BIGNUM?
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to