X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fjournal%2Ffsprg.c;h=5c8d6d6febf0444557bd2142757a7fb8f0943327;hp=34ce3be96b707bca7844f38d7746f98de8ded31b;hb=79008bddf679a5e0900369950eb346c9fa687107;hpb=7560fffcd2531786b9c1ca657667a43e90331326 diff --git a/src/journal/fsprg.c b/src/journal/fsprg.c index 34ce3be96..5c8d6d6fe 100644 --- a/src/journal/fsprg.c +++ b/src/journal/fsprg.c @@ -19,7 +19,13 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA + */ + +/* + * See "Practical Secure Logging: Seekable Sequential Key Generators" + * by G. A. Marson, B. Poettering for details: * + * http://eprint.iacr.org/2013/397 */ #include @@ -45,7 +51,7 @@ static void mpi_export(void *buf, size_t buflen, const gcry_mpi_t x) { assert(gcry_mpi_cmp_ui(x, 0) >= 0); len = (gcry_mpi_get_nbits(x) + 7) / 8; assert(len <= buflen); - memset(buf, 0, buflen); + memzero(buf, buflen); gcry_mpi_print(GCRYMPI_FMT_USG, buf + (buflen - len), len, &nwritten, x); assert(nwritten == len); } @@ -74,7 +80,7 @@ static void uint64_export(void *buf, size_t buflen, uint64_t x) { ((uint8_t*) buf)[7] = (x >> 0) & 0xff; } -static uint64_t uint64_import(const void *buf, size_t buflen) { +_pure_ static uint64_t uint64_import(const void *buf, size_t buflen) { assert(buflen == 8); return (uint64_t)(((uint8_t*) buf)[0]) << 56 | @@ -160,7 +166,7 @@ static gcry_mpi_t twopowmodphi(uint64_t m, const gcry_mpi_t p) { gcry_mpi_sub_ui(phi, p, 1); /* count number of used bits in m */ - for (n = 0; ((uint64_t)1 << n) <= m; n++) + for (n = 0; (1ULL << n) <= m; n++) ; r = gcry_mpi_new(0); @@ -300,7 +306,7 @@ void FSPRG_GenState0(void *state, const void *mpk, const void *seed, size_t seed memcpy(state, mpk, 2 + secpar / 8); mpi_export(state + 2 + 1 * secpar / 8, secpar / 8, x); - memset(state + 2 + 2 * secpar / 8, 0, 8); + memzero(state + 2 + 2 * secpar / 8, 8); gcry_mpi_release(n); gcry_mpi_release(x);