packages feed

crypton-2.3.1 / cbits / tests / scrub / README

What is left in memory after a secret has been through it.Round eight asked whether a secret can be read from the time a primitivetakes.  This asks whether it can be read from the memory afterwards.  Thestack below a returning function is not erased -- it is simply no longeraddressed -- and a context handed back to a caller is whatever the primitiveleft in it, so a later core file, crash dump or swapped page can carry a keyaway long after the caller believes it is done with it.Each probe paints the stack with a filler, runs a primitive on anunmistakable secret, copies the painted region away before anything candisturb it, and looks for the pattern.  Two things are asked separately:  scratch   what the primitive left below the caller's frame, in its own            working memory  context   what it left in the context object the caller still holds, which            is on the heap here as it is in cryptonThe first probe keeps the secret on purpose and has to be found.  That is notceremony: the first two versions of this file reported that nothing was everleft behind, including by that probe, and both times the search was at fault.Once because the probed function was inlined into its caller, so its localssat in a live frame rather than an abandoned one; once because the loop thatcopies the region away was turned into a call to memcpy, whose own framelanded exactly on the evidence.What this can say and what it cannot------------------------------------It finds a secret that survives *as it was handed over*.  It cannot find onethat survives transformed, and the difference matters: Poly1305 reportsnothing, but its finalize clears nothing either -- the key is clamped into rand pad, so it is still there and simply not byte-for-byte what was passed in.Read "no verbatim copy" as exactly that and no more.What it found-------------Nothing survives in any primitive's own scratch.  The RSA exponentiation isclean, which is worth saying because crypton_powm_sec memsets its table andthen frees it, and a compiler is entitled to drop a store to memory that isabout to die.  clang at -O2 keeps it -- the bzero is still there in theassembly, two instructions before the free -- but that is the compiler'schoice rather than a guarantee, and explicit_bzero exists for this.Three contexts keep the secret as it was given: SHA-256, SHA-512 andChaCha20.  The hash ones hold the buffered message, the ChaCha one holds thekey.  Nothing clears any of them, in the C or in the Haskell above it, whereContext is Bytes rather than ScrubbedBytes -- and hashFinalize copies thecontext before finalizing, so there are two of them per digest.  They arelisted in known.txt; whether to clear them is a question about what a contextmeans after it is finished with, and about the cost of scrubbing every hash,rather than something to settle here.