Clarification on Memory Allocation for Libsodium in C# #1406
Unanswered
Wojtekxor2
asked this question in
Q&A
Replies: 2 comments 1 reply
-
Why can't you use an existing .NET binding? They save you from having to do this yourself and are heavily tested. Anyway, if you can't/don't want to use one for whatever reason, you can follow what they're doing, like this. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Not that .NET version I need it for. I looked at nSec however I didn't find chacha implementation for long data (with update method) ... |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I’m using C# with Libsodium, and I have a couple of questions regarding memory allocation for structs. Currently, I calculate SHA-256 hashes for binary files and also perform encryption using XChaCha20-Poly1305.
I’m a bit unclear on whether I should manually allocate memory for the following structs, or if it's handled automatically:
Initially, I was declaring them like this:
or
Is this approach correct, or should I be manually allocating memory for these structs using Marshal.AllocHGlobal or another method (e.g., for XChaCha20 specifically or for both)?
I came across some Delphi code that aligns memory for XChaCha, and I rewrote it in C#. Here's the code I’m using:
Is this approach necessary? Should I always be aligning the memory for these structs, or is this only required in specific cases?
Beta Was this translation helpful? Give feedback.
All reactions