What changed, and why it matters
This commit is a cleanup of how the word 'const' is used in the Trezor firmware's ed25519 cryptographic code. Previously, the code defined a custom 'CONST' macro that meant 'const' on newer compilers and nothing on older GCC versions. The commit removes that macro and uses plain 'const' everywhere. It also adjusts a Rust build script comment and compiler flag. There is no indication in the commit that this fixes a security vulnerability or changes runtime behavior.
No security action required. Treat as a normal code-quality/build cleanup commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch removes the CONST macro from crypto/ed25519-donna/ed25519.h and replaces its two remaining uses with standard ‘const’ in ed25519.c function signatures. The Rust build.rs change swaps a bindgen clang argument from ‘-fgnuc-version=0’ (which was a workaround for the CONST macro confusing bindgen) to ‘-Wno-unused-function’ (to suppress warnings from static inline functions in mode_hdr.h). The change is syntactic/build-level and does not alter code logic, memory safety, or cryptographic operations.
Changed components
crypto/ed25519-donna/ed25519.hcrypto/ed25519-donna/ed25519.ccore/embed/rust/build.rsInspect captured patch +5 / −11
diff --git a/core/embed/rust/build.rs b/core/embed/rust/build.rs
index 39479e60..558f5641 100644
--- a/core/embed/rust/build.rs
+++ b/core/embed/rust/build.rs
@@ -580,7 +580,7 @@ fn generate_crypto_bindings() {
// Write the bindings to a file in the OUR_DIR.
bindings
- .clang_arg("-fgnuc-version=0") // avoid weirdness with ed25519.h CONST definition
+ .clang_arg("-Wno-unused-function") // mode_hdr.h has static inline functions unused at parse time
.generate()
.expect("Unable to generate bindings")
.write_to_file(PathBuf::from(out_path).join("crypto.rs"))
diff --git a/crypto/ed25519-donna/ed25519.c b/crypto/ed25519-donna/ed25519.c
index adc608d3..7fda5892 100644
--- a/crypto/ed25519-donna/ed25519.c
+++ b/crypto/ed25519-donna/ed25519.c
@@ -222,7 +222,7 @@ ed25519_publickey_ext(const ed25519_secret_key extsk, ed25519_public_key pk) {
}
int
-ed25519_cosi_combine_publickeys(ed25519_public_key res, CONST ed25519_public_key *pks, size_t n) {
+ed25519_cosi_combine_publickeys(ed25519_public_key res, const ed25519_public_key *pks, size_t n) {
size_t i = 0;
ge25519 P = {0};
ge25519_pniels sump = {0};
@@ -253,7 +253,7 @@ ed25519_cosi_combine_publickeys(ed25519_public_key res, CONST ed25519_public_key
}
void
-ed25519_cosi_combine_signatures(ed25519_signature res, const ed25519_public_key R, CONST ed25519_cosi_signature *sigs, size_t n) {
+ed25519_cosi_combine_signatures(ed25519_signature res, const ed25519_public_key R, const ed25519_cosi_signature *sigs, size_t n) {
bignum256modm s = {0}, t = {0};
size_t i = 0;
diff --git a/crypto/ed25519-donna/ed25519.h b/crypto/ed25519-donna/ed25519.h
index defaf436..30796cc0 100644
--- a/crypto/ed25519-donna/ed25519.h
+++ b/crypto/ed25519-donna/ed25519.h
@@ -29,14 +29,8 @@ int ed25519_scalarmult(ed25519_public_key res, const ed25519_secret_key sk, cons
void curve25519_scalarmult(curve25519_key mypublic, const curve25519_key secret, const curve25519_key basepoint);
void curve25519_scalarmult_basepoint(curve25519_key mypublic, const curve25519_key secret);
-#if !defined(__GNUC__) || __GNUC__ > 4
-#define CONST const
-#else
-#define CONST
-#endif
-
-int ed25519_cosi_combine_publickeys(ed25519_public_key res, CONST ed25519_public_key *pks, size_t n);
-void ed25519_cosi_combine_signatures(ed25519_signature res, const ed25519_public_key R, CONST ed25519_cosi_signature *sigs, size_t n);
+int ed25519_cosi_combine_publickeys(ed25519_public_key res, const ed25519_public_key *pks, size_t n);
+void ed25519_cosi_combine_signatures(ed25519_signature res, const ed25519_public_key R, const ed25519_cosi_signature *sigs, size_t n);
void ed25519_cosi_commit(ed25519_secret_key nonce, ed25519_public_key commitment);
int ed25519_cosi_sign(const unsigned char *m, size_t mlen, const ed25519_secret_key key, const ed25519_secret_key nonce, const ed25519_public_key R, const ed25519_public_key pk, ed25519_cosi_signature sig);
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.