Given the example code below that generates 32 bytes and masks the first bytes with zeroes.
static uint256_t rand256(struct seed *seed)
{
seed->counter++;
return sha256(seed, sizeof(struct seed));
}
static uint256_t rand256_and_mask(struct seed *seed)
{
uint256_t r = rand256(seed);
memset(&r, 0, 27);
//r.i8[23] = 0xE;
return r;
}
I would like to get the bytes sequentially(as in sequence like \x09,\x0A ... 99
) with the difference of +1
, like if the last byte is "\x09"
on first call then on second call it would be "\x0A"
.
Note: the numbers i am working on are very large and my program accept type "uint256_t"
which is declared like this:
union uint256_s
{
uint8_t i8[32];
uint16_t i16[16];
uint32_t i32[8];
uint64_t i64[4];
};
typedef union uint256_s uint256_t;
Lets say uint256_t r = rand256(seed); produce this on first execution of my program:
E8411A8777E440FD1FA6CBF5F5149D14B45844B32F7B720CE653686229F9B758
then after memset in rand256_and_mask() the value of r
returned will be:
0000000000000000000000000000000000000000000000000000000029F9B758
Here i need to keep the value of r
which i will then increment by 1 on the next call (skip rand256() call if necessary), so the value of r
will be:
0000000000000000000000000000000000000000000000000000000029F9B759
Technically i need the program to keep track of r
as it represents a position in range.
I am not fluent in C, so I hope I clarified something.
C developers please help.