libtpmtss: Get TPM 2.0 capabilities
This commit is contained in:
@@ -8,7 +8,8 @@ ipseclib_LTLIBRARIES = libtpmtss.la
|
||||
libtpmtss_la_SOURCES = \
|
||||
tpm_tss.h tpm_tss.c \
|
||||
tpm_tss_trousers.h tpm_tss_trousers.c \
|
||||
tpm_tss_tss2.h tpm_tss_tss2.c
|
||||
tpm_tss_tss2.h tpm_tss_tss2.c \
|
||||
tpm_tss_tss2_names.h tpm_tss_tss2_names.c
|
||||
|
||||
libtpmtss_la_LIBADD = \
|
||||
$(top_builddir)/src/libstrongswan/libstrongswan.la
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "tpm_tss_tss2.h"
|
||||
#include "tpm_tss_tss2_names.h"
|
||||
|
||||
#ifdef TSS_TSS2
|
||||
|
||||
@@ -60,6 +61,74 @@ int TpmClientPrintf (uint8_t type, const char *format, ...)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of supported algorithms
|
||||
*/
|
||||
static bool get_algs_capability(private_tpm_tss_tss2_t *this)
|
||||
{
|
||||
TPMS_CAPABILITY_DATA cap_data;
|
||||
TPMI_YES_NO more_data;
|
||||
uint32_t rval, i;
|
||||
size_t len = BUF_LEN;
|
||||
char buf[BUF_LEN];
|
||||
char *pos = buf;
|
||||
int written;
|
||||
|
||||
/* get supported algorithms */
|
||||
rval = Tss2_Sys_GetCapability(this->sys_context, 0, TPM_CAP_ALGS,
|
||||
0, TPM_PT_ALGORITHM_SET, &more_data, &cap_data, 0);
|
||||
if (rval != TPM_RC_SUCCESS)
|
||||
{
|
||||
DBG1(DBG_PTS, "%s GetCapability failed for TPM_CAP_ALGS: 0x%06x",
|
||||
LABEL, rval);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* print supported algorithms */
|
||||
for (i = 0; i < cap_data.data.algorithms.count; i++)
|
||||
{
|
||||
written = snprintf(pos, len, " %N", tpm_alg_id_names,
|
||||
cap_data.data.algorithms.algProperties[i].alg);
|
||||
if (written < 0 || written >= len)
|
||||
{
|
||||
break;
|
||||
}
|
||||
pos += written;
|
||||
len -= written;
|
||||
}
|
||||
DBG2(DBG_PTS, "%s algorithms:%s", LABEL, buf);
|
||||
|
||||
/* get supported ECC curves */
|
||||
rval = Tss2_Sys_GetCapability(this->sys_context, 0, TPM_CAP_ECC_CURVES,
|
||||
0, TPM_PT_LOADED_CURVES, &more_data, &cap_data, 0);
|
||||
if (rval != TPM_RC_SUCCESS)
|
||||
{
|
||||
DBG1(DBG_PTS, "%s GetCapability failed for TPM_ECC_CURVES: 0x%06x",
|
||||
LABEL, rval);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* reset print buffer */
|
||||
pos = buf;
|
||||
len = BUF_LEN;
|
||||
|
||||
/* print supported ECC curves */
|
||||
for (i = 0; i < cap_data.data.eccCurves.count; i++)
|
||||
{
|
||||
written = snprintf(pos, len, " %N", tpm_ecc_curve_names,
|
||||
cap_data.data.eccCurves.eccCurves[i]);
|
||||
if (written < 0 || written >= len)
|
||||
{
|
||||
break;
|
||||
}
|
||||
pos += written;
|
||||
len -= written;
|
||||
}
|
||||
DBG2(DBG_PTS, "%s ECC curves:%s", LABEL, buf);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize TSS context
|
||||
*/
|
||||
@@ -116,7 +185,9 @@ static bool initialize_context(private_tpm_tss_tss2_t *this)
|
||||
LABEL, rval);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
/* get a list of supported algorithms and ECC curves */
|
||||
return get_algs_capability(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Andreas Steffen
|
||||
* HSR Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include "tpm_tss_tss2_names.h"
|
||||
|
||||
#ifdef TSS_TSS2
|
||||
|
||||
#include <tss2/tpm20.h>
|
||||
|
||||
#ifndef TPM_ALG_ECMQV
|
||||
#define TPM_ALG_ECMQV (TPM_ALG_ID)0x001D
|
||||
#endif
|
||||
|
||||
#ifndef TPM_ALG_CAMELLIA
|
||||
#define TPM_ALG_CAMELLIA (TPM_ALG_ID)0x0026
|
||||
#endif
|
||||
|
||||
/**
|
||||
* TPM 2.0 algorithm ID names
|
||||
*/
|
||||
ENUM_BEGIN(tpm_alg_id_names, TPM_ALG_ERROR, TPM_ALG_RSA,
|
||||
"ERROR",
|
||||
"RSA"
|
||||
);
|
||||
ENUM_NEXT(tpm_alg_id_names, TPM_ALG_SHA1, TPM_ALG_KEYEDHASH, TPM_ALG_RSA,
|
||||
"SHA1",
|
||||
"HMAC",
|
||||
"AES",
|
||||
"MGF1",
|
||||
"KEYEDHASH"
|
||||
);
|
||||
ENUM_NEXT(tpm_alg_id_names, TPM_ALG_XOR, TPM_ALG_SHA512, TPM_ALG_KEYEDHASH,
|
||||
"XOR",
|
||||
"SHA256",
|
||||
"SHA384",
|
||||
"SHA512"
|
||||
);
|
||||
ENUM_NEXT(tpm_alg_id_names, TPM_ALG_NULL, TPM_ALG_NULL, TPM_ALG_SHA512,
|
||||
"NULL"
|
||||
);
|
||||
ENUM_NEXT(tpm_alg_id_names, TPM_ALG_SM3_256, TPM_ALG_ECMQV, TPM_ALG_NULL,
|
||||
"SM3_256",
|
||||
"SM4",
|
||||
"RSASSA",
|
||||
"RSAES",
|
||||
"RSAPSS",
|
||||
"OAEP",
|
||||
"ECDSA",
|
||||
"ECDH",
|
||||
"SM2",
|
||||
"ECSCHNORR",
|
||||
"ECMQV"
|
||||
);
|
||||
ENUM_NEXT(tpm_alg_id_names, TPM_ALG_KDF1_SP800_56A, TPM_ALG_ECC, TPM_ALG_ECMQV,
|
||||
"KDF1_SP800_56A",
|
||||
"KDF2",
|
||||
"KDF1_SP800_108",
|
||||
"ECC"
|
||||
);
|
||||
ENUM_NEXT(tpm_alg_id_names, TPM_ALG_SYMCIPHER, TPM_ALG_CAMELLIA, TPM_ALG_ECC,
|
||||
"SYMCIPHER",
|
||||
"CAMELLIA"
|
||||
);
|
||||
ENUM_NEXT(tpm_alg_id_names, TPM_ALG_CTR, TPM_ALG_ECB, TPM_ALG_CAMELLIA,
|
||||
"CTR",
|
||||
"OFB",
|
||||
"CBC",
|
||||
"CFB",
|
||||
"ECB"
|
||||
);
|
||||
ENUM_END(tpm_alg_id_names, TPM_ALG_ECB);
|
||||
|
||||
/**
|
||||
* TPM 2.0 ECC curve names
|
||||
*/
|
||||
ENUM_BEGIN(tpm_ecc_curve_names, TPM_ECC_NONE, TPM_ECC_NIST_P521,
|
||||
"NONE",
|
||||
"NIST_P192",
|
||||
"NIST_P224",
|
||||
"NIST_P256",
|
||||
"NIST_P384",
|
||||
"NIST_P521"
|
||||
);
|
||||
ENUM_NEXT(tpm_ecc_curve_names, TPM_ECC_BN_P256, TPM_ECC_BN_P638, TPM_ECC_NIST_P521,
|
||||
"BN_P256",
|
||||
"BN_P638"
|
||||
);
|
||||
ENUM_NEXT(tpm_ecc_curve_names, TPM_ECC_SM2_P256, TPM_ECC_SM2_P256, TPM_ECC_BN_P638,
|
||||
"SM2_P256"
|
||||
);
|
||||
ENUM_END(tpm_ecc_curve_names, TPM_ECC_SM2_P256);
|
||||
|
||||
#else /* TSS_TSS2 */
|
||||
|
||||
/**
|
||||
* TPM 2.0 algorithm ID names
|
||||
*/
|
||||
ENUM(tpm_alg_id_names, 0, 0,
|
||||
"ERROR"
|
||||
);
|
||||
|
||||
/**
|
||||
* TPM 2.0 ECC curve names
|
||||
*/
|
||||
ENUM(tpm_ecc_curve_names, 0, 0,
|
||||
"NONE"
|
||||
);
|
||||
|
||||
#endif /* TSS_TSS2 */
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Andreas Steffen
|
||||
* HSR Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup tpm_tss_tss_names tpm_tss_tss_names
|
||||
* @{ @ingroup libtpmtss
|
||||
*/
|
||||
|
||||
#ifndef TPM_TSS_TSS2_NAMES_H_
|
||||
#define TPM_TSS_TSS2_NAMES_H_
|
||||
|
||||
#include <library.h>
|
||||
|
||||
extern enum_name_t *tpm_alg_id_names;
|
||||
|
||||
extern enum_name_t *tpm_ecc_curve_names;
|
||||
|
||||
#endif /** TPM_TSS_TSS2_NAMES_H_ @}*/
|
||||
Reference in New Issue
Block a user