-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Docs Syncer
committed
Nov 19, 2024
1 parent
6a3bff4
commit 65b9116
Showing
3 changed files
with
397 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# ECDSA384 | ||
|
||
## Overview | ||
|
||
#### License: MIT | ||
|
||
```solidity | ||
library ECDSA384 | ||
``` | ||
|
||
Cryptography module | ||
|
||
This library provides functionality for ECDSA verification over any 384-bit curve. Currently, | ||
this is the most efficient implementation out there, consuming ~9 million gas per call. | ||
|
||
The approach is Strauss-Shamir double scalar multiplication with 4 bits of precompute + projective points. | ||
## Structs info | ||
|
||
### Parameters | ||
|
||
```solidity | ||
struct Parameters { | ||
bytes a; | ||
bytes b; | ||
bytes gx; | ||
bytes gy; | ||
bytes p; | ||
bytes n; | ||
bytes lowSmax; | ||
} | ||
``` | ||
|
||
384-bit curve parameters. | ||
### _Parameters | ||
|
||
```solidity | ||
struct _Parameters { | ||
uint256 a; | ||
uint256 b; | ||
uint256 gx; | ||
uint256 gy; | ||
uint256 p; | ||
uint256 n; | ||
uint256 lowSmax; | ||
} | ||
``` | ||
|
||
|
||
### _Inputs | ||
|
||
```solidity | ||
struct _Inputs { | ||
uint256 r; | ||
uint256 s; | ||
uint256 x; | ||
uint256 y; | ||
} | ||
``` | ||
|
||
|
||
## Functions info | ||
|
||
### verify | ||
|
||
```solidity | ||
function verify( | ||
ECDSA384.Parameters memory curveParams_, | ||
bytes memory hashedMessage_, | ||
bytes memory signature_, | ||
bytes memory pubKey_ | ||
) internal view returns (bool) | ||
``` | ||
|
||
The function to verify the ECDSA signature | ||
|
||
|
||
Parameters: | ||
|
||
| Name | Type | Description | | ||
| :------------- | :------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| curveParams_ | struct ECDSA384.Parameters | the 384-bit curve parameters. `lowSmax` is `n / 2`. | | ||
| hashedMessage_ | bytes | the already hashed message to be verified. | | ||
| signature_ | bytes | the ECDSA signature. Equals to `bytes(r) + bytes(s)`. | | ||
| pubKey_ | bytes | the full public key of a signer. Equals to `bytes(x) + bytes(y)`. Note that signatures only from the lower part of the curve are accepted. If your `s >= n / 2`, change it to `s = n - s`. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# RSASSAPSS | ||
|
||
## Overview | ||
|
||
#### License: MIT | ||
|
||
```solidity | ||
library RSASSAPSS | ||
``` | ||
|
||
Cryptography module | ||
|
||
This library provides functionality to verify RSASSA-PSS signatures with MGF1 mask generation function. | ||
|
||
Users may provide custom hash functions via `Parameters` struct. However, the usage of `sha256` is recommended. | ||
The RSASSA-PSS signature verification costs ~340k gas. | ||
|
||
Learn more about the algorithm [here](https://datatracker.ietf.org/doc/html/rfc3447#section-8.1). | ||
## Structs info | ||
|
||
### Parameters | ||
|
||
```solidity | ||
struct Parameters { | ||
uint256 hashLength; | ||
uint256 saltLength; | ||
function (bytes) pure returns (bytes) hasher; | ||
} | ||
``` | ||
|
||
The RSASSA-PSS parameters. | ||
|
||
|
||
Parameters: | ||
|
||
| Name | Type | Description | | ||
| :--------- | :------------------------------------ | :---------------------------------------------- | | ||
| hashLength | uint256 | the hash function output length in bytes. | | ||
| saltLength | uint256 | the pss encoding salt length in bytes. | | ||
| hasher | function (bytes) pure returns (bytes) | the function-pointer to a custom hash function. | | ||
|
||
## Functions info | ||
|
||
### verifySha256 | ||
|
||
```solidity | ||
function verifySha256( | ||
bytes memory message_, | ||
bytes memory s_, | ||
bytes memory e_, | ||
bytes memory n_ | ||
) internal view returns (bool) | ||
``` | ||
|
||
Same as `verify` but with `sha256` hash function preconfiguration. | ||
### verify | ||
|
||
```solidity | ||
function verify( | ||
RSASSAPSS.Parameters memory params_, | ||
bytes memory message_, | ||
bytes memory s_, | ||
bytes memory e_, | ||
bytes memory n_ | ||
) internal view returns (bool) | ||
``` | ||
|
||
Verifies RSAPSS-SSA signature with custom parameters. | ||
|
||
|
||
Parameters: | ||
|
||
| Name | Type | Description | | ||
| :------- | :-------------------------- | :------------------------------------------------------------------------------------ | | ||
| params_ | struct RSASSAPSS.Parameters | The parameters to specify the hash length, salt length, and hash function of choice. | | ||
| message_ | bytes | The arbitrary message to be verified. | | ||
| s_ | bytes | The "encrypted" signature | | ||
| e_ | bytes | The public key exponent. `65537` is a recommended value. | | ||
| n_ | bytes | The modulus of a public key. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
# U384 | ||
|
||
## Overview | ||
|
||
#### License: MIT | ||
|
||
```solidity | ||
library U384 | ||
``` | ||
|
||
Low-level utility library that implements unsigned 384-bit arithmetics. | ||
|
||
Should not be used outside of this file. | ||
## Functions info | ||
|
||
### init | ||
|
||
```solidity | ||
function init(uint256 from_) internal pure returns (uint256 handler_) | ||
``` | ||
|
||
|
||
### init | ||
|
||
```solidity | ||
function init(bytes memory from_) internal pure returns (uint256 handler_) | ||
``` | ||
|
||
|
||
### init2 | ||
|
||
```solidity | ||
function init2( | ||
bytes memory from2_ | ||
) internal pure returns (uint256 handler1_, uint256 handler2_) | ||
``` | ||
|
||
|
||
### initCall | ||
|
||
```solidity | ||
function initCall(uint256 m_) internal pure returns (uint256 handler_) | ||
``` | ||
|
||
|
||
### copy | ||
|
||
```solidity | ||
function copy(uint256 handler_) internal pure returns (uint256 handlerCopy_) | ||
``` | ||
|
||
|
||
### eq | ||
|
||
```solidity | ||
function eq(uint256 a_, uint256 b_) internal pure returns (bool eq_) | ||
``` | ||
|
||
|
||
### eqInteger | ||
|
||
```solidity | ||
function eqInteger( | ||
uint256 a_, | ||
uint256 bInteger_ | ||
) internal pure returns (bool eq_) | ||
``` | ||
|
||
|
||
### cmp | ||
|
||
```solidity | ||
function cmp(uint256 a_, uint256 b_) internal pure returns (int256 cmp_) | ||
``` | ||
|
||
|
||
### modexp | ||
|
||
```solidity | ||
function modexp( | ||
uint256 call_, | ||
uint256 b_, | ||
uint256 eInteger_ | ||
) internal view returns (uint256 r_) | ||
``` | ||
|
||
|
||
### modexpAssign | ||
|
||
```solidity | ||
function modexpAssign( | ||
uint256 call_, | ||
uint256 b_, | ||
uint256 eInteger_ | ||
) internal view | ||
``` | ||
|
||
|
||
### modexpAssignTo | ||
|
||
```solidity | ||
function modexpAssignTo( | ||
uint256 call_, | ||
uint256 to_, | ||
uint256 b_, | ||
uint256 eInteger_ | ||
) internal view | ||
``` | ||
|
||
|
||
### modadd | ||
|
||
```solidity | ||
function modadd( | ||
uint256 a_, | ||
uint256 b_, | ||
uint256 m_ | ||
) internal pure returns (uint256 r_) | ||
``` | ||
|
||
|
||
### modaddAssign | ||
|
||
```solidity | ||
function modaddAssign(uint256 a_, uint256 b_, uint256 m_) internal pure | ||
``` | ||
|
||
|
||
### modaddAssignTo | ||
|
||
```solidity | ||
function modaddAssignTo( | ||
uint256 to_, | ||
uint256 a_, | ||
uint256 b_, | ||
uint256 m_ | ||
) internal pure | ||
``` | ||
|
||
|
||
### modmul | ||
|
||
```solidity | ||
function modmul( | ||
uint256 call_, | ||
uint256 a_, | ||
uint256 b_ | ||
) internal view returns (uint256 r_) | ||
``` | ||
|
||
|
||
### modmulAssign | ||
|
||
```solidity | ||
function modmulAssign(uint256 call_, uint256 a_, uint256 b_) internal view | ||
``` | ||
|
||
|
||
### modmulAssignTo | ||
|
||
```solidity | ||
function modmulAssignTo( | ||
uint256 call_, | ||
uint256 to_, | ||
uint256 a_, | ||
uint256 b_ | ||
) internal view | ||
``` | ||
|
||
|
||
### sub | ||
|
||
```solidity | ||
function sub(uint256 a_, uint256 b_) internal pure returns (uint256 r_) | ||
``` | ||
|
||
|
||
### subAssignTo | ||
|
||
```solidity | ||
function subAssignTo(uint256 to_, uint256 a_, uint256 b_) internal pure | ||
``` | ||
|
||
|
||
### modshl1Assign | ||
|
||
```solidity | ||
function modshl1Assign(uint256 a_, uint256 m_) internal pure | ||
``` | ||
|
||
|
||
### modshl1AssignTo | ||
|
||
```solidity | ||
function modshl1AssignTo(uint256 to_, uint256 a_, uint256 m_) internal pure | ||
``` | ||
|
||
|
||
### moddiv | ||
|
||
```solidity | ||
function moddiv( | ||
uint256 call_, | ||
uint256 a_, | ||
uint256 b_, | ||
uint256 m_ | ||
) internal view returns (uint256 r_) | ||
``` | ||
|
||
|
||
### modinv | ||
|
||
```solidity | ||
function modinv( | ||
uint256 call_, | ||
uint256 b_, | ||
uint256 m_ | ||
) internal view returns (uint256 r_) | ||
``` | ||
|
||
|
||
### _shl1 | ||
|
||
```solidity | ||
function _shl1(uint256 a_, uint256 r_) internal pure | ||
``` | ||
|
||
|
||
### _shl1To | ||
|
||
```solidity | ||
function _shl1To(uint256 a_) internal pure | ||
``` | ||
|