sodium-friends / sodium-native

Low level bindings for libsodium
MIT License
300 stars 64 forks source link

Remove stdlib dependency #162

Closed chm-diederichs closed 2 years ago

chm-diederichs commented 2 years ago

This PR removes the string.h dependency.

Previously memcpy was used to write from intermediate values to the returned value. In both cases only 32 bytes were copied, so a naive for loop is used instead.

mafintosh commented 2 years ago

I think this would be sufficient also:

#define SN_COPY_32(a, b) \
  { \
    long long *src = (long long *) a; \
    long long *dst = (long long *) b; \
    *dst = *src; \
    *(++dst) = *(++src); \
    *(++dst) = *(++src); \
    *(++dst) = *(++src); \
  };

cc @kasperisager for review of that

mafintosh commented 2 years ago

https://en.wikipedia.org/wiki/C_data_types <-- guaranteed to be 64bit

kasperisager commented 2 years ago

I'd use uint64_t from stdint.h to make the intent clear.

chm-diederichs commented 2 years ago

Wouldn't stdint.h reintroduce stdlib dep?

chm-diederichs commented 2 years ago

I've used the above macro, but using explicit indices instead of incrementing the pointer for clarity. Let me know if I should revert to the macro above.

kasperisager commented 2 years ago

@chm-diederichs stdint.h only contains typedefs so no symbols should be linked against.

kasperisager commented 2 years ago

Granted, long long works fine and is guaranteed to be at least 64 bits!

SimenB commented 2 years ago

Release? 🙏

louneskmt commented 1 year ago

Any update on this?