]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fsprg: Drop const from gcry_mpi_t arguments
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 25 Nov 2025 11:09:34 +0000 (12:09 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 26 Nov 2025 07:22:32 +0000 (16:22 +0900)
gcry_mpi_t is defined as "typedef struct gcry_mpi *gcry_mpi_t;".
When const is applied to this type, it resolves to
"struct gcry_mpi *const" instead of what we expect ("const struct gcry_mpi *").

So we end up with a const pointer to a mutable object instead of a mutable
pointer to a const object. Since the pointer passed to the function
is copied regardless, making it const has zero benefit.

You'd think we could instead stop using gcry_mpi_t and replace it with
"const struct gcry_mpi *", except that gcrypt leaked this mess into its
api, so it expects const pointers to mutable objects as well, which means
we can't take pointers to const objects as arguments, as we'd discard the qualifier
when calling a gcrypt function.

To avoid confusion, let's drop the const qualifiers from the gcry_mpi_t arguments.

src/libsystemd/sd-journal/fsprg.c

index 707177b9f4495571c7e5135e6ab52dda91fb8bfb..aebb46b521cb03c06d93daa7a68c3bf5a2b1858f 100644 (file)
@@ -33,7 +33,7 @@
 
 /******************************************************************************/
 
-static void mpi_export(void *buf, size_t buflen, const gcry_mpi_t x) {
+static void mpi_export(void *buf, size_t buflen, gcry_mpi_t x) {
         unsigned len;
         size_t nwritten;
 
@@ -136,7 +136,7 @@ static gcry_mpi_t genprime3mod4(int bits, const void *seed, size_t seedlen, uint
 }
 
 /* deterministically generate from seed/idx a quadratic residue (mod n) */
-static gcry_mpi_t gensquare(const gcry_mpi_t n, const void *seed, size_t seedlen, uint32_t idx, unsigned secpar) {
+static gcry_mpi_t gensquare(gcry_mpi_t n, const void *seed, size_t seedlen, uint32_t idx, unsigned secpar) {
         size_t buflen = secpar / 8;
         uint8_t buf[buflen];
         gcry_mpi_t x;
@@ -150,7 +150,7 @@ static gcry_mpi_t gensquare(const gcry_mpi_t n, const void *seed, size_t seedlen
 }
 
 /* compute 2^m (mod phi(p)), for a prime p */
-static gcry_mpi_t twopowmodphi(uint64_t m, const gcry_mpi_t p) {
+static gcry_mpi_t twopowmodphi(uint64_t m, gcry_mpi_t p) {
         gcry_mpi_t phi, r;
         int n;
 
@@ -178,7 +178,7 @@ static gcry_mpi_t twopowmodphi(uint64_t m, const gcry_mpi_t p) {
 }
 
 /* Decompose $x \in Z_n$ into $(xp,xq) \in Z_p \times Z_q$ using Chinese Remainder Theorem */
-static void CRT_decompose(gcry_mpi_t *xp, gcry_mpi_t *xq, const gcry_mpi_t x, const gcry_mpi_t p, const gcry_mpi_t q) {
+static void CRT_decompose(gcry_mpi_t *xp, gcry_mpi_t *xq, gcry_mpi_t x, gcry_mpi_t p, gcry_mpi_t q) {
         *xp = sym_gcry_mpi_new(0);
         *xq = sym_gcry_mpi_new(0);
         sym_gcry_mpi_mod(*xp, x, p);
@@ -186,7 +186,7 @@ static void CRT_decompose(gcry_mpi_t *xp, gcry_mpi_t *xq, const gcry_mpi_t x, co
 }
 
 /* Compose $(xp,xq) \in Z_p \times Z_q$ into $x \in Z_n$ using Chinese Remainder Theorem */
-static void CRT_compose(gcry_mpi_t *x, const gcry_mpi_t xp, const gcry_mpi_t xq, const gcry_mpi_t p, const gcry_mpi_t q) {
+static void CRT_compose(gcry_mpi_t *x, gcry_mpi_t xp, gcry_mpi_t xq, gcry_mpi_t p, gcry_mpi_t q) {
         gcry_mpi_t a, u;
 
         a = sym_gcry_mpi_new(0);