Block Cipher Reccomendations
- avalyn0x45
- Posts: 7
- Joined: Sat Aug 22, 2026 3:40 pm
Block Cipher Reccomendations
I'm trying to implement a non-repeating PRNG, and it seems that the best way to do that is with a block cipher on an increasing value. Are there any 64 bit block ciphers that would be easy to implement in x86_64 assembly?
“By what right then can any one whatever appropriate the least morsel of this immense whole and say--This is mine, not yours?”
Re: Block Cipher Reccomendations
There is no such thing as a non-repeating PRNG. Any PRNG has a finite amount of state, and therefore a finite number of states it can be in, and therefore has to repeat its sequence at some point.
But anyway, a block cipher that should be easy to implement in x86_64, if you're willing to use architecture extensions, would be Rijndael, since the introduction of AES-NI means that it can be implemented in only a few instructions. Otherwise they are all very long instruction lists. May I ask why assembler and not C or any other high-level language?
Another approach may be to use the SHA counter algorithm. You fill a hash buffer with entropy (e.g. from a simpler LCG), and then, when more entropy is requested, you hash that buffer (with something like SHA-3) and return the data from that hash. Once that data is used up, you increment the buffer and return the hash of the increment. Highly unlikely to repeat until the hash buffer has completely wrapped around.
But anyway, a block cipher that should be easy to implement in x86_64, if you're willing to use architecture extensions, would be Rijndael, since the introduction of AES-NI means that it can be implemented in only a few instructions. Otherwise they are all very long instruction lists. May I ask why assembler and not C or any other high-level language?
Another approach may be to use the SHA counter algorithm. You fill a hash buffer with entropy (e.g. from a simpler LCG), and then, when more entropy is requested, you hash that buffer (with something like SHA-3) and return the data from that hash. Once that data is used up, you increment the buffer and return the hash of the increment. Highly unlikely to repeat until the hash buffer has completely wrapped around.
Carpe diem!
- avalyn0x45
- Posts: 7
- Joined: Sat Aug 22, 2026 3:40 pm
Re: Block Cipher Reccomendations
By non-repeating, I mean that it will not repeat before every possible value has been returned. I specifically need 64 bit output, which excludes AES and SHA as they both would require truncation, and would not guarantee a period of 2^64 after that.
“By what right then can any one whatever appropriate the least morsel of this immense whole and say--This is mine, not yours?”
- avalyn0x45
- Posts: 7
- Joined: Sat Aug 22, 2026 3:40 pm
Re: Block Cipher Reccomendations
The entirety of the codebase that this is going to be integrated into is written in assembly.
“By what right then can any one whatever appropriate the least morsel of this immense whole and say--This is mine, not yours?”
Re: Block Cipher Reccomendations
That wouldn't stop you writing this particular function in C. It would be much easier.
- avalyn0x45
- Posts: 7
- Joined: Sat Aug 22, 2026 3:40 pm
Re: Block Cipher Reccomendations
I neither have a stack or a compiler. That's a fairly big roadblock for writing it in c.
“By what right then can any one whatever appropriate the least morsel of this immense whole and say--This is mine, not yours?”
- avalyn0x45
- Posts: 7
- Joined: Sat Aug 22, 2026 3:40 pm
Re: Block Cipher Reccomendations
I will also note that I am fine with a C implementation that I can manually translate into assembly.
“By what right then can any one whatever appropriate the least morsel of this immense whole and say--This is mine, not yours?”
-
Octocontrabass
- Member

- Posts: 6261
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Block Cipher Reccomendations
Why don't you have a stack?
- avalyn0x45
- Posts: 7
- Joined: Sat Aug 22, 2026 3:40 pm
Re: Block Cipher Reccomendations
Because I don't need one.
“By what right then can any one whatever appropriate the least morsel of this immense whole and say--This is mine, not yours?”
-
Octocontrabass
- Member

- Posts: 6261
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Block Cipher Reccomendations
Why don't you need a stack? How are you able to do things like call functions and handle interrupts without one?
- avalyn0x45
- Posts: 7
- Joined: Sat Aug 22, 2026 3:40 pm
Re: Block Cipher Reccomendations
The logic is small enough to not require function calls, and interrupts are handled by setting rsp0 to a tiny 64 byte region of memory only used for interrupts.Octocontrabass wrote: ↑Tue Sep 29, 2026 4:32 pm Why don't you need a stack? How are you able to do things like call functions and handle interrupts without one?
“By what right then can any one whatever appropriate the least morsel of this immense whole and say--This is mine, not yours?”