Skip to content

Commit

Permalink
reviewing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wqx6 committed Nov 16, 2022
1 parent eb794d7 commit 302903d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
24 changes: 14 additions & 10 deletions src/tools/spake2p/Cmd_GenVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ const char * const gCmdOptionHelp =
" -f, --pin-code-file <file>\n"
"\n"
" A file which contains all the PIN codes to generate verifiers.\n"
" Each line in this file should be a valid PIN code.\n"
" Each line in this file should be a valid PIN code. If the row count of this file is less than\n"
" the number of pin-code/verifier parameter sets to be generated, the first few verifier sets will\n"
" be generated using the PIN codes in this file, and the next will use the random PIN codes.\n"
" The following file is a example with 5 PIN codes:\n"
" 1234\n"
" 2345\n"
" 3456\n"
" 4567\n"
" 5678\n"
"\n"
" -i, --iteration-count <int>\n"
"\n"
Expand Down Expand Up @@ -160,11 +168,10 @@ static uint32_t GetNextPinCode()
char pinCodeStr[9] = { 0 };
if (fgets(pinCodeStr, 8, gPinCodeFile) != nullptr)
{
uint32_t pinCode = atoi(pinCodeStr);
if (pinCode == 11111111 || pinCode == 22222222 || pinCode == 33333333 || pinCode == 44444444 || pinCode == 55555555 ||
pinCode == 66666666 || pinCode == 77777777 || pinCode == 88888888 || pinCode == 99999999 || pinCode == 12345678 ||
pinCode == 87654321)
uint32_t pinCode = static_cast<uint32_t>(atoi(pinCodeStr));
if (!chip::SetupPayload::IsValidSetupPIN(pinCode))
{
fprintf(stderr, "The line %s in PIN codes file is invalid, using a random PIN code.\n", pinCodeStr);
return chip::kSetupPINCodeUndefinedValue;
}
return pinCode;
Expand All @@ -185,11 +192,7 @@ bool HandleOption(const char * progName, OptionSet * optSet, int id, const char
break;
case 'p':
// Specifications sections 5.1.1.6 and 5.1.6.1
if (!ParseInt(arg, gPinCode) || (gPinCode > chip::kSetupPINCodeMaximumValue) ||
(gPinCode == chip::kSetupPINCodeUndefinedValue) || (gPinCode == 11111111) || (gPinCode == 22222222) ||
(gPinCode == 33333333) || (gPinCode == 44444444) || (gPinCode == 55555555) || (gPinCode == 66666666) ||
(gPinCode == 77777777) || (gPinCode == 88888888) || (gPinCode == 99999999) || (gPinCode == 12345678) ||
(gPinCode == 87654321))
if (!ParseInt(arg, gPinCode) || (!chip::SetupPayload::IsValidSetupPIN(gPinCode)))
{
PrintArgError("%s: Invalid value specified for pin-code parameter: %s\n", progName, arg);
return false;
Expand Down Expand Up @@ -372,6 +375,7 @@ bool Cmd_GenVerifier(int argc, char * argv[])
return false;
}

// If the file with PIN codes is not provided, the PIN code on next iteration will be randomly generated.
gPinCode = GetNextPinCode();
// On the next iteration the Salt will be randomly generated.
gSaltDecodedLen = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/tools/spake2p/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Example command that generates 100 sets of spake2p parameters (Specific PIN
Codes, random Salts and corresponding Verifiers):

```
./spake2p gen-verifier --count 100 --pin-code-file pincodes.txt --iteration-count 15000 --salt-len 32 --out spake2p-provisioning-data.csv
./spake2p gen-verifier --count 100 --pin-code-file pincodes.csv --iteration-count 15000 --salt-len 32 --out spake2p-provisioning-data.csv
```

Notes: Each line of the `pincodes.txt` should be a valid PIN code.
Notes: Each line of the `pincodes.csv` should be a valid PIN code. You can use
`spake2p --help` to get the example content of the file.

0 comments on commit 302903d

Please sign in to comment.