From a8fe6dd40d024f10eb135464e933b02b7ec3f6d4 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Wed, 13 Dec 2023 14:43:39 -0500 Subject: [PATCH] rev180: Move SM2KeyExchange prototype into header file Signed-off-by: Stefan Berger --- src/tpm2/crypto/CryptEccKeyExchange_fp.h | 24 +++++++++++++++++++ src/tpm2/crypto/openssl/CryptEccKeyExchange.c | 10 -------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/tpm2/crypto/CryptEccKeyExchange_fp.h b/src/tpm2/crypto/CryptEccKeyExchange_fp.h index fd31c3f8..e60dbac4 100644 --- a/src/tpm2/crypto/CryptEccKeyExchange_fp.h +++ b/src/tpm2/crypto/CryptEccKeyExchange_fp.h @@ -83,6 +83,30 @@ LIB_EXPORT TPM_RC CryptEcc2PhaseKeyExchange( TPMS_ECC_POINT* QsB, // IN: static public party B key TPMS_ECC_POINT* QeB // IN: ephemeral public party B key ); +# if ALG_SM2 + +//*** SM2KeyExchange() +// This function performs the key exchange defined in SM2. +// The first step is to compute +// 'tA' = ('dsA' + 'deA' avf(Xe,A)) mod 'n' +// Then, compute the 'Z' value from +// 'outZ' = ('h' 'tA' mod 'n') ('QsA' + [avf('QeB.x')]('QeB')). +// The function will compute the ephemeral public key from the ephemeral +// private key. +// All points are required to be on the curve of 'inQsA'. The function will fail +// catastrophically if this is not the case +// Return Type: TPM_RC +// TPM_RC_NO_RESULT the value for dsA does not give a valid point on the +// curve +LIB_EXPORT TPM_RC SM2KeyExchange( + TPMS_ECC_POINT* outZ, // OUT: the computed point + TPM_ECC_CURVE curveId, // IN: the curve for the computations + TPM2B_ECC_PARAMETER* dsAIn, // IN: static private TPM key + TPM2B_ECC_PARAMETER* deAIn, // IN: ephemeral private TPM key + TPMS_ECC_POINT* QsBIn, // IN: static public party B key + TPMS_ECC_POINT* QeBIn // IN: ephemeral public party B key + ); +# endif #endif // CC_ZGen_2Phase #endif // _CRYPT_ECC_KEY_EXCHANGE_FP_H_ diff --git a/src/tpm2/crypto/openssl/CryptEccKeyExchange.c b/src/tpm2/crypto/openssl/CryptEccKeyExchange.c index 0308415b..63027957 100644 --- a/src/tpm2/crypto/openssl/CryptEccKeyExchange.c +++ b/src/tpm2/crypto/openssl/CryptEccKeyExchange.c @@ -64,16 +64,6 @@ #include "Tpm.h" -LIB_EXPORT TPM_RC -SM2KeyExchange( - TPMS_ECC_POINT *outZ, // OUT: the computed point - TPM_ECC_CURVE curveId, // IN: the curve for the computations - TPM2B_ECC_PARAMETER *dsAIn, // IN: static private TPM key - TPM2B_ECC_PARAMETER *deAIn, // IN: ephemeral private TPM key - TPMS_ECC_POINT *QsBIn, // IN: static public party B key - TPMS_ECC_POINT *QeBIn // IN: ephemeral public party B key - ); - #if CC_ZGen_2Phase == YES //** Functions