Hi, I've been looking through the code of this repo while doing my own Noise XX and KK implementation based on monocypher and noticed an issue with usage of C++ exceptions.
I see that not all the code that exceptions can be thrown through is exception-safe. For example, some code fails to call crypto_wipe if an exception is thrown. Specifically worrying is the exceptions thrown in decrypt, as failing to decrypt doesn't necessarily mean that the communication session needs to be terminated (specifically, after the handshake phase), so this could leave some sensitive for the session values on the stack.
Biased opinion follows.
My personal opinion would be not to use exceptions at all, and use enum-based return codes instead. I feel like this would increase the adoption of the library, as some C++ programmers are allergic to exceptions.
Hi, I've been looking through the code of this repo while doing my own Noise XX and KK implementation based on monocypher and noticed an issue with usage of C++ exceptions.
I see that not all the code that exceptions can be thrown through is exception-safe. For example, some code fails to call crypto_wipe if an exception is thrown. Specifically worrying is the exceptions thrown in
decrypt, as failing to decrypt doesn't necessarily mean that the communication session needs to be terminated (specifically, after the handshake phase), so this could leave some sensitive for the session values on the stack.Biased opinion follows.
My personal opinion would be not to use exceptions at all, and use enum-based return codes instead. I feel like this would increase the adoption of the library, as some C++ programmers are allergic to exceptions.