Skip to content

Commit a0992d0

Browse files
authored
improve naming and description of parameters in CHIPCryptoPAL functions (project-chip#36470)
- w0s and w1s are not exactly identical to w0 and w1
1 parent b2ebece commit a0992d0

15 files changed

+60
-59
lines changed

src/crypto/CHIPCryptoPAL.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,16 +330,16 @@ CHIP_ERROR Spake2p::BeginVerifier(const uint8_t * my_identity, size_t my_identit
330330
}
331331

332332
CHIP_ERROR Spake2p::BeginProver(const uint8_t * my_identity, size_t my_identity_len, const uint8_t * peer_identity,
333-
size_t peer_identity_len, const uint8_t * w0in, size_t w0in_len, const uint8_t * w1in,
334-
size_t w1in_len)
333+
size_t peer_identity_len, const uint8_t * w0sin, size_t w0sin_len, const uint8_t * w1sin,
334+
size_t w1sin_len)
335335
{
336336
VerifyOrReturnError(state == CHIP_SPAKE2P_STATE::INIT, CHIP_ERROR_INTERNAL);
337337

338338
ReturnErrorOnFailure(InternalHash(my_identity, my_identity_len));
339339
ReturnErrorOnFailure(InternalHash(peer_identity, peer_identity_len));
340340
ReturnErrorOnFailure(WriteMN());
341-
ReturnErrorOnFailure(FELoad(w0in, w0in_len, w0));
342-
ReturnErrorOnFailure(FELoad(w1in, w1in_len, w1));
341+
ReturnErrorOnFailure(FELoad(w0sin, w0sin_len, w0));
342+
ReturnErrorOnFailure(FELoad(w1sin, w1sin_len, w1));
343343

344344
state = CHIP_SPAKE2P_STATE::STARTED;
345345
role = CHIP_SPAKE2P_ROLE::PROVER;

src/crypto/CHIPCryptoPAL.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,16 +1163,16 @@ class Spake2p
11631163
* @param my_identity_len The prover identity length.
11641164
* @param peer_identity The peer identity. May be NULL if identities are not established.
11651165
* @param peer_identity_len The peer identity length.
1166-
* @param w0in The input w0 (an output from the PBKDF).
1167-
* @param w0in_len The input w0 length.
1168-
* @param w1in The input w1 (an output from the PBKDF).
1169-
* @param w1in_len The input w1 length.
1166+
* @param w0sin The input w0s (an output from the PBKDF).
1167+
* @param w0sin_len The input w0s length.
1168+
* @param w1sin The input w1s (an output from the PBKDF).
1169+
* @param w1sin_len The input w1s length.
11701170
*
11711171
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
11721172
**/
11731173
virtual CHIP_ERROR BeginProver(const uint8_t * my_identity, size_t my_identity_len, const uint8_t * peer_identity,
1174-
size_t peer_identity_len, const uint8_t * w0in, size_t w0in_len, const uint8_t * w1in,
1175-
size_t w1in_len);
1174+
size_t peer_identity_len, const uint8_t * w0sin, size_t w0sin_len, const uint8_t * w1sin,
1175+
size_t w1sin_len);
11761176

11771177
/**
11781178
* @brief Compute the first round of the protocol.
@@ -1347,26 +1347,26 @@ class Spake2p
13471347
/*
13481348
* @synopsis Compute w0sin mod p
13491349
*
1350-
* @param w0out Output field element (modulo p)
1350+
* @param w0out Output field element w0
13511351
* @param w0_len Output field element length
1352-
* @param w1sin Input field element
1353-
* @param w1sin_len Input field element length
1352+
* @param w0sin Input field element
1353+
* @param w0sin_len Input field element length
13541354
*
13551355
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
13561356
**/
13571357
virtual CHIP_ERROR ComputeW0(uint8_t * w0out, size_t * w0_len, const uint8_t * w0sin, size_t w0sin_len) = 0;
13581358

13591359
/*
1360-
* @synopsis Compute w1in*G
1360+
* @synopsis Compute w1in*G where w1in is w1sin mod p
13611361
*
13621362
* @param Lout Output point in 0x04 || X || Y format.
13631363
* @param L_len Output point length
1364-
* @param w1in Input field element
1365-
* @param w1in_len Input field element size
1364+
* @param w1sin Input field element
1365+
* @param w1sin_len Input field element size
13661366
*
13671367
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
13681368
**/
1369-
virtual CHIP_ERROR ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1in, size_t w1in_len) = 0;
1369+
virtual CHIP_ERROR ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1sin, size_t w1sin_len) = 0;
13701370

13711371
void * M;
13721372
void * N;
@@ -1521,7 +1521,7 @@ class Spake2p_P256_SHA256_HKDF_HMAC : public Spake2p
15211521
CHIP_ERROR PointIsValid(void * R) override;
15221522

15231523
CHIP_ERROR ComputeW0(uint8_t * w0out, size_t * w0_len, const uint8_t * w0sin, size_t w0sin_len) override;
1524-
CHIP_ERROR ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1in, size_t w1in_len) override;
1524+
CHIP_ERROR ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1sin, size_t w1sin_len) override;
15251525

15261526
protected:
15271527
CHIP_ERROR InitImpl() override;
@@ -1561,12 +1561,12 @@ class Spake2pVerifier
15611561
CHIP_ERROR Generate(uint32_t pbkdf2IterCount, const ByteSpan & salt, uint32_t setupPin);
15621562

15631563
/**
1564-
* @brief Compute the initiator values (w0, w1) used for PAKE input.
1564+
* @brief Compute the initiator values (w0s, w1s) used for PAKE input.
15651565
*
15661566
* @param pbkdf2IterCount Iteration count for PBKDF2 function
15671567
* @param salt Salt to be used for Spake2+ operation
15681568
* @param setupPin Provided setup PIN (passcode)
1569-
* @param ws The output pair (w0, w1) stored sequentially
1569+
* @param ws The output pair (w0s, w1s) stored sequentially
15701570
* @param ws_len The output length
15711571
*
15721572
* @return CHIP_ERROR The result from running PBKDF2

src/crypto/CHIPCryptoPALOpenSSL.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::PointCofactorMul(void * R)
16081608
return CHIP_NO_ERROR;
16091609
}
16101610

1611-
CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1in, size_t w1in_len)
1611+
CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1sin, size_t w1sin_len)
16121612
{
16131613
CHIP_ERROR error = CHIP_ERROR_INTERNAL;
16141614
int error_openssl = 0;
@@ -1623,8 +1623,8 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_le
16231623
Lout_point = EC_POINT_new(context->curve);
16241624
VerifyOrExit(Lout_point != nullptr, error = CHIP_ERROR_INTERNAL);
16251625

1626-
VerifyOrExit(CanCastTo<boringssl_size_t_openssl_int>(w1in_len), error = CHIP_ERROR_INTERNAL);
1627-
BN_bin2bn(Uint8::to_const_uchar(w1in), static_cast<boringssl_size_t_openssl_int>(w1in_len), w1_bn);
1626+
VerifyOrExit(CanCastTo<boringssl_size_t_openssl_int>(w1sin_len), error = CHIP_ERROR_INTERNAL);
1627+
BN_bin2bn(Uint8::to_const_uchar(w1sin), static_cast<boringssl_size_t_openssl_int>(w1sin_len), w1_bn);
16281628
error_openssl = BN_mod(w1_bn, w1_bn, (BIGNUM *) order, context->bn_ctx);
16291629
VerifyOrExit(error_openssl == 1, error = CHIP_ERROR_INTERNAL);
16301630

src/crypto/CHIPCryptoPALPSA.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::PointCofactorMul(void * R)
10421042
return CHIP_NO_ERROR;
10431043
}
10441044

1045-
CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1in, size_t w1in_len)
1045+
CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1sin, size_t w1sin_len)
10461046
{
10471047
CHIP_ERROR error = CHIP_NO_ERROR;
10481048
int result = 0;
@@ -1058,7 +1058,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_le
10581058
result = mbedtls_ecp_group_load(&curve, MBEDTLS_ECP_DP_SECP256R1);
10591059
VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL);
10601060

1061-
result = mbedtls_mpi_read_binary(&w1_bn, Uint8::to_const_uchar(w1in), w1in_len);
1061+
result = mbedtls_mpi_read_binary(&w1_bn, Uint8::to_const_uchar(w1sin), w1sin_len);
10621062
VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL);
10631063

10641064
result = mbedtls_mpi_mod_mpi(&w1_bn, &w1_bn, &curve.N);

src/crypto/CHIPCryptoPALmbedTLS.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::PointCofactorMul(void * R)
10921092
return CHIP_NO_ERROR;
10931093
}
10941094

1095-
CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1in, size_t w1in_len)
1095+
CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1sin, size_t w1sin_len)
10961096
{
10971097
CHIP_ERROR error = CHIP_NO_ERROR;
10981098
int result = 0;
@@ -1108,7 +1108,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_le
11081108
result = mbedtls_ecp_group_load(&curve, MBEDTLS_ECP_DP_SECP256R1);
11091109
VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL);
11101110

1111-
result = mbedtls_mpi_read_binary(&w1_bn, Uint8::to_const_uchar(w1in), w1in_len);
1111+
result = mbedtls_mpi_read_binary(&w1_bn, Uint8::to_const_uchar(w1sin), w1sin_len);
11121112
VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL);
11131113

11141114
result = mbedtls_mpi_mod_mpi(&w1_bn, &w1_bn, &curve.N);

src/crypto/PSASpake2p.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ CHIP_ERROR PSASpake2p_P256_SHA256_HKDF_HMAC::BeginVerifier(const uint8_t * my_id
9494

9595
CHIP_ERROR PSASpake2p_P256_SHA256_HKDF_HMAC::BeginProver(const uint8_t * my_identity, size_t my_identity_len,
9696
const uint8_t * peer_identity, size_t peer_identity_len,
97-
const uint8_t * w0in, size_t w0in_len, const uint8_t * w1in,
98-
size_t w1in_len)
97+
const uint8_t * w0sin, size_t w0sin_len, const uint8_t * w1sin,
98+
size_t w1sin_len)
9999
{
100-
VerifyOrReturnError(w0in_len <= kSpake2p_WS_Length, CHIP_ERROR_INVALID_ARGUMENT);
101-
VerifyOrReturnError(w1in_len <= kSpake2p_WS_Length, CHIP_ERROR_INVALID_ARGUMENT);
100+
VerifyOrReturnError(w0sin_len <= kSpake2p_WS_Length, CHIP_ERROR_INVALID_ARGUMENT);
101+
VerifyOrReturnError(w1sin_len <= kSpake2p_WS_Length, CHIP_ERROR_INVALID_ARGUMENT);
102102

103103
uint8_t password[kSpake2p_WS_Length * 2];
104104
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -107,13 +107,13 @@ CHIP_ERROR PSASpake2p_P256_SHA256_HKDF_HMAC::BeginProver(const uint8_t * my_iden
107107
psa_pake_cs_set_algorithm(&cp, PSA_ALG_SPAKE2P_MATTER);
108108
psa_pake_cs_set_primitive(&cp, PSA_PAKE_PRIMITIVE(PSA_PAKE_PRIMITIVE_TYPE_ECC, PSA_ECC_FAMILY_SECP_R1, 256));
109109

110-
memcpy(password + 0, w0in, w0in_len);
111-
memcpy(password + w0in_len, w1in, w1in_len);
110+
memcpy(password + 0, w0sin, w0sin_len);
111+
memcpy(password + w0sin_len, w1sin, w1sin_len);
112112
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
113113
psa_set_key_algorithm(&attributes, PSA_ALG_SPAKE2P_MATTER);
114114
psa_set_key_type(&attributes, PSA_KEY_TYPE_SPAKE2P_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1));
115115

116-
psa_status_t status = psa_import_key(&attributes, password, w0in_len + w1in_len, &mKey);
116+
psa_status_t status = psa_import_key(&attributes, password, w0sin_len + w1sin_len, &mKey);
117117

118118
psa_reset_key_attributes(&attributes);
119119
VerifyOrReturnError(status == PSA_SUCCESS, CHIP_ERROR_INTERNAL);

src/crypto/PSASpake2p.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,16 @@ class PSASpake2p_P256_SHA256_HKDF_HMAC
8989
* @param my_identity_len The prover identity length.
9090
* @param peer_identity The peer identity. May be NULL if identities are not established.
9191
* @param peer_identity_len The peer identity length.
92-
* @param w0in The input w0 (an output from the PBKDF).
93-
* @param w0in_len The input w0 length.
94-
* @param w1in The input w1 (an output from the PBKDF).
95-
* @param w1in_len The input w1 length.
92+
* @param w0sin The input w0s (an output from the PBKDF).
93+
* @param w0sin_len The input w0s length.
94+
* @param w1sin The input w1s (an output from the PBKDF).
95+
* @param w1sin_len The input w1s length.
9696
*
9797
* @return Returns a CHIP_ERROR on error, CHIP_NO_ERROR otherwise
9898
**/
9999
CHIP_ERROR BeginProver(const uint8_t * my_identity, size_t my_identity_len, const uint8_t * peer_identity,
100-
size_t peer_identity_len, const uint8_t * w0in, size_t w0in_len, const uint8_t * w1in, size_t w1in_len);
100+
size_t peer_identity_len, const uint8_t * w0sin, size_t w0sin_len, const uint8_t * w1sin,
101+
size_t w1sin_len);
101102

102103
/**
103104
* @brief Compute the first round of the protocol.

src/platform/Infineon/crypto/trustm/CHIPCryptoPALHost.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::PointCofactorMul(void * R)
838838
return CHIP_NO_ERROR;
839839
}
840840

841-
CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1in, size_t w1in_len)
841+
CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1sin, size_t w1sin_len)
842842
{
843843
CHIP_ERROR error = CHIP_NO_ERROR;
844844
int result = 0;
@@ -854,7 +854,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_le
854854
result = mbedtls_ecp_group_load(&curve, MBEDTLS_ECP_DP_SECP256R1);
855855
VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL);
856856

857-
result = mbedtls_mpi_read_binary(&w1_bn, Uint8::to_const_uchar(w1in), w1in_len);
857+
result = mbedtls_mpi_read_binary(&w1_bn, Uint8::to_const_uchar(w1sin), w1sin_len);
858858
VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL);
859859

860860
result = mbedtls_mpi_mod_mpi(&w1_bn, &w1_bn, &curve.N);

src/platform/nxp/common/crypto/CHIPCryptoPALTinyCrypt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::PointCofactorMul(void * R)
10511051
return CHIP_NO_ERROR;
10521052
}
10531053

1054-
CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1in, size_t w1in_len)
1054+
CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1sin, size_t w1sin_len)
10551055
{
10561056
CHIP_ERROR error = CHIP_NO_ERROR;
10571057
int result = 0;
@@ -1061,7 +1061,7 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_le
10611061
uECC_word_t w1_bn[NUM_ECC_WORDS];
10621062
uECC_word_t L_tmp[2 * NUM_ECC_WORDS];
10631063

1064-
uECC_vli_bytesToNative(tmp, w1in, NUM_ECC_BYTES);
1064+
uECC_vli_bytesToNative(tmp, w1sin, NUM_ECC_BYTES);
10651065

10661066
uECC_vli_mmod(w1_bn, tmp, curve_n);
10671067

src/platform/nxp/common/crypto/CHIPCryptoPalS200.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,13 +1138,13 @@ CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::PointCofactorMul(void * R)
11381138
return CHIP_NO_ERROR;
11391139
}
11401140

1141-
CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1in, size_t w1in_len)
1141+
CHIP_ERROR Spake2p_P256_SHA256_HKDF_HMAC::ComputeL(uint8_t * Lout, size_t * L_len, const uint8_t * w1sin, size_t w1sin_len)
11421142
{
11431143
secEcp256Status_t result;
11441144
ecp256Point_t gen_point;
11451145
uint32_t W1[SEC_ECP256_COORDINATE_WLEN];
11461146

1147-
result = ECP256_ModularReductionN(W1, w1in, w1in_len);
1147+
result = ECP256_ModularReductionN(W1, w1sin, w1sin_len);
11481148
VerifyOrReturnError(result == gSecEcp256Success_c, CHIP_ERROR_INTERNAL);
11491149

11501150
result = ECP256_GeneratePublicKey((uint8_t *) &gen_point, (uint8_t *) &W1, NULL);

0 commit comments

Comments
 (0)