Kim Alvefur
ea7bf939d5
util.signal: Factor out single #define that enables signalfd(2) use
...
Makes it easier to test by disabling this #define
2025-01-10 12:31:27 +01:00
Kim Alvefur
4919301ad4
util.signal: Implement signalfd for *BSD
...
The Lua hook based signal handling does not work correctly if signal
handling is setup in a coroutine. signalfd solves that in a nice way,
but is Linux-only.
2025-01-10 03:18:46 +01:00
Matthew Wild
a3b71e8fc9
util.pposix: Add fdopen() to return a Lua file object from an fd
...
Now we can, for example, read/write pipes using Lua's standard I/O routines.
2024-11-20 12:08:59 +00:00
Matthew Wild
6480651a93
util.pposix: Add pipe() (with support for pipe2() flags on Linux)
2024-11-16 12:26:55 +00:00
Stephen Paul Weber
d477528e67
util.crypto: Add more ECC methods
...
pkey_meth_derive: to derive a shared symmetric key from two ECC keys
pkey_meth_public_raw: to get the raw form of the public key
import_public_ec_raw: to import the raw form of the public key
generate_p256_keypair: key generation for the P-256 curve
2024-10-29 09:15:50 -05:00
Kim Alvefur
36a9583069
util.signal: Fail signalfd() if unable to change signal mask
...
By aborting early, the failure should be brought to the attention
somehow.
2024-02-28 22:31:06 +01:00
Kim Alvefur
761643abcc
util.signal: Wrap signalfd in an userdatum for gc handling etc
2024-02-24 01:00:44 +01:00
Kim Alvefur
54f76b97d2
util.signal: Add support for signalfd(2) on Linux
...
signalfd allows handling signal events using the same method as sockets,
via file descriptors. Thus all signal dispatch can go through the same
main event loop as everything else, removing need for thread-scary
signal handling where execution would just jump to the signal handler
regardless of the state of Lua, and needing to keep track of Lua
states/threads.
2024-02-24 00:05:29 +01:00
Matthew Wild
7f748556a2
util.strbitop: Add common_prefix_bits() method
...
This returns the number of bits that two strings have in common. It is
significantly more efficient than similar calculations in Lua.
2024-02-23 12:08:37 +00:00
Kim Alvefur
8a2e65d5b7
util.poll: Rename things to clarify poll(2) limits
...
With epoll(7), MAX_EVENTS controls how many events can be retrieved in one
epoll_wait call, while with poll(2) this MAX_WATCHED controls how many
sockets or other FDs can be watched at once.
2023-11-27 08:19:52 +01:00
Kim Alvefur
da38e2af42
util.poll: Quadruple number of events retrieved at once from epoll
...
Better performance under load maybe?
See b890ceb1c24f for previous increase
2023-11-21 20:45:56 +01:00
Kim Alvefur
c8e2129a82
util.poll: Return early if given zero timeout and no pending events
...
Should have been part of f33887f925e1 to ensure it won't skip processing
timers at all when very busy.
2023-11-21 17:43:46 +01:00
Kim Alvefur
048b064fcd
util.pposix: Add remove_blocks() for deleting parts of files
...
Allows implementing e.g. a FIFO
Will probably only work on some Linux file systems like ext4.
2023-06-07 05:07:03 +02:00
Kim Alvefur
b7b65435f7
util.pposix: Use Lua enum API for resource limit name argument
...
Because diffstat.
2023-06-14 13:39:39 +02:00
Kim Alvefur
8136aa749a
util: Add compat for prosody module name change to C sources
2023-03-17 18:03:07 +01:00
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.
2023-02-10 00:37:05 +01:00
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() {
| ^~~~~~~~~~~~~~
2023-01-31 16:27:55 +01:00
Kim Alvefur
2e44f8260b
util.struct: Fix typo in comment
2023-01-20 18:19:34 +01:00
Kim Alvefur
732d5ad8a8
util.hashes: Silence compiler warning about char pointer signedness
...
Introduced in dbe9781fd278
2023-01-17 15:30:28 +01:00
Matthew Wild
26dc334ae3
util.crypto: Add support for AES-256-CTR
...
This is required by PASETO v3.local
2023-01-13 14:34:10 +00:00
Matthew Wild
341c8417c2
util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
...
These are needed for PASETO v3.local.
2023-01-13 14:29:08 +00:00
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.
2022-09-29 23:15:39 +01:00
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
2022-07-11 17:11:38 +02:00
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()
2022-07-11 17:01:55 +02:00
Matthew Wild
5316b0005e
util.crypto: More digests for sign/verify, use macros for clarity/consistency
2022-07-02 14:59:52 +01:00
Matthew Wild
d7b32f1b71
util.crypto: Friendlier error message on incorrect key types
2022-07-02 11:51:24 +01:00
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)
2022-07-02 11:50:56 +01:00
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.
2022-06-24 16:56:16 +01:00
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.
2022-07-01 15:11:08 +01:00
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.
2022-07-11 20:02:10 +02:00
Kim Alvefur
dff4beae02
util-src: Remove Lua 5.1 compat macros
...
Part of #1600
2022-07-01 21:21:21 +02:00
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.
2022-06-24 16:59:54 +02:00
Kim Alvefur
8f3d837cd2
util.hashes: Remove unused constants
2022-06-24 16:49:03 +02:00
Kim Alvefur
452f9e4e2b
util.hashes: Remove unused struct
...
Unused since 9f1c5ae8d70b
2022-06-24 16:12:11 +02:00
Kim Alvefur
9a96021706
util.hashes: Return OpenSSL error messages on failure
...
With luck, might contain more details than just "failed"
2022-06-24 15:33:04 +02:00
Kim Alvefur
a7567a9055
util.hashes: Add SHA3 bindings
2020-09-10 21:58:24 +02:00
Kim Alvefur
f3d61e3945
util.hashes: Bind BLAKE2 algoritms supported by OpenSSL
2020-09-10 21:58:24 +02:00
Kim Alvefur
9f932f7559
util.hashes: Refactor PBKDF2 to deduplicate code
2020-09-10 21:58:25 +02:00
Kim Alvefur
ae14dc1220
util.hashes: Expose sha224 and sha384 HMAC functions
...
For completeness and consistency with set of plain hash functions
2020-11-29 17:58:45 +01:00
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.
2020-11-29 17:58:30 +01:00
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.
2020-09-10 21:58:23 +02:00
Kim Alvefur
300813b68b
util.crand: Reduce scope here too
...
Same as previous commit
2022-04-23 14:37:43 +02:00
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.
2022-04-23 14:29:43 +02:00
Matthew Wild
ca3d1e1958
util.table: Compatibility with Lua 5.1 lua_equals
2022-03-18 15:29:05 +00:00
Matthew Wild
26605b5197
util.table: Backport table.move() from Lua 5.4
...
One difference is that 5.4 accepts "table-like" values (for this and other
table.*() functions), but that would require additional backporting work.
2022-03-18 15:21:25 +00:00
Kim Alvefur
43351d2b54
Spelling: Fix various spelling mistakes (thanks timeless)
...
Words, sometimes I wonder how they even work
Maybe I missed something.
2022-03-07 00:13:56 +01:00
Kim Alvefur
ffb37f3ef3
make: Fix build of util.struct on *BSD
2022-03-04 17:46:33 +01:00
Matthew Wild
b47c7951d5
Merge config-updates+check-turn from timber
2022-03-04 16:33:41 +00:00
Kim Alvefur
af95bb77e6
util.poll: Add support for the poll() API
...
Might be better than select(), more portable than epoll.
2022-02-23 20:31:03 +01:00
Kim Alvefur
04aa101da3
util.poll: Expose API (epoll or select) used
...
Could he handy to know for debugging or decisions
2022-02-27 14:36:43 +01:00