Kim Alvefur
8136aa749a
util: Add compat for prosody module name change to C sources
3 years ago
Kim Alvefur
bf35a39a15
util.poll: Include unistd.h only for epoll
...
This defines close(), which is only used with epoll, hence we don't need
to include it when building in poll or select mode.
3 years ago
Kim Alvefur
1ea488deee
util.crypto: Preemptively silence 'strict-prototypes' warning
...
With `gcc-12 -Wstrict-prototypes` the following warning is shown:
crypto.c:43:13: warning: function declaration isn't a prototype [-Wstrict-prototypes]
43 | static BIO* new_memory_BIO() {
| ^~~~~~~~~~~~~~
3 years ago
Kim Alvefur
2e44f8260b
util.struct: Fix typo in comment
3 years ago
Kim Alvefur
43351d2b54
Spelling: Fix various spelling mistakes (thanks timeless)
...
Words, sometimes I wonder how they even work
Maybe I missed something.
4 years ago
Kim Alvefur
ffb37f3ef3
make: Fix build of util.struct on *BSD
4 years ago
Kim Alvefur
af95bb77e6
util.poll: Add support for the poll() API
...
Might be better than select(), more portable than epoll.
4 years ago
Kim Alvefur
04aa101da3
util.poll: Expose API (epoll or select) used
...
Could he handy to know for debugging or decisions
4 years ago
Kim Alvefur
22d734e305
util.poll: Restructure to make adding additional system APIs easier
4 years ago
Kim Alvefur
732d5ad8a8
util.hashes: Silence compiler warning about char pointer signedness
...
Introduced in dbe9781fd278
3 years ago
Matthew Wild
26dc334ae3
util.crypto: Add support for AES-256-CTR
...
This is required by PASETO v3.local
3 years ago
Matthew Wild
341c8417c2
util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
...
These are needed for PASETO v3.local.
3 years ago
Matthew Wild
fe56effa55
util.struct: Import Roberto 'struct' library v0.3
...
Downloaded from http://www.inf.puc-rio.br/~roberto/struct/
This is for compatibility with Lua 5.2 (and 5.1). Eventually we can replace
this with string.pack/string.unpack which are available in 5.3+.
4 years ago
Matthew Wild
8695a72a66
util.crypto, util.jwt: Generate consistent signature sizes (via padding)
...
This fixes the signature parsing and building to work correctly. Sometimes
a signature was one or two bytes too short, and needed to be padded. OpenSSL
can do this for us.
4 years ago
Kim Alvefur
62438f482e
util.crypto: Use Lua 5.2 API for predictable buffer size
...
In Lua 5.3 LUAL_BUFFERSIZE is a macro computed from sizeof and is thus
not known at pre-processing time, so this does not work.
Since Lua 5.1 is no longer supported, we can use luaL_prepbuffsize()
which is available from Lua 5.2
4 years ago
Kim Alvefur
e893bbf681
util.crypto: Use stack space buffers
...
Removes assumption that LUAL_BUFFERSIZE is known at pre-processing time,
which it is not in Lua 5.3 and 5.4, where it is a computed macro based
on sizeof.
Allocation of stack space is safer and faster, no need to worry about
luaL_prepbuffer failing to allocate memory and skipping free()
4 years ago
Matthew Wild
5316b0005e
util.crypto: More digests for sign/verify, use macros for clarity/consistency
4 years ago
Matthew Wild
d7b32f1b71
util.crypto: Friendlier error message on incorrect key types
4 years ago
Matthew Wild
ba282f1070
util.crypto: Add support for RSA signatures (PKCS1-v1.5 + PSS)
...
These are used by the RS*** and PS*** family of JOSE algorithms (e.g. in JWTs)
4 years ago
Matthew Wild
b357cf1be1
util.crypto: New wrapper for some operations in OpenSSL's libcrypto
...
Specifically, ED25519 key generation/import/export, sign/verify operations,
and AES encrypt/decrypt.
4 years ago
Matthew Wild
6a64363e78
util-src: Add new utility header managed_pointer.h
...
The macros in this header allow creation of GC-managed objects from manually-
managed C alloc/free APIs.
4 years ago
Kim Alvefur
dabdfc91be
util.table: Fix inaccurate comment
...
Probably a duplicate of the comment next to Lmove, recorded by mistake
Lpack can probably be removed at some point in the near future once we
are confident it is not used anywhere.
4 years ago
Kim Alvefur
dff4beae02
util-src: Remove Lua 5.1 compat macros
...
Part of #1600
4 years ago
Kim Alvefur
b1c7b93139
util.hashes: Revert to HMAC() convenience function
...
Reverts some of 1e41dd0f8353
Seems HMAC() isn't deprecated after all? Must have been at some point
according to #1589
Twice as fast for some reason.
4 years ago
Kim Alvefur
8f3d837cd2
util.hashes: Remove unused constants
4 years ago
Kim Alvefur
452f9e4e2b
util.hashes: Remove unused struct
...
Unused since 9f1c5ae8d70b
4 years ago
Kim Alvefur
9a96021706
util.hashes: Return OpenSSL error messages on failure
...
With luck, might contain more details than just "failed"
4 years ago
Kim Alvefur
a7567a9055
util.hashes: Add SHA3 bindings
6 years ago
Kim Alvefur
f3d61e3945
util.hashes: Bind BLAKE2 algoritms supported by OpenSSL
6 years ago
Kim Alvefur
9f932f7559
util.hashes: Refactor PBKDF2 to deduplicate code
6 years ago
Kim Alvefur
ae14dc1220
util.hashes: Expose sha224 and sha384 HMAC functions
...
For completeness and consistency with set of plain hash functions
6 years ago
Kim Alvefur
54f8ca81f4
util.hashes: Refactor HMAC bindings ( fixes #1589 )
...
HMAC() is deprecated
As with the regular hash functions, macros like this make it awkward to
apply static analysis and code formatting.
6 years ago
Kim Alvefur
d690f1502a
util.hashes: Refactor hash functions to use OpenSSL EVP methods ( fix #1698 )
...
MD5() is deprecated, but EVP_md5() is not.
Functions in macros like this make it awkward to apply static analysis
and code formatting.
6 years ago
Kim Alvefur
300813b68b
util.crand: Reduce scope here too
...
Same as previous commit
4 years ago
Kim Alvefur
787835d693
util.strbitop: Reduce scope of functions
...
Equivalent to 'local' in Lua, these functions are exported via the
luaopen_ function, which is the only one needing to be visible outside
of the file.
Pointed out by Link Mauve at some point, but there wasn't really any
rush here.
4 years ago
Matthew Wild
f5460a5037
util.hashes: Add constant-time string comparison (binding to CRYPTO_memcmp)
5 years ago
Kim Alvefur
20fc0c9c15
Back out changeset 2c1583bb0e0f
...
Same reason as 712b2e6a09d9
6 years ago
Kim Alvefur
bad47be8f9
Back out 6dde2c9fa272: Doesn't work on Lua 5.1
6 years ago
Kim Alvefur
9b8a54345f
util.strbitop: Remove redundant init function
...
When you have 3 almost identical functions, you tend to edit one and
then copypaste. Forgot to remove this line from the other two.
6 years ago
Kim Alvefur
da8eca639a
util.strbitop: Create buffer in the correct size (optimization)
...
This avoids dynamically growing the buffer as Lua does when luaL_addchar
is used, thus saving on realloc calls.
6 years ago
Kim Alvefur
539255c692
util.strbitop: Reformat code
...
astyle \
--indent=tab \
--attach-classes \
--indent-switches \
--break-blocks \
--pad-oper \
--unpad-paren \
--add-braces \
--align-pointer=name \
--lineend=linux \
*.c
6 years ago
Kim Alvefur
fb1808b185
util.strbitop: Library for bitwise operations on strings
7 years ago
Kim Alvefur
d3bd9f9be5
util.pposix: Use mallinfo2() on glibc 2.33, fix #1649
4 years ago
Kim Alvefur
b93398ce79
util.pposix: Bind isatty(3)
...
Useful for disabling certain behavior, ANSI colors etc when not
connected to a terminal.
5 years ago
Kim Alvefur
654fd45546
util.hashes: Expose OpenSSL version
5 years ago
Kim Alvefur
9eb8214030
configure: Pass compiler flag to enable ICU only when building util.encodings
...
Passing it in CFLAGS applied to all modules, which was not needed.
6 years ago
Matthew Wild
b9a670dace
util.ringbuffer: Ensure unsigned chars are always returned from :byte()
6 years ago
Kim Alvefur
625ec0a93f
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
...
Actually just an alias of pushnil, but it does make it more obvious
where the failure conditions are, which is good for readability.
6 years ago
Matthew Wild
14a436817d
util.ringbuffer: Add :sub() and :byte() methods equivalent to the string methods
6 years ago
Kim Alvefur
4bab7af07d
util.ringbuffer: Prevent creation of buffer with negative size
...
Previously this would have been (unsigned)-1 which is a large positive
integer.
6 years ago