Skip to content

Commit 9aff835

Browse files
bzbarsky-appleadbridge
authored andcommitted
Stop passing passcode by mutable reference to Spake2pVerifier::Generate. (project-chip#23571)
The generation bits never modify the passcode. Fixes project-chip#23511
1 parent ccbfb4a commit 9aff835

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/crypto/CHIPCryptoPAL.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ CHIP_ERROR Spake2pVerifier::Deserialize(const ByteSpan & inSerialized)
540540
return CHIP_NO_ERROR;
541541
}
542542

543-
CHIP_ERROR Spake2pVerifier::Generate(uint32_t pbkdf2IterCount, const ByteSpan & salt, uint32_t & setupPin)
543+
CHIP_ERROR Spake2pVerifier::Generate(uint32_t pbkdf2IterCount, const ByteSpan & salt, uint32_t setupPin)
544544
{
545545
uint8_t serializedWS[kSpake2p_WS_Length * 2] = { 0 };
546546
ReturnErrorOnFailure(ComputeWS(pbkdf2IterCount, salt, setupPin, serializedWS, sizeof(serializedWS)));
@@ -572,7 +572,7 @@ CHIP_ERROR Spake2pVerifier::Generate(uint32_t pbkdf2IterCount, const ByteSpan &
572572
return err;
573573
}
574574

575-
CHIP_ERROR Spake2pVerifier::ComputeWS(uint32_t pbkdf2IterCount, const ByteSpan & salt, uint32_t & setupPin, uint8_t * ws,
575+
CHIP_ERROR Spake2pVerifier::ComputeWS(uint32_t pbkdf2IterCount, const ByteSpan & salt, uint32_t setupPin, uint8_t * ws,
576576
uint32_t ws_len)
577577
{
578578
#ifdef ENABLE_HSM_PBKDF2

src/crypto/CHIPCryptoPAL.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ class Spake2pVerifier
13511351
*
13521352
* @return CHIP_ERROR The result of Spake2+ verifier generation
13531353
*/
1354-
CHIP_ERROR Generate(uint32_t pbkdf2IterCount, const ByteSpan & salt, uint32_t & setupPin);
1354+
CHIP_ERROR Generate(uint32_t pbkdf2IterCount, const ByteSpan & salt, uint32_t setupPin);
13551355

13561356
/**
13571357
* @brief Compute the initiator values (w0, w1) used for PAKE input.
@@ -1364,8 +1364,7 @@ class Spake2pVerifier
13641364
*
13651365
* @return CHIP_ERROR The result from running PBKDF2
13661366
*/
1367-
static CHIP_ERROR ComputeWS(uint32_t pbkdf2IterCount, const ByteSpan & salt, uint32_t & setupPin, uint8_t * ws,
1368-
uint32_t ws_len);
1367+
static CHIP_ERROR ComputeWS(uint32_t pbkdf2IterCount, const ByteSpan & salt, uint32_t setupPin, uint8_t * ws, uint32_t ws_len);
13691368
};
13701369

13711370
/**

src/darwin/Framework/CHIP/MTRDeviceController.mm

+1-3
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,8 @@ + (nullable NSData *)computePASEVerifierForSetupPasscode:(NSNumber *)setupPassco
567567
salt:(NSData *)salt
568568
error:(NSError * __autoreleasing *)error
569569
{
570-
// Spake2pVerifier::Generate takes the passcode by non-const reference for some reason.
571-
uint32_t unboxedSetupPasscode = [setupPasscode unsignedIntValue];
572570
chip::Spake2pVerifier verifier;
573-
CHIP_ERROR err = verifier.Generate([iterations unsignedIntValue], AsByteSpan(salt), unboxedSetupPasscode);
571+
CHIP_ERROR err = verifier.Generate(iterations.unsignedIntValue, AsByteSpan(salt), setupPasscode.unsignedIntValue);
574572
if ([MTRDeviceController checkForError:err logMsg:kErrorSpake2pVerifierGenerationFailed error:error]) {
575573
return nil;
576574
}

0 commit comments

Comments
 (0)