Is it possible to create the constants used in SHA256 on the fly? Meaning I dont have to reserve 64 32-bit words of space? It would result in a slower implementation, but at the profit of using less memory. I know it is possible to do it with AES Sboxes, but how about the SHA256 constants?
If you look at the specification to understand how those constants were chosen, you'll realize you waste more memory generating them "on the fly".
SHA-256 compression function key schedule constants are calculated as the fraction part of cubic-root of the first 64 prime numbers. You said you coud delete them after use (in the comment), but wouldn't that overlap with DRAM allocated for message buffer or something else? If you need a memory-compact implementation, this would be an anti-optimization.
If you desire a hash function without large memory footprint, you could consider SHA-3/Keccak, it too has some constants, but generating them "on the fly" requires only few additional registers to hold values from a LSFR.
$\begingroup$ Does generating them on the fly reserve more memory, or just dynamic memory? By memory I mean, stuff you have to save no matter what, which will be the minimal assumption of memory you have. If you use more RAM to generate the constants and then delete them, thats okay, what I mean by memory is the static memory. $\endgroup$– alice03Feb 11, 2021 at 17:10
$\begingroup$ @alice03 See updated answer. $\endgroup$– DannyNiuFeb 11, 2021 at 18:32