Arc4random, where are you?

While running cmake, arc4random is checked. Now, it is actually not found but I think it is cmake failing:

Run Build Command(s):/bin/ninja cmTC_d6bd3 && [1/2] Building C object CMakeFiles/cmTC_d6bd3.dir/CheckFunctionExists.c.o
[2/2] Linking C executable cmTC_d6bd3
FAILED: cmTC_d6bd3 
: && /bin/clang -DCHECK_FUNCTION_EXISTS=arc4random  CMakeFiles/cmTC_d6bd3.dir/CheckFunctionExists.c.o -o cmTC_d6bd3  -lbsd && :
/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/11.2.0/../../../../x86_64-unknown-haiku/bin/ld: CMakeFiles/cmTC_d6bd3.dir/CheckFunctionExists.c.o: in function `main':
CheckFunctionExists.c:(.text+0x17): undefined reference to `arc4random'
collect2: error: ld returned 1 exit status
clang-12: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Since the linker fails (not the compiler), I think I’m only missing the proper library.
I already provided -lbsd but the linker needs some other libs.

Doing:

/boot/system> grep -r arc4random *
grep: add-ons/kernel/drivers/bin/realtekwifi: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/ralinkwifi: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/marvell88w8335: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/marvell88w8363: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/iprowifi4965: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/iprowifi3945: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/iprowifi2200: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/iprowifi2100: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/idualwifi7260: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/iaxwifi200: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/broadcom43xx: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/atheroswifi: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/aironetwifi: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/syskonnect: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/intel22x: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/ipro1000: il file binario corrisponde
grep: add-ons/kernel/drivers/bin/attansic_l2: il file binario corrisponde
grep: bin/sshd: il file binario corrisponde
grep: bin/ssh-keyscan: il file binario corrisponde
grep: bin/ssh-keygen: il file binario corrisponde
grep: bin/ssh-agent: il file binario corrisponde
grep: bin/ssh-add: il file binario corrisponde
grep: bin/ssh: il file binario corrisponde
grep: bin/sftp: il file binario corrisponde
grep: bin/scp: il file binario corrisponde
grep: bin/ctest: il file binario corrisponde
grep: bin/cpack: il file binario corrisponde
grep: bin/cmake: il file binario corrisponde
grep: bin/ccmake: il file binario corrisponde
grep: develop/lib/libclangStaticAnalyzerCheckers.a: il file binario corrisponde
develop/headers/private/libs/compat/freebsd_wlan/net80211/ieee80211_haiku.cpp:          uint32_t v = arc4random();
develop/headers/private/libs/compat/freebsd_network/compat/sys/libkern.h:uint32_t arc4random(void);
develop/headers/private/libs/compat/freebsd_network/compat/sys/libkern.h:void arc4random_buf(void *ptr, size_t len);
documentation/packages/expat/changelog:                    option USE_libbsd=ON to use arc4random_buf of libbsd
documentation/packages/expat/changelog:             #81  Pre-10.7/Lion macOS: Support entropy from arc4random
documentation/packages/expat/changelog:                    * arc4random_buf on BSD, systems with libbsd
documentation/packages/bash/bashref.html:support <samp>/dev/urandom</samp> or <code>arc4random</code>, so each returned number
documentation/packages/bash/bash.html:support <TT>/dev/urandom</TT> or <I>arc4random</I>, so each returned number
documentation/packages/bash/NEWS:   /dev/urandom or arc4random if available. There is a fallback generator if
documentation/packages/bash/CHANGES:   /dev/urandom or arc4random if available. There is a fallback generator if
documentation/man/man1/bash.1:support \f(CW/dev/urandom\fP or \fIarc4random\fP, so each returned number
grep: documentation/info/bash.info: il file binario corrisponde
grep: lib/libclang-cpp.so.12: il file binario corrisponde
grep: lib/openssh/ssh-sk-helper: il file binario corrisponde
grep: lib/openssh/ssh-pkcs11-helper: il file binario corrisponde
grep: lib/openssh/ssh-keysign: il file binario corrisponde
grep: lib/openssh/sftp-server: il file binario corrisponde
grep: var/swap: il file binario corrisponde

I see many binaries on my system are calling this arc4random, but where is it?
I’m on haiku 64 bit into a virtualbox VM.

https://cgit.haiku-os.org/haiku/tree/src/libs/compat/freebsd_network/libkern.cpp#n31, that at least is for the network drivers.

Edit: Not sure where the ssh bins are getting it from (or if they came from ssh’s sources).

Not sure it is of much help to your case, but… at least now you know where the drivers get it from.

Thank you :smiley:
So, I think it is reasonable to say haiku does not provide arc4random, just for anyone to know.

Yes, it is currently not available. There are patches on Gerrit to add it, but it needs a rework of the entropy sources in the kernel to actually generate crypto-safe randomness. We prefer to not provide it rather than provide an unsafe implementation.

1 Like