error compiling crypto/rand/rand_unix.c from missing include

nbriggs created this issue on 2021-09-04 · The issue is replied 4 times

Summary: Building openssl 1.1.1l on OS X 10.11.6 fails compiling crypto/rand/rand_unix.c because CCCryptorStatus is not defined, as used by /usr/include/CommonCrypto/CommonRandom.h. This is easily fixed by including CommonCrypto/CommonCryptoError.h before CommonRandom.h.

In file included from crypto/rand/rand_unix.c:38:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/CommonCrypto/CommonRandom.h:35:9: error: unknown type name 'CCCryptorStatus'
typedef CCCryptorStatus CCRNGStatus;
        ^
crypto/rand/rand_unix.c:385:47: error: use of undeclared identifier 'kCCSuccess'
    if (CCRandomGenerateBytes(buf, buflen) == kCCSuccess)
                                              ^
2 errors generated.

Configuration:


Command line (with current working directory = .):

    /usr/bin/perl ./Configure darwin64-x86_64-cc

Perl information:

    /usr/bin/perl
    5.18.2 for darwin-thread-multi-2level

Enabled features:

    aria
    asm
    async
    autoalginit
    autoerrinit
    autoload-config
    bf
    blake2
    camellia
    capieng
    cast
    chacha
    cmac
    cms
    comp
    ct
    deprecated
    des
    dgram
    dh
    dsa
    dso
    dtls
    dynamic-engine
    ec
    ec2m
    ecdh
    ecdsa
    engine
    err
    filenames
    gost
    hw(-.+)?
    idea
    makedepend
    md4
    mdc2
    multiblock
    nextprotoneg
    pinshared
    ocb
    ocsp
    pic
    poly1305
    posix-io
    psk
    rc2
    rc4
    rdrand
    rfc3779
    rmd160
    scrypt
    seed
    shared
    siphash
    sm2
    sm3
    sm4
    sock
    srp
    srtp
    sse2
    ssl
    static-engine
    stdio
    tests
    threads
    tls
    ts
    ui-console
    whirlpool
    tls1
    tls1-method
    tls1_1
    tls1_1-method
    tls1_2
    tls1_2-method
    tls1_3
    dtls1
    dtls1-method
    dtls1_2
    dtls1_2-method

Disabled features:

    afalgeng                [not-linux] OPENSSL_NO_AFALGENG
    asan                    [default]   OPENSSL_NO_ASAN
    buildtest-c++           [default]   
    crypto-mdebug           [default]   OPENSSL_NO_CRYPTO_MDEBUG
    crypto-mdebug-backtrace [default]   OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE
    devcryptoeng            [default]   OPENSSL_NO_DEVCRYPTOENG
    ec_nistp_64_gcc_128     [default]   OPENSSL_NO_EC_NISTP_64_GCC_128
    egd                     [default]   OPENSSL_NO_EGD
    external-tests          [default]   OPENSSL_NO_EXTERNAL_TESTS
    fuzz-libfuzzer          [default]   OPENSSL_NO_FUZZ_LIBFUZZER
    fuzz-afl                [default]   OPENSSL_NO_FUZZ_AFL
    heartbeats              [default]   OPENSSL_NO_HEARTBEATS
    md2                     [default]   OPENSSL_NO_MD2 (skip crypto/md2)
    msan                    [default]   OPENSSL_NO_MSAN
    rc5                     [default]   OPENSSL_NO_RC5 (skip crypto/rc5)
    sctp                    [default]   OPENSSL_NO_SCTP
    ssl-trace               [default]   OPENSSL_NO_SSL_TRACE
    ubsan                   [default]   OPENSSL_NO_UBSAN
    unit-test               [default]   OPENSSL_NO_UNIT_TEST
    weak-ssl-ciphers        [default]   OPENSSL_NO_WEAK_SSL_CIPHERS
    zlib                    [default]   
    zlib-dynamic            [default]   
    ssl3                    [default]   OPENSSL_NO_SSL3
    ssl3-method             [default]   OPENSSL_NO_SSL3_METHOD

Config target attributes:

    AR => "ar",
    ARFLAGS => "r",
    CC => "cc",
    CFLAGS => "-O3 -Wall",
    HASHBANGPERL => "/usr/bin/env perl",
    RANLIB => "ranlib -c",
    RC => "windres",
    aes_asm_src => "aes_core.c aes_cbc.c vpaes-x86_64.s aesni-x86_64.s aesni-sha1-x86_64.s aesni-sha256-x86_64.s aesni-mb-x86_64.s",
    aes_obj => "aes_core.o aes_cbc.o vpaes-x86_64.o aesni-x86_64.o aesni-sha1-x86_64.o aesni-sha256-x86_64.o aesni-mb-x86_64.o",
    apps_aux_src => "",
    apps_init_src => "",
    apps_obj => "",
    bf_asm_src => "bf_enc.c",
    bf_obj => "bf_enc.o",
    bn_asm_src => "asm/x86_64-gcc.c x86_64-mont.s x86_64-mont5.s x86_64-gf2m.s rsaz_exp.c rsaz-x86_64.s rsaz-avx2.s",
    bn_obj => "asm/x86_64-gcc.o x86_64-mont.o x86_64-mont5.o x86_64-gf2m.o rsaz_exp.o rsaz-x86_64.o rsaz-avx2.o",
    bn_ops => "SIXTY_FOUR_BIT_LONG",
    build_file => "Makefile",
    build_scheme => [ "unified", "unix" ],
    cast_asm_src => "c_enc.c",
    cast_obj => "c_enc.o",
    cflags => "-arch x86_64",
    chacha_asm_src => "chacha-x86_64.s",
    chacha_obj => "chacha-x86_64.o",
    cmll_asm_src => "cmll-x86_64.s cmll_misc.c",
    cmll_obj => "cmll-x86_64.o cmll_misc.o",
    cppflags => "-D_REENTRANT",
    cpuid_asm_src => "x86_64cpuid.s",
    cpuid_obj => "x86_64cpuid.o",
    defines => [  ],
    des_asm_src => "des_enc.c fcrypt_b.c",
    des_obj => "des_enc.o fcrypt_b.o",
    disable => [  ],
    dso_extension => ".dylib",
    dso_scheme => "dlfcn",
    ec_asm_src => "ecp_nistz256.c ecp_nistz256-x86_64.s x25519-x86_64.s",
    ec_obj => "ecp_nistz256.o ecp_nistz256-x86_64.o x25519-x86_64.o",
    enable => [  ],
    exe_extension => "",
    includes => [  ],
    keccak1600_asm_src => "keccak1600-x86_64.s",
    keccak1600_obj => "keccak1600-x86_64.o",
    lflags => "-Wl,-search_paths_first",
    lib_cflags => "",
    lib_cppflags => "-DL_ENDIAN",
    lib_defines => [  ],
    md5_asm_src => "md5-x86_64.s",
    md5_obj => "md5-x86_64.o",
    modes_asm_src => "ghash-x86_64.s aesni-gcm-x86_64.s",
    modes_obj => "ghash-x86_64.o aesni-gcm-x86_64.o",
    module_cflags => "-fPIC",
    module_cxxflags => "",
    module_ldflags => "-bundle",
    padlock_asm_src => "e_padlock-x86_64.s",
    padlock_obj => "e_padlock-x86_64.o",
    perlasm_scheme => "macosx",
    poly1305_asm_src => "poly1305-x86_64.s",
    poly1305_obj => "poly1305-x86_64.o",
    rc4_asm_src => "rc4-x86_64.s rc4-md5-x86_64.s",
    rc4_obj => "rc4-x86_64.o rc4-md5-x86_64.o",
    rc5_asm_src => "rc5_enc.c",
    rc5_obj => "rc5_enc.o",
    rmd160_asm_src => "",
    rmd160_obj => "",
    sha1_asm_src => "sha1-x86_64.s sha256-x86_64.s sha512-x86_64.s sha1-mb-x86_64.s sha256-mb-x86_64.s",
    sha1_obj => "sha1-x86_64.o sha256-x86_64.o sha512-x86_64.o sha1-mb-x86_64.o sha256-mb-x86_64.o",
    shared_cflag => "-fPIC",
    shared_defines => [  ],
    shared_extension => ".\$(SHLIB_VERSION_NUMBER).dylib",
    shared_extension_simple => ".dylib",
    shared_ldflag => "-dynamiclib -current_version \$(SHLIB_VERSION_NUMBER) -compatibility_version \$(SHLIB_VERSION_NUMBER)",
    shared_rcflag => "",
    shared_sonameflag => "-install_name \$(INSTALLTOP)/\$(LIBDIR)/",
    shared_target => "darwin-shared",
    sys_id => "MACOSX",
    thread_defines => [  ],
    thread_scheme => "pthreads",
    unistd => "<unistd.h>",
    uplink_aux_src => "",
    uplink_obj => "",
    wp_asm_src => "wp-x86_64.s",
    wp_obj => "wp-x86_64.o",

Recorded environment:

    AR = 
    ARFLAGS = 
    AS = 
    ASFLAGS = 
    BUILDFILE = 
    CC = 
    CFLAGS = 
    CPP = 
    CPPDEFINES = 
    CPPFLAGS = 
    CPPINCLUDES = 
    CROSS_COMPILE = 
    CXX = 
    CXXFLAGS = 
    HASHBANGPERL = 
    LD = 
    LDFLAGS = 
    LDLIBS = 
    MT = 
    MTFLAGS = 
    OPENSSL_LOCAL_CONFIG_DIR = 
    PERL = 
    RANLIB = 
    RC = 
    RCFLAGS = 
    RM = 
    WINDRES = 
    __CNF_CFLAGS = 
    __CNF_CPPDEFINES = 
    __CNF_CPPFLAGS = 
    __CNF_CPPINCLUDES = 
    __CNF_CXXFLAGS = 
    __CNF_LDFLAGS = 
    __CNF_LDLIBS = 

Makevars:

    AR              = ar
    ARFLAGS         = r
    CC              = cc
    CFLAGS          = -O3 -Wall
    CPPDEFINES      = 
    CPPFLAGS        = 
    CPPINCLUDES     = 
    CXXFLAGS        = 
    HASHBANGPERL    = /usr/bin/env perl
    LDFLAGS         = 
    LDLIBS          = 
    PERL            = /usr/bin/perl
    RANLIB          = ranlib -c
    RC              = windres
    RCFLAGS         = 

NOTE: These variables only represent the configuration view.  The build file
template may have processed these variables further, please have a look at the
build file for more exact data:
    Makefile

build file:

    Makefile

build file templates:

    Configurations/common0.tmpl
    Configurations/unix-Makefile.tmpl
    Configurations/common.tmpl
nbriggs wrote this answer on 2021-09-04

Fix could be:

% git diff
diff --git a/crypto/rand/rand_unix.c b/crypto/rand/rand_unix.c
index 43f1069..a89c55a 100644
--- a/crypto/rand/rand_unix.c
+++ b/crypto/rand/rand_unix.c
@@ -35,6 +35,7 @@
 # include <sys/param.h>
 #endif
 #if defined(__APPLE__)
+# include <CommonCrypto/CommonCryptoError.h>
 # include <CommonCrypto/CommonRandom.h>
 #endif
 
paulidale wrote this answer on 2021-09-05

Pull request welcomed.

The OpenSSL fellows do not develop on MacOS.

nbriggs wrote this answer on 2021-09-05

I'll generate a pull request. This is really an error in CommonCrypto/CommonRandom.h, though, which should have included CommonCryptoError.h since it depends on it. It appears to have been fixed in more recent macOS SDK versions -- but an extra include in the openssl code won't be a problem and will help anyone who tries to compile with the older SDKs.

nbriggs wrote this answer on 2021-09-05

This already got fixed by merge of PR #16409 for issues #16407, #16408 -- I guess I'll see the fix in 1.1.1m.

More Details About Repo
Owner Name openssl
Repo Name openssl
Full Name openssl/openssl
Language C
Created Date 2013-01-15
Updated Date 2021-11-26
Star Count 17002
Watcher Count 934
Fork Count 7425
Issue Count 1554

YOU MAY BE INTERESTED

Issue Title State Comments Created Date Updated Date Closed Date
Replace tests with snapshot tests open 0 2021-10-26 2021-11-17 -
Does Rultor support env variable in script? open 2 2020-05-02 2021-10-28 -
Considering not to get snapshot for transaction commands in gRPC threads closed 6 2021-10-12 2021-10-18 2021-10-20
Encoding of KeyAgreeRecipientInfo structures is omitting ukm field closed 2 2021-05-12 2021-10-19 2021-05-19
[WIP] Working changes closed 2 2019-03-09 2021-10-24 2019-04-21
Missing field in OrganizationConnection closed 1 2021-06-23 2021-11-03 2021-08-18
Not working in a library project open 5 2021-02-15 2021-11-19 -
The Long type is not available closed 11 2021-09-20 2021-11-18 2021-09-30
Add GPU video encoder, rankers and segmenters closed 7 2021-09-08 2021-11-15 2021-09-15
Can we check for existing tables in atomic database when adding a new replica to cluster and creating a schema there? open 3 2021-11-23 2021-11-18 -