Skip to content

Commit e5e7790

Browse files
committed
Remove workaround for missing symbols in PQClean
Now that the upstream issue has been fixed, we can remove the workaround for the missing ML-DSA symbols. Refs: PQClean/PQClean#576
1 parent d6945e5 commit e5e7790

2 files changed

Lines changed: 1 addition & 91 deletions

File tree

scripts/build-wasm.mjs

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -76,53 +76,7 @@ const commonSourceFiles = await sources('common', (name) => name !== 'randombyte
7676
const kemSourceFiles = (await Promise.all(kemNames.map((kem) => sources(`crypto_kem/${kem}/clean`)))).flat();
7777
const signSourceFiles = (await Promise.all(signNames.map((sign) => sources(`crypto_sign/${sign}/clean`)))).flat();
7878

79-
const wrapperCode = `// Some implementations do not provide certain functions as symbols but only as
80-
// macros with parameters, which we cannot export. Implement symbols here.
81-
82-
${signNames.map((sign) => `#include "../../${depDir}/crypto_sign/${sign}/clean/api.h"`).join('\n')}
83-
84-
${functions(signNames, 'sign', 'signature').map((fn) => `#ifdef ${fn}
85-
static inline int _fn_symbol_${fn}(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk) {
86-
return ${fn}(sig, siglen, m, mlen, sk);
87-
}
88-
#undef ${fn}
89-
int ${fn}(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk) {
90-
return _fn_symbol_${fn}(sig, siglen, m, mlen, sk);
91-
}
92-
#endif`).join('\n')}
93-
${functions(signNames, 'sign', 'sign').map((fn) => `#ifdef ${fn}
94-
static inline int _fn_symbol_${fn}(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk) {
95-
return ${fn}(sig, siglen, m, mlen, sk);
96-
}
97-
#undef ${fn}
98-
int ${fn}(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk) {
99-
return _fn_symbol_${fn}(sig, siglen, m, mlen, sk);
100-
}
101-
#endif`).join('\n')}
102-
${functions(signNames, 'sign', 'verify').map((fn) => `#ifdef ${fn}
103-
static inline int _fn_symbol_${fn}(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *pk) {
104-
return ${fn}(sig, siglen, m, mlen, pk);
105-
}
106-
#undef ${fn}
107-
int ${fn}(const uint8_t *sig, size_t siglen, const uint8_t *m, size_t mlen, const uint8_t *pk) {
108-
return _fn_symbol_${fn}(sig, siglen, m, mlen, pk);
109-
}
110-
#endif
111-
`).join('\n')}
112-
${functions(signNames, 'sign', 'open').map((fn) => `#ifdef ${fn}
113-
static inline int _fn_symbol_${fn}(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk) {
114-
return ${fn}(sig, siglen, m, mlen, sk);
115-
}
116-
#undef ${fn}
117-
int ${fn}(uint8_t *sig, size_t *siglen, const uint8_t *m, size_t mlen, const uint8_t *sk) {
118-
return _fn_symbol_${fn}(sig, siglen, m, mlen, sk);
119-
}
120-
#endif`).join('\n')}
121-
`;
122-
123-
await writeFile(`${buildDir}/missing-symbols.c`, wrapperCode);
124-
125-
console.log(`Compiling ${commonSourceFiles.length} common source files, ${kemSourceFiles.length} KEM source files, ${signSourceFiles.length} sign source files, and missing symbols`);
79+
console.log(`Compiling ${commonSourceFiles.length} common source files, ${kemSourceFiles.length} KEM source files, ${signSourceFiles.length} sign source files`);
12680

12781
const proc = spawn('emcc', [
12882
'-std=c11',
@@ -142,7 +96,6 @@ const proc = spawn('emcc', [
14296
...commonSourceFiles,
14397
...kemSourceFiles,
14498
...signSourceFiles,
145-
`${buildDir}/missing-symbols.c`,
14699
], {
147100
stdio: 'inherit'
148101
});
@@ -151,7 +104,5 @@ if (code !== 0) {
151104
throw new Error(`emcc exited with ${code !== null ? `code ${code}` : `signal ${signal}`}`);
152105
}
153106

154-
await unlink(`${buildDir}/missing-symbols.c`);
155-
156107
const { size } = await stat(`${buildDir}/pqclean.wasm`);
157108
console.log(`WebAssembly module size is ${(size / 1024).toFixed(1)} KiB`);

scripts/regenerate-native.mjs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,6 @@ namespace sign {
113113
114114
constexpr unsigned int N_ALGORITHMS = ${nSignImpls};
115115
116-
// Some implementations do not provide certain functions as symbols but only as
117-
// macros with parameters, which we cannot use as function pointers directly.
118-
namespace {
119-
${signImpls.map((impl) => `#ifdef PQCLEAN_${id(impl)}_CLEAN_crypto_sign_signature
120-
inline int _fn_symbol_PQCLEAN_${id(impl)}_CLEAN_crypto_sign_signature(uint8_t* sig, size_t* siglen, const uint8_t* m, size_t mlen, const uint8_t* sk) {
121-
return PQCLEAN_${id(impl)}_CLEAN_crypto_sign_signature(sig, siglen, m, mlen, sk);
122-
}
123-
#endif
124-
#ifdef PQCLEAN_${id(impl)}_CLEAN_crypto_sign
125-
inline int _fn_symbol_PQCLEAN_${id(impl)}_CLEAN_crypto_sign(uint8_t* sm, size_t* smlen, const uint8_t* m, size_t mlen, const uint8_t* sk) {
126-
return PQCLEAN_${id(impl)}_CLEAN_crypto_sign(sm, smlen, m, mlen, sk);
127-
}
128-
#endif
129-
#ifdef PQCLEAN_${id(impl)}_CLEAN_crypto_sign_verify
130-
inline int _fn_symbol_PQCLEAN_${id(impl)}_CLEAN_crypto_sign_verify(const uint8_t* sig, size_t siglen, const uint8_t* m, size_t mlen, const uint8_t* pk) {
131-
return PQCLEAN_${id(impl)}_CLEAN_crypto_sign_verify(sig, siglen, m, mlen, pk);
132-
}
133-
#endif
134-
#ifdef PQCLEAN_${id(impl)}_CLEAN_crypto_sign_open
135-
inline int _fn_symbol_PQCLEAN_${id(impl)}_CLEAN_crypto_sign_open(uint8_t* m, size_t* mlen, const uint8_t* sm, size_t smlen, const uint8_t* pk) {
136-
return PQCLEAN_${id(impl)}_CLEAN_crypto_sign_open(m, mlen, sm, smlen, pk);
137-
}
138-
#endif`).join('\n')}
139-
}
140-
141116
const std::array<Algorithm, N_ALGORITHMS>& algorithms() {
142117
static const std::array<Algorithm, N_ALGORITHMS> all = {{
143118
${signImpls.map((impl) => ` {
@@ -152,26 +127,10 @@ ${signImpls.map((impl) => ` {
152127
0,
153128
#endif
154129
PQCLEAN_${id(impl)}_CLEAN_crypto_sign_keypair,
155-
#ifndef PQCLEAN_${id(impl)}_CLEAN_crypto_sign_signature
156130
PQCLEAN_${id(impl)}_CLEAN_crypto_sign_signature,
157-
#else
158-
_fn_symbol_PQCLEAN_${id(impl)}_CLEAN_crypto_sign_signature,
159-
#endif
160-
#ifndef PQCLEAN_${id(impl)}_CLEAN_crypto_sign
161131
PQCLEAN_${id(impl)}_CLEAN_crypto_sign,
162-
#else
163-
_fn_symbol_PQCLEAN_${id(impl)}_CLEAN_crypto_sign,
164-
#endif
165-
#ifndef PQCLEAN_${id(impl)}_CLEAN_crypto_sign_verify
166132
PQCLEAN_${id(impl)}_CLEAN_crypto_sign_verify,
167-
#else
168-
_fn_symbol_PQCLEAN_${id(impl)}_CLEAN_crypto_sign_verify,
169-
#endif
170-
#ifndef PQCLEAN_${id(impl)}_CLEAN_crypto_sign_open
171133
PQCLEAN_${id(impl)}_CLEAN_crypto_sign_open
172-
#else
173-
_fn_symbol_PQCLEAN_${id(impl)}_CLEAN_crypto_sign_open
174-
#endif
175134
},`).join('\n')}
176135
}};
177136
return all;

0 commit comments

Comments
 (0)