tpm2-software / tpm2-tss

OSS implementation of the TCG TPM2 Software Stack (TSS2)
https://tpm2-software.github.io
BSD 2-Clause "Simplified" License
733 stars 360 forks source link

tss2_tpm2_types.h could be a lot more useful #1567

Closed hughsie closed 4 years ago

hughsie commented 4 years ago

I'm using tss2 in my project (fwupd, a daemon for installing firmware) and we have two unfortunate helpers that I think should be provided by the base tss2 library:

const char *
_alg_id_to_string (TPM2_ALG_ID hash_kind)
{
    if (hash_kind == TPM2_ALG_SHA1)
        return "SHA1";
    if (hash_kind == TPM2_ALG_SHA256)
        return "SHA256";
    if (hash_kind == TPM2_ALG_SHA384)
        return "SHA384";
    if (hash_kind == TPM2_ALG_SHA512)
        return "SHA512";
    return NULL;
}

and:

uint32_t
_alg_id_get_size (TPM2_ALG_ID hash_kind)
{
    if (hash_kind == TPM2_ALG_SHA1)
        return TPM2_SHA1_DIGEST_SIZE;
    if (hash_kind == TPM2_ALG_SHA256)
        return TPM2_SHA256_DIGEST_SIZE;
    if (hash_kind == TPM2_ALG_SHA384)
        return TPM2_SHA384_DIGEST_SIZE;
    if (hash_kind == TPM2_ALG_SHA512)
        return TPM2_SHA512_DIGEST_SIZE;
    return 0;
}

If this is provided and I'm just being blind, please let me know. Thanks for all your work on this, tss2 is pretty great so far for me.

tstruk commented 4 years ago

If this is provided and I'm just being blind, please let me know. Thanks for all your work on this, tss2 is pretty great so far for me.

No, tss2 doesn't provide these helpers. It only provides what is required by the TCG spec: https://trustedcomputinggroup.org/wp-content/uploads/TSS_SAPI_v1p1_r29_pub_20190806.pdf

If we were to add these to tss2, then the spec would need to be updated also.

hughsie commented 4 years ago

No, tss2 doesn't provide these helpers

Could it? It seems like the sort of useful thing that every user of tss2 must be hand-rolling themselves. Something like tss2_helper.h or tss2_common.h would work.

tstruk commented 4 years ago

Yes, we are open to improvements. If you could submit patches all the better.

AndreasFuchsTPM commented 4 years ago

Ok, added to #1587 where we should start collecting everything we want for a tpm2tss_utils.h Closing this one here...