forked from Proxmox/proxmox
b926ea1f5c
previously we only used asymmetric cryptographic schemes to authenticate tickets. this is fairly costly and not necessary in every instance. imagine a service that runs as a single daemon. this daemon is then the only party that needs to sign and verify tickets. this makes hmac perfectly suitable for such usecases. hmac has some advantages over asymmetric schemes: - much simpler and well reviewed construction - much faster and better optimized crypto primitives (hash functions) this commit first introduces a new hmac key wrapper that uses openssl's hmac implementation and can easily be reused by other parts of the code. it also refactors the keyring code to make it easier to rotate new hmac keys into place so switching to hmac keys is easier. hmac keys are symmetric, so the verification key is the same key as the signing key. this breaks the previous assumption by the keyring that these correspond to public and private keys. thus, this commit introduces two wrapper enums to distinguish between hmac and asymmetric signature schemes. the verification of hmac keys is also done via `openssl::memcmp::eq()` to avoid potential timing side-channel attacks. below are some simple benchmarks done with criterion.rs to show how much faster hmac is, no matter the actual hash function: rsa 4096 + sha256 time: [2.7825 ms 2.7907 ms 2.7995 ms] ed25519 time: [94.411 µs 94.840 µs 95.324 µs] hmac sha256 time: [5.7202 µs 5.7412 µs 5.7645 µs] hmac sha384 time: [6.6577 µs 6.6780 µs 6.7006 µs] hmac sha3_256 time: [5.6930 µs 5.7114 µs 5.7322 µs] rsa with 4096 bit keys and a sha256 digest is our current default. the test itself consists of a single sign + verification cycle. criterion repeats this test as it sees fit to arrive at the above numbers. Signed-off-by: Stefan Sterz <s.sterz@proxmox.com> |
||
---|---|---|
.. | ||
debian | ||
examples | ||
src | ||
Cargo.toml |