Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mRemoteNG/PuTTYNG.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/keygen
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2021-11-19 13:23:32 +0300
committerSimon Tatham <anakin@pobox.com>2021-11-19 14:32:47 +0300
commitbe8d3974ff7ccf3864d134722ff5b9ba611c1ed4 (patch)
tree48a2241a810e82403ac4291e0f2a2822213c8dc4 /keygen
parentefee4e0eae8cc15fdb8614c022e67b9568d8a0cb (diff)
Generalise strbuf_catf() into put_fmt().
marshal.h now provides a macro put_fmt() which allows you to write arbitrary printf-formatted data to an arbitrary BinarySink. We already had this facility for strbufs in particular, in the form of strbuf_catf(). That was able to take advantage of knowing the inner structure of a strbuf to minimise memory allocation (it would snprintf directly into the strbuf's existing buffer if possible). For a general black-box BinarySink we can't do that, so instead we dupvprintf into a temporary buffer. For consistency, I've removed strbuf_catf, and converted all uses of it into the new put_fmt - and I've also added an extra vtable method in the BinarySink API, so that put_fmt can still use strbuf_catf's more efficient memory management when talking to a strbuf, and fall back to the simpler strategy when that's not available.
Diffstat (limited to 'keygen')
-rw-r--r--keygen/pockle.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/keygen/pockle.c b/keygen/pockle.c
index 60017e33..2a072f18 100644
--- a/keygen/pockle.c
+++ b/keygen/pockle.c
@@ -410,10 +410,10 @@ strbuf *pockle_mpu(Pockle *pockle, mp_int *p)
memset(needed, 0, pockle->nlist * sizeof(bool));
needed[pr->index] = true;
- strbuf_catf(sb, "[MPU - Primality Certificate]\nVersion 1.0\nBase 10\n\n"
- "Proof for:\nN ");
+ put_fmt(sb, "[MPU - Primality Certificate]\nVersion 1.0\nBase 10\n\n"
+ "Proof for:\nN ");
mp_write_decimal(sb, p);
- strbuf_catf(sb, "\n");
+ put_fmt(sb, "\n");
for (size_t index = pockle->nlist; index-- > 0 ;) {
if (!needed[index])
@@ -421,27 +421,27 @@ strbuf *pockle_mpu(Pockle *pockle, mp_int *p)
pr = pockle->list[index];
if (mp_get_nbits(pr->prime) <= 64) {
- strbuf_catf(sb, "\nType Small\nN ");
+ put_fmt(sb, "\nType Small\nN ");
mp_write_decimal(sb, pr->prime);
- strbuf_catf(sb, "\n");
+ put_fmt(sb, "\n");
} else {
assert(pr->witness);
- strbuf_catf(sb, "\nType BLS5\nN ");
+ put_fmt(sb, "\nType BLS5\nN ");
mp_write_decimal(sb, pr->prime);
- strbuf_catf(sb, "\n");
+ put_fmt(sb, "\n");
for (size_t i = 0; i < pr->nfactors; i++) {
- strbuf_catf(sb, "Q[%"SIZEu"] ", i+1);
+ put_fmt(sb, "Q[%"SIZEu"] ", i+1);
mp_write_decimal(sb, pr->factors[i]->prime);
assert(pr->factors[i]->index < index);
needed[pr->factors[i]->index] = true;
- strbuf_catf(sb, "\n");
+ put_fmt(sb, "\n");
}
for (size_t i = 0; i < pr->nfactors + 1; i++) {
- strbuf_catf(sb, "A[%"SIZEu"] ", i);
+ put_fmt(sb, "A[%"SIZEu"] ", i);
mp_write_decimal(sb, pr->witness);
- strbuf_catf(sb, "\n");
+ put_fmt(sb, "\n");
}
- strbuf_catf(sb, "----\n");
+ put_fmt(sb, "----\n");
}
}
sfree(needed);