Skip to content

Commit

Permalink
Merge pull request #48 from 5afe/feature/split-pubkey-into-two-variables
Browse files Browse the repository at this point in the history
Accept elementary types for Q
  • Loading branch information
rdubois-crypto authored Dec 18, 2023
2 parents d5823e5 + 5d3c3f7 commit 999dbd3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 14 additions & 1 deletion solidity/src/FCL_Webauthn.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,27 @@ library FCL_WebAuthn {
uint256 clientChallengeDataOffset,
uint256[2] calldata rs,
uint256[2] calldata Q
) internal view returns (bool) {
return checkSignature(authenticatorData, authenticatorDataFlagMask, clientData, clientChallenge, clientChallengeDataOffset, rs, Q[0], Q[1]);
}

function checkSignature (
bytes calldata authenticatorData,
bytes1 authenticatorDataFlagMask,
bytes calldata clientData,
bytes32 clientChallenge,
uint256 clientChallengeDataOffset,
uint256[2] calldata rs,
uint256 Qx,
uint256 Qy
) internal view returns (bool) {
// Let the caller check if User Presence (0x01) or User Verification (0x04) are set

bytes32 message = FCL_WebAuthn.WebAuthn_format(
authenticatorData, authenticatorDataFlagMask, clientData, clientChallenge, clientChallengeDataOffset, rs
);

bool result = FCL_ecdsa_utils.ecdsa_verify(message, rs, Q);
bool result = FCL_ecdsa_utils.ecdsa_verify(message, rs, Qx, Qy);

return result;
}
Expand Down
8 changes: 5 additions & 3 deletions solidity/src/FCL_ecdsa_utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ library FCL_ecdsa_utils {
* @dev ECDSA verification, given , signature, and public key.
*/

function ecdsa_verify(bytes32 message, uint256[2] calldata rs, uint256[2] calldata Q) internal view returns (bool) {
function ecdsa_verify(bytes32 message, uint256[2] calldata rs, uint256 Qx, uint256 Qy) internal view returns (bool) {
uint256 r = rs[0];
uint256 s = rs[1];
if (r == 0 || r >= FCL_Elliptic_ZZ.n || s == 0 || s >= FCL_Elliptic_ZZ.n) {
return false;
}
uint256 Qx = Q[0];
uint256 Qy = Q[1];
if (!FCL_Elliptic_ZZ.ecAff_isOnCurve(Qx, Qy)) {
return false;
}
Expand All @@ -60,6 +58,10 @@ library FCL_ecdsa_utils {
return x1 == 0;
}

function ecdsa_verify(bytes32 message, uint256[2] calldata rs, uint256[2] calldata Q) internal view returns (bool) {
return ecdsa_verify(message, rs, Q[0], Q[1]);
}

function ec_recover_r1(uint256 h, uint256 v, uint256 r, uint256 s) internal view returns (address)
{
if (r == 0 || r >= FCL_Elliptic_ZZ.n || s == 0 || s >= FCL_Elliptic_ZZ.n) {
Expand Down

0 comments on commit 999dbd3

Please sign in to comment.