botan
botan copied to clipboard
Botan::AutoSeeded_RNG is not swappable
The following doesn't compile:
using std::swap;
Botan::AutoSeeded_RNG a,b;
swap(a,b);
Please could we make most objects swappable.
This could be implemented, but why would you need to do this?
Because std::swap is great and it's nice when types have well defined swap functions as well as copy semantics and move semantics. Otherwise you need to use hacks like wrapping types in std::unique_ptr or std::shared_ptr which have all of the above.
I can understand that as a general rule for types. But my point is more, in this specific instance - one AutoSeeded_RNG
is literally (cryptographically) indistinguishable from any other AutoSeeded_RNG
so not swapping should have identical behavior as swapping, because you should not be able to detect any difference between a
and b
.
So AutoSeeded_RNG
always produces the same sequence ?
No, it always produces a cryptographically random sequence of bits.
If you could swap a
and b
and detect via any computational means any difference in their output distributions, then you would have broken HMAC-DRBG.
Hmm. Not sure what the type system rules should be in this case for AutoSeeded_RNG
. I guess it doesn't make sense to make it moveable either. Currently it's moveable. But if you're willing to make it moveable, then it makes sense to also make it swappable.
You can either think of a swap as being 2 moves or a move as being a swap (with some default constructed empty state to reset the moved from object to something sensible). So move and swap go hand in hand in my mind.