Score:0

Standard way to generate pseudorandom bytes on demand

in flag

I considered Extendable-Output Function (XOF) with a random seed but it seems I would have to specify the output length at the start and store the entire output. I don't know how many bytes I will need in advance, and I don't want to store a very long string.

I also considered some ad-hoc stateful construction using XOF that maintains a running counter. I wonder what is the "standard" and efficient way to do this.

Paul Uszak avatar
cn flag
Is there some nuance that's not apparent from the question's title? Why not just do the standard thing: CSPRNG?
Maarten Bodewes avatar
in flag
@PaulUszak One thing that might be an issue is that many CSPRNG *implementations* are seeded by the system, may be reseeded etc. So they are not reliable to generate the same bits all the time. Some CSPRNG's may also specify a specific speed size, so there's that. But yeah, if this is just about getting random bytes or integers: use a CSPRNG.
Score:0
my flag

I considered Extendable-Output Function (XOF) with a random seed but it seems I would have to specify the output length at the start and store the entire output.

No; the standard SHAKE XOF doesn't need to know up front how long of an output it can generate; there's no reason why you can't keep on 'squeezing' to get as much output as you need.

Now, it's possible that the API for the crypto library that you are using has such a limitation (that is, it'll always generate all its output at once, and has no provision to generate any more). On the other hand, I wouldn't naively expect that from a library - have you looked to ensure that your library doesn't have a 'generate more output' function/API available (possibly by simply calling the 'generate output API' with the SHAKE state)?

Myath avatar
in flag
I'm looking at Python hashlib https://docs.python.org/3/library/hashlib.html and it doesn't seem to have such an API.
poncho avatar
my flag
@Myath: I suspect that calling shake.digest(length) multiple times will generate consecutive parts of the shake output.
JamesTheAwesomeDude avatar
cn flag
@poncho Sadly, that is not the case; I just tested it. It looks like @Myath will have to use a 3rd-party library such as [`pycryptodome`](https://pycryptodome.readthedocs.io/en/stable/src/hash/shake256.html)—neither the standard library nor [`pyca/cryptography`](https://cryptography.io/en/latest/hazmat/primitives/cryptographic-hashes/#cryptography.hazmat.primitives.hashes.SHAKE256) supports that functionality, strangely.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.