Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing BrainPool and Curve25519 algorithms #2897

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/tss2/tss2_tpm2_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ typedef UINT16 TPM2_ECC_CURVE;
#define TPM2_ECC_BN_P256 ((TPM2_ECC_CURVE) 0x0010)
#define TPM2_ECC_BN_P638 ((TPM2_ECC_CURVE) 0x0011)
#define TPM2_ECC_SM2_P256 ((TPM2_ECC_CURVE) 0x0020)
#define TPM_ECC_BP_P256_R1 ((TPM2_ECC_CURVE) 0x0030)
#define TPM_ECC_BP_P384_R1 ((TPM2_ECC_CURVE) 0x0031)
#define TPM_ECC_BP_P512_R1 ((TPM2_ECC_CURVE) 0x0032)
#define TPM_ECC_CURVE_25519 ((TPM2_ECC_CURVE) 0x0040)

/* From TPM 2.0 Part 2: Definition of TPM2_CC Constants */
typedef UINT32 TPM2_CC;
Expand Down
18 changes: 18 additions & 0 deletions src/tss2-esys/esys_crypto_ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,24 @@ iesys_cryptossl_get_ecdh_point(TPM2B_PUBLIC *key,
curveId = NID_sm2;
key_size = 32;
break;
#endif
#ifdef NID_brainpoolP256r1
case TPM_ECC_BP_P256_R1:
curveId = NID_brainpoolP256r1;
key_size = 32;
break;
#endif
#ifdef NID_brainpoolP384r1
case TPM_ECC_BP_P384_R1:
curveId = NID_brainpoolP384r1;
key_size = 48;
break;
#endif
#ifdef NID_brainpoolP512r1
case TPM_ECC_BP_P512_R1:
curveId = NID_brainpoolP512r1;
key_size = 64;
break;
#endif
default:
return_error(TSS2_ESYS_RC_NOT_IMPLEMENTED,
Expand Down
15 changes: 15 additions & 0 deletions src/tss2-fapi/fapi_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,21 @@ ossl_ecc_pub_from_tpm(const TPM2B_PUBLIC *tpmPublicKey, EVP_PKEY **evpPublicKey)
case TPM2_ECC_SM2_P256:
curveId = NID_sm2;
break;
#endif
#ifdef NID_brainpoolP256r1
case TPM_ECC_BP_P256_R1:
curveId = NID_brainpoolP256r1;
break;
#endif
#ifdef NID_brainpoolP384r1
case TPM_ECC_BP_P384_R1:
curveId = NID_brainpoolP384r1;
break;
#endif
#ifdef NID_brainpoolP512r1
case TPM_ECC_BP_P512_R1:
curveId = NID_brainpoolP512r1;
break;
#endif
default:
return_error(TSS2_FAPI_RC_BAD_VALUE,
Expand Down
7 changes: 6 additions & 1 deletion src/tss2-fapi/tpm_json_deserialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,10 @@ ifapi_json_TPM2_ECC_CURVE_deserialize(json_object *jso, TPM2_ECC_CURVE *out)
{ TPM2_ECC_BN_P256, "BN_P256" },
{ TPM2_ECC_BN_P638, "BN_P638" },
{ TPM2_ECC_SM2_P256, "SM2_P256" },
{ TPM_ECC_BP_P256_R1, "BP_P256_R1" },
{ TPM_ECC_BP_P384_R1, "BP_P384_R1" },
{ TPM_ECC_BP_P512_R1, "BP_P512_R1" },
{ TPM_ECC_CURVE_25519, "CURVE_25519"},
};

const char *s = json_object_get_string(jso);
Expand Down Expand Up @@ -3721,7 +3725,8 @@ ifapi_json_TPMI_ECC_CURVE_deserialize(json_object *jso, TPMI_ECC_CURVE *out)
SUBTYPE_FILTER(TPMI_ECC_CURVE, TPM2_ECC_CURVE,
TPM2_ECC_NONE, TPM2_ECC_NIST_P192, TPM2_ECC_NIST_P224, TPM2_ECC_NIST_P256,
TPM2_ECC_NIST_P384, TPM2_ECC_NIST_P521, TPM2_ECC_BN_P256, TPM2_ECC_BN_P638,
TPM2_ECC_SM2_P256);
TPM2_ECC_SM2_P256, TPM_ECC_BP_P256_R1, TPM_ECC_BP_P384_R1, TPM_ECC_BP_P512_R1,
TPM_ECC_CURVE_25519);
}

static char *field_TPMT_ECC_SCHEME_tab[] = {
Expand Down
4 changes: 4 additions & 0 deletions src/tss2-fapi/tpm_json_serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ ifapi_json_TPM2_ECC_CURVE_serialize(const TPM2_ECC_CURVE in, json_object **jso)
{ TPM2_ECC_BN_P256, "BN_P256" },
{ TPM2_ECC_BN_P638, "BN_P638" },
{ TPM2_ECC_SM2_P256, "SM2_P256" },
{ TPM_ECC_BP_P256_R1, "BP_P256_R1" },
{ TPM_ECC_BP_P384_R1, "BP_P384_R1" },
{ TPM_ECC_BP_P512_R1, "BP_P512_R1" },
{ TPM_ECC_CURVE_25519, "CURVE_25519"},
};

for (size_t i = 0; i < sizeof(tab) / sizeof(tab[0]); i++) {
Expand Down