integrity: Fix integrity_key_size for algorithms without keys

INTEGRITY_key_size returns -EINVAL for algorithms without a key
and because crypt_params_integrity.integrity_key_size is an
unsigned integer we get key size 4294967274 instead of more
appropriate 0 for these algorithms.
This commit is contained in:
Vojtech Trefny
2022-05-22 19:53:57 +02:00
parent 5d9e362553
commit 6c73057156
2 changed files with 6 additions and 3 deletions

View File

@@ -5245,13 +5245,15 @@ const char *crypt_get_integrity(struct crypt_device *cd)
/* INTERNAL only */
int crypt_get_integrity_key_size(struct crypt_device *cd)
{
int key_size = 0;
if (isINTEGRITY(cd->type))
return INTEGRITY_key_size(crypt_get_integrity(cd));
key_size = INTEGRITY_key_size(crypt_get_integrity(cd));
if (isLUKS2(cd->type))
return INTEGRITY_key_size(crypt_get_integrity(cd));
key_size = INTEGRITY_key_size(crypt_get_integrity(cd));
return 0;
return key_size > 0 ? key_size : 0;
}
/* INTERNAL only */

View File

@@ -2007,6 +2007,7 @@ static void IntegrityTest(void)
EQ_(ip.interleave_sectors, params.interleave_sectors);
EQ_(ip.journal_size, params.journal_size);
EQ_(ip.journal_watermark, params.journal_watermark);
EQ_(ip.integrity_key_size, 0);
OK_(strcmp(ip.integrity,params.integrity));
FAIL_(crypt_set_uuid(cd,DEVICE_1_UUID),"can't set uuid to integrity device");
CRYPT_FREE(cd);