1

When making an IV for AES-256 CBC mode the IV should be random and shouldn't be able to be guessed.

If I were to use the rand() function in C, seeded with time(NULL) to generate sim random numbers which would then be put through sha256, would that be a secure IV or would that still be vulnerable as the seed was the time?

I am under the impression that the IV is only there so that the same data encrypted twice with the same key would come out differently because of the IV.

1 Answer 1

3

Given that rand() is only a pseudo-random function and thus kind of predictable and that time() is actually very predictable (i.e. only a few values within a specific time frame) and that the predictability of the output of SHA-256 is the same as the predictability of its input it should be clear that essentially the result is about as predictable as the original rand(), provided that the attacker knows how your seed was constructed.

3
  • 1
    but does this matter as the iv is only really used so that the same data is not encrypted twice?
    – dangee1705
    Jul 20, 2017 at 9:43
  • @DanielGee Depends on how often you seed with time(NULL). My question is, if you're using a CSPRNG for your AES key, why not just use that?
    – RoraΖ
    Jul 20, 2017 at 11:38
  • 1
    @DanielGee: You are right in that the IV does not need to be cryptographically random. It only needs to be different if the same message is encrypted again with the same key. But in this case - why make it too complex with calling rand() and time() instead of just using SHA-256 of a global counter? Jul 20, 2017 at 16:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .