Skip to content

Commit

Permalink
Move SCL Linked Lib to Embedded
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzel98 committed Dec 19, 2024
1 parent 22630d6 commit f494ee1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libraries/P256SCLVerifierLib.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT AND Apache-2.0
pragma solidity 0.8.23;

import { SCL_RIP7212 } from "@SCL/lib/libSCL_RIP7212.sol";
import { SCL_RIP7212 } from "./libSCL_RIP7212.sol";
import { ec_isOnCurve } from "@SCL/elliptic/SCL_ecOncurve.sol";
import { a, b, p, n } from "@SCL/fields/SCL_secp256r1.sol";

Expand Down
52 changes: 52 additions & 0 deletions src/libraries/libSCL_RIP7212.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
*
*/
/*
/* ╔═╗╔╦╗╔═╗╔═╗╔╦╗╦ ╦ ╔═╗╦═╗╦ ╦╔═╗╔╦╗╔═╗╦ ╦╔╗
/* ╚═╗║║║║ ║║ ║ ║ ╠═╣ ║ ╠╦╝╚╦╝╠═╝ ║ ║ ║║ ║╠╩╗
/* ╚═╝╩ ╩╚═╝╚═╝o╩ ╩ ╩ ╚═╝╩╚═ ╩ ╩ ╩ ╚═╝╩═╝╩╚═╝
/*
/* Copyright (C) 2024 - Renaud Dubois - This file is part of SCL (Smoo.th CryptoLib) project
/* License: This software is licensed under MIT License (and allways will)
/* Description: This file implements the ecdsa verification protocol using Shamir's trick + 4bit windowing.
/********************************************************************************************/
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19 <0.9.0;

import { a, b, p, gx, gy, n } from "@SCL/fields/SCL_secp256r1.sol";

//import modular inversion over prime field defined over curve subgroup of prime order
import { nModInv } from "@SCL/modular/SCL_modular.sol";
//import point on curve checking
import { ec_isOnCurve } from "@SCL/elliptic/SCL_ecOncurve.sol";
//import point double multiplication and accumulation (RIP7696)
import "@SCL/elliptic/SCL_mulmuladdX_fullgenW.sol";

library SCL_RIP7212 {
function verify(bytes32 message, uint256 r, uint256 s, uint256 qx, uint256 qy) internal view returns (bool) {
// check the validity of the signature
if (r == 0 || r >= n || s == 0 || s >= n) {
return false;
}

// check the public key validity (rejecting not on curve and weak keys)
if (ec_isOnCurve(p, a, b, qx, qy) == false) {
return false;
}

// calculate the scalars used for the multiplication of the point
uint256 sInv = nModInv(s);
uint256 scalar_u = mulmod(uint256(message), sInv, n);
uint256 scalar_v = mulmod(r, sInv, n);
uint256[6] memory Qpa = [qx, qy, p, a, gx, gy];

uint256 x1;
(x1,) = ecGenMulmuladdB4W(Qpa, scalar_u, scalar_v);

assembly {
x1 := addmod(x1, sub(n, r), n)
}

return x1 == 0;
}
}

0 comments on commit f494ee1

Please sign in to comment.