Salt was added in v253. We are not checking whether it was actually found
(non-zero size), so when an old tpm+pin enrollment is opened things go boom.
For good measure, check both the buffer and the size in both places.
Assertion 'saltlen > 0' failed at src/shared/tpm2-util.c:2490, function tpm2_util_pbkdf2_hmac_sha256(). Aborting.
_cleanup_(erase_and_freep) char *b64_salted_pin = NULL;
int r;
+ assert(salt || salt_size == 0);
assert(ret_decrypted_key);
assert(ret_decrypted_key_size);
if ((flags & TPM2_FLAGS_USE_PIN) && salt && !pin)
return -ENOANO;
- if (pin) {
+ if (pin && salt_size > 0) {
uint8_t salted_pin[SHA256_DIGEST_SIZE] = {};
CLEANUP_ERASE(salted_pin);
r = tpm2_util_pbkdf2_hmac_sha256(pin, strlen(pin), salt, salt_size, salted_pin);
const void *blob;
int r;
+ assert(salt || salt_size == 0);
+
if (!device) {
r = tpm2_find_device_auto(LOG_DEBUG, &auto_device);
if (r == -ENODEV)
if (r < 0)
return r;
- if (salt) {
+ if (salt_size > 0) {
uint8_t salted_pin[SHA256_DIGEST_SIZE] = {};
CLEANUP_ERASE(salted_pin);
*/
static const uint8_t block_cnt[] = { 0, 0, 0, 1 };
+ assert (salt);
assert (saltlen > 0);
assert (saltlen <= (SIZE_MAX - sizeof(block_cnt)));
assert (passlen > 0);