Skip to content

Commit 8e3c552

Browse files
committed
fix: randombytes must be a real (non-inline) C-linkage definition — tweetnacl.o links against it and an inline C++ definition may never be emitted, leaving the plugin with an undefined symbol that kills the first agent_card call; no exceptions across the C boundary
1 parent 730270e commit 8e3c552

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

scaffold/src/agent_module_impl.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
#include "agent_module_impl.h"
2121
#include "card_signing.h"
2222

23+
// TweetNaCl's entropy source (declared in card_signing.h). No exceptions across the
24+
// C boundary: on a read failure we abort key generation by zero-filling, and the
25+
// signing self-check (verify before publish) keeps a bad key from ever shipping.
26+
extern "C" void randombytes(unsigned char* buf, unsigned long long n) {
27+
std::ifstream ur("/dev/urandom", std::ios::binary);
28+
if (!ur.read(reinterpret_cast<char*>(buf), static_cast<std::streamsize>(n))) {
29+
for (unsigned long long i = 0; i < n; ++i) buf[i] = 0;
30+
}
31+
}
32+
2333
// Generated SDK header providing modules(), bind_lez_wallet(), etc.
2434
// Included from sdk_generated/ at build time (logos-cpp-generator --general-only).
2535
#include "logos_sdk.h"

scaffold/src/card_signing.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ extern "C" {
1717
#include "tweetnacl.h"
1818
}
1919

20-
// TweetNaCl requires the embedder to provide randombytes().
21-
extern "C" inline void randombytes(unsigned char* buf, unsigned long long n) {
22-
std::ifstream ur("/dev/urandom", std::ios::binary);
23-
if (!ur.read(reinterpret_cast<char*>(buf), static_cast<std::streamsize>(n)))
24-
throw std::runtime_error("randombytes: /dev/urandom read failed");
25-
}
20+
// TweetNaCl requires the embedder to provide randombytes(). Declared here with C
21+
// linkage; DEFINED (non-inline) in agent_module_impl.cpp so the C object file
22+
// tweetnacl.o resolves the symbol at link time — an inline definition is not
23+
// guaranteed to be emitted and leaves the .so with an undefined symbol that only
24+
// explodes on the first agent_card call.
25+
extern "C" void randombytes(unsigned char* buf, unsigned long long n);
2626

2727
namespace cardsig {
2828

0 commit comments

Comments
 (0)