Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenSSL 3.0.0-alpha generated C code has different function name declaration than older OpenSSL versions #30

Open
alichry opened this issue Jul 12, 2020 · 0 comments

Comments

@alichry
Copy link

alichry commented Jul 12, 2020

I was installing this, I've compiled OpenSSL and configured it with the advised arguments in the install instructions.

While trying to compile revsh, running make produced:

...
if [ ! -e keys/dh_params.c ]; then \
    ../openssl/apps/openssl dhparam -noout -C 2048 >keys/dh_params.c ; \
	echo "DH *(*get_dh)() = &get_dh2048;" >>keys/dh_params.c ; \
  fi
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
.+........+......+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
..+..+.+..+.........+..+...
...
keys/dh_params.c:75:20: error: 'get_dh2048' undeclared here (not in a function)
 DH *(*get_dh)() = &get_dh2048;

The generated C code in keys/dh_params.c is:

static DH *get_dh256(void)
{
    static unsigned char dhp_256[] = {
        0x96, 0x4E, 0x1B, 0xBE, 0x81, 0x01, 0x67, 0x67, 0x21, 0xFF,
        0x19, 0x63, 0x5C, 0x13, 0x02, 0x3E, 0xC0, 0xE7, 0xCA, 0x1A,
        0xB7, 0x59, 0x61, 0x08, 0x05, 0xE8, 0x0B, 0xF3, 0xB6, 0xD3,
        0x73, 0x3B, 0x26, 0x56, 0xF8, 0xB1, 0xDA, 0x42, 0xEB, 0x78,
        0xE9, 0xE5, 0x85, 0x70, 0x9E, 0x10, 0xA2, 0x80, 0x0D, 0x53,
        0xFF, 0x06, 0x61, 0xE1, 0x2F, 0xB7, 0x80, 0x42, 0x76, 0xE3,
        0x99, 0xAB, 0x32, 0x93, 0x65, 0xF0, 0xA2, 0xC6, 0x9E, 0x0F,
        0x52, 0xD1, 0x27, 0x6B, 0xDF, 0xCC, 0x99, 0x71, 0x65, 0x1E,
        0xBC, 0x89, 0xBC, 0x5D, 0xF4, 0x80, 0x9E, 0xC5, 0x19, 0xB5,
        0xE1, 0x0F, 0xE8, 0xAF, 0xE2, 0x75, 0x15, 0xED, 0xCE, 0x99,
        0xA6, 0xC5, 0xC5, 0xD1, 0xEA, 0xEE, 0x4E, 0xBB, 0x18, 0xAF,
        0xC5, 0x12, 0xE3, 0x93, 0x5D, 0xDC, 0xF7, 0xE2, 0xAB, 0x56,
        0x4A, 0x58, 0x60, 0x7D, 0x31, 0xA9, 0xCD, 0xA5, 0xF1, 0x40,
        0xD0, 0x93, 0xD4, 0x4A, 0x8B, 0x74, 0x43, 0xA3, 0x83, 0x3A,
        0xFA, 0xD7, 0xEE, 0x86, 0x59, 0xA3, 0x6F, 0xDA, 0x5E, 0x4C,
        0x39, 0xDB, 0x0E, 0x75, 0xCC, 0x40, 0xD5, 0xF5, 0x0B, 0x94,
        0xCC, 0xB2, 0xC7, 0x07, 0xEB, 0x1C, 0xEF, 0xFF, 0xD2, 0x9C,
        0x95, 0x5F, 0x48, 0x1D, 0x0B, 0x0E, 0xE5, 0xE1, 0x5F, 0x3E,
        0x01, 0xE8, 0xD6, 0xB6, 0x58, 0x86, 0x38, 0xBA, 0xC9, 0x50,
        0xB2, 0x5C, 0x83, 0xC1, 0xB2, 0x78, 0xAB, 0x07, 0xDD, 0x17,
        0xAC, 0x4D, 0xA6, 0x37, 0x0C, 0x3A, 0xCB, 0xE9, 0xE2, 0x0C,
        0x06, 0xB0, 0xE2, 0x6E, 0x19, 0x90, 0x00, 0xEA, 0xDA, 0x77,
        0xD2, 0xA4, 0xCE, 0x93, 0x7F, 0x13, 0x33, 0x7E, 0xF5, 0x3E,
        0x31, 0xF9, 0x77, 0xAA, 0x39, 0x71, 0xFF, 0xAD, 0x02, 0x41,
        0x62, 0x57, 0xF5, 0xC1, 0x26, 0xAE, 0xA2, 0xC0, 0x29, 0x48,
        0x28, 0xE2, 0x86, 0x4C, 0xB4, 0x0D
    };
    static unsigned char dhg_256[] = {
        0x0E, 0x5B, 0xAB, 0x57, 0x41, 0x6E, 0x82, 0x3C, 0x10, 0x92,
        0x8B, 0x18, 0x0D, 0xD5, 0x66, 0xF7, 0x33, 0x5E, 0x35, 0xAF,
        0xFF, 0x7A, 0x56, 0x87, 0x8A, 0xDA, 0x5D, 0xD4, 0xF4, 0x2E,
        0xB1, 0x77, 0x2F, 0x79, 0xB3, 0x77, 0x95, 0xC5, 0x8E, 0x9C,
        0xB0, 0x2A, 0xCE, 0x3A, 0x0F, 0xF5, 0x55, 0x0F, 0x06, 0x12,
        0x9B, 0xEC, 0x90, 0x42, 0x9B, 0x4B, 0xCA, 0xF5, 0x72, 0x70,
        0x8A, 0xE2, 0xEC, 0x5C, 0x13, 0x1D, 0xB3, 0x03, 0xC2, 0xCE,
        0xF4, 0x08, 0xF2, 0x63, 0x65, 0xF3, 0x53, 0xD6, 0x02, 0xA7,
        0x19, 0x11, 0x2D, 0x6C, 0x5A, 0x82, 0x06, 0xEF, 0xC7, 0x3E,
        0x92, 0x1E, 0xE1, 0x64, 0x71, 0xB4, 0x88, 0x91, 0x5E, 0xD3,
        0xCF, 0x16, 0xB3, 0x3E, 0xB2, 0x8D, 0xB0, 0x61, 0x7F, 0x23,
        0xA3, 0x39, 0x69, 0x3E, 0x9D, 0x44, 0x92, 0x57, 0xED, 0x90,
        0xF1, 0x0C, 0xB2, 0x28, 0xD0, 0x61, 0x4B, 0x2A, 0x70, 0xE7,
        0x82, 0xCC, 0x75, 0x92, 0x1E, 0x65, 0x3A, 0x56, 0x85, 0x0D,
        0x3F, 0x40, 0x59, 0x0A, 0x45, 0xEF, 0x99, 0x03, 0x88, 0x8C,
        0xD5, 0x82, 0xC3, 0xE2, 0x6F, 0x1F, 0x2B, 0xBD, 0x0F, 0x50,
        0xAD, 0xD6, 0x46, 0x26, 0xBD, 0x02, 0x58, 0x41, 0xA9, 0x00,
        0xE5, 0x23, 0x0E, 0x0A, 0xD6, 0x10, 0xEB, 0x9B, 0x81, 0x0B,
        0xB2, 0x53, 0x73, 0x35, 0xF9, 0xBE, 0x5C, 0x86, 0x33, 0xE4,
        0xAA, 0x10, 0x34, 0xA5, 0x0A, 0x63, 0x06, 0x0E, 0xF3, 0x4B,
        0x4C, 0xDB, 0xE4, 0x28, 0xED, 0x1B, 0x4D, 0x43, 0x62, 0x46,
        0xF5, 0xD3, 0x55, 0x67, 0x7D, 0xEC, 0x6A, 0x2F, 0x61, 0x5A,
        0x0F, 0x8C, 0xAA, 0xFA, 0x20, 0xE2, 0x40, 0xD2, 0x1D, 0x39,
        0xE9, 0x08, 0x99, 0xAF, 0x7E, 0x0A, 0x32, 0xBE, 0xA6, 0xC9,
        0xB0, 0x6E, 0x09, 0x94, 0xFB, 0xD7, 0xF8, 0xE4, 0xAC, 0xEB,
        0xFC, 0x1D, 0xD4, 0xB9, 0x0A, 0xF0
    };
    DH *dh = DH_new();
    BIGNUM *p, *g;

    if (dh == NULL)
        return NULL;
    p = BN_bin2bn(dhp_256, sizeof(dhp_256), NULL);
    g = BN_bin2bn(dhg_256, sizeof(dhg_256), NULL);
    if (p == NULL || g == NULL
            || !DH_set0_pqg(dh, p, NULL, g)) {
        DH_free(dh);
        BN_free(p);
        BN_free(g);
        return NULL;
    }
    return dh;
}
DH *(*get_dh)() = &get_dh2048;

If I generate the C code using the OpenSSL binary installed on my system and not the compiled one, the generated function declaration is

$ openssl dhparam -noout -C 2048
#ifndef HEADER_DH_H
#include <openssl/dh.h>
#endif
DH *get_dh2048()
        {
        static unsigned char dh2048_p[]={
                0x86,0xB5,0x48,0xF3,0x63,0xE2,0x92,0x97,0xC1,0x5B,0xEC,0x3A,
                0x40,0xFF,0x3E,0xA9,0x64,0xBC,0x24,0x11,0x3D,0xC0,0x9A,0x57,
                0xCF,0xF5,0x02,0xFA,0x08,0xF5,0x1A,0x50,0x08,0x77,0x2E,0xD9,
                0x20,0x5B,0xB0,0xA7,0xAA,0x32,0xC1,0x54,0xF1,0xF3,0x29,0xBE,
                0x34,0x54,0xD6,0xC1,0x57,0x2F,0x35,0xED,0x7F,0xE4,0xE0,0x46,
                0x82,0x28,0x0D,0xB2,0xB2,0x30,0x7E,0x43,0xCB,0x98,0xBA,0x09,
                0x75,0x72,0xED,0x71,0xD0,0x2D,0xE6,0xAD,0x45,0x2E,0xE8,0x37,
                0x48,0x81,0x1F,0x94,0x3C,0x1C,0x5B,0x22,0x67,0x6E,0xB2,0x96,
                0xBD,0x26,0x75,0x59,0x4E,0xCF,0x2F,0xA0,0x26,0x70,0x4A,0xF6,
                0x8C,0xAF,0x69,0x88,0x2B,0x05,0x59,0x5E,0x60,0xFD,0x4F,0xB7,
                0xBC,0x63,0x96,0x0F,0xC2,0xE1,0x9B,0xF9,0x71,0x1B,0x0F,0x05,
                0x74,0x5D,0xAB,0xF5,0x37,0x65,0x50,0xF0,0x9F,0xF4,0x3F,0xE6,
                0x21,0xB9,0x28,0xAA,0x68,0xC8,0x11,0xC2,0xB6,0x30,0xD3,0x8D,
                0xB8,0x3E,0x6E,0x9D,0x24,0xE0,0xE8,0xDF,0xEE,0x0E,0x4F,0xDD,
                0xC6,0x55,0x7F,0xC3,0x5D,0x48,0xC1,0x20,0x01,0x79,0xCE,0x12,
                0xEA,0x9C,0xAD,0x32,0xC5,0x62,0x01,0xA2,0x40,0x36,0xB9,0x8E,
                0x9B,0x72,0xF4,0xBB,0xA7,0x38,0xEF,0x44,0xC0,0x46,0xAC,0x91,
                0xE4,0xF2,0x5C,0x1A,0xC6,0xF4,0xE3,0x3C,0x36,0x17,0x6F,0x41,
                0x87,0xB7,0x2A,0xB8,0xF8,0xF9,0x5D,0x9C,0x6F,0x09,0x71,0x66,
                0xB1,0xD1,0xF5,0xA7,0x05,0x4F,0xB3,0x93,0x54,0x81,0x36,0x18,
                0x7D,0x93,0x50,0xFB,0x68,0x55,0xAB,0x48,0xE9,0x7B,0x4C,0xAF,
                0x74,0xB6,0xFA,0x03,
                };
        static unsigned char dh2048_g[]={
                0x02,
                };
        DH *dh;

        if ((dh=DH_new()) == NULL) return(NULL);
        dh->p=BN_bin2bn(dh2048_p,sizeof(dh2048_p),NULL);
        dh->g=BN_bin2bn(dh2048_g,sizeof(dh2048_g),NULL);
        if ((dh->p == NULL) || (dh->g == NULL))
                { DH_free(dh); return(NULL); }
        return(dh);
        }

Compiled OpenSSL version:

$ ../openssl/apps/openssl version  
OpenSSL 3.0.0-alpha5-dev  (Library: OpenSSL 3.0.0-alpha5-dev )

Installed OpenSSL version:

$ openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017

Obviously cloning the latest branch commit of OpenSSL can raise compatibility issues with future releases of OpenSSL. I'll be happy to create a PR to modify the INSTALL instructions, or instead maybe we use can use sed to get the declared function name instead of hardcoding it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant