Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/secp384r1 #17

Merged
merged 46 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fa7ab7a
init stack & big int
dovgopoly Oct 7, 2024
e2e6a24
fix
dovgopoly Oct 7, 2024
21d1128
basic impl
dovgopoly Oct 9, 2024
8771120
adjustments
dovgopoly Oct 9, 2024
cadc8ba
fix
dovgopoly Oct 9, 2024
7f3b3bd
refactored & sub
dovgopoly Oct 10, 2024
4713981
added mul
dovgopoly Oct 10, 2024
da287d6
added moddiv modinv
dovgopoly Oct 11, 2024
e134fb7
typos
dovgopoly Oct 11, 2024
1978065
fix
dovgopoly Oct 14, 2024
4b8ef37
bigint - optimized
joYyHack Oct 15, 2024
d57b712
weird stuff
dovgopoly Oct 15, 2024
da3551b
fix mload
Arvolear Oct 15, 2024
a2a11ba
17mil 10 iterations
Arvolear Oct 16, 2024
1e99c60
Quick adjustment
joYyHack Oct 17, 2024
6590533
added u384
dovgopoly Oct 17, 2024
10d729e
Add test
joYyHack Oct 17, 2024
ed82a56
all its
dovgopoly Oct 17, 2024
cc56be3
26.8kk 512 its!!!!!
dovgopoly Oct 18, 2024
cd41bad
44kk 768 its!
dovgopoly Oct 18, 2024
6e69530
512 its 70kk right answers!!!
dovgopoly Oct 18, 2024
0fd14e5
added eq fns
dovgopoly Oct 18, 2024
4ab2585
38.1kk
Arvolear Oct 18, 2024
5f502b5
38kk
Arvolear Oct 18, 2024
3283496
34.8kk shl1
dovgopoly Oct 18, 2024
be13993
32.9kk
dovgopoly Oct 19, 2024
615edbd
ez 26.5kk can be even less if using references
dovgopoly Oct 20, 2024
cf9f8f9
24kk readable
dovgopoly Oct 21, 2024
f5996a2
23kk
dovgopoly Oct 21, 2024
d3952e5
21.6kk
Arvolear Oct 21, 2024
201bd0a
small
Arvolear Oct 21, 2024
dd8cf9f
21.38kk
dovgopoly Oct 21, 2024
21a0d1a
Merge branch 'master' into feat/big-shit
dovgopoly Oct 24, 2024
fadd67a
cleaned up repo
dovgopoly Oct 24, 2024
612fb4c
rm stack mock
dovgopoly Oct 24, 2024
52d7961
fixes
dovgopoly Oct 24, 2024
736fe2b
fix
dovgopoly Oct 24, 2024
3c836ec
fixed test
dovgopoly Oct 25, 2024
e73908a
mv ecdsa to certificates
dovgopoly Oct 25, 2024
444483e
cleaned up
dovgopoly Oct 25, 2024
2c6862c
rm logs
dovgopoly Oct 25, 2024
e2ddb16
cleaned up cfg
dovgopoly Oct 25, 2024
c636f5f
rollback changes
dovgopoly Oct 25, 2024
1d3b485
rm bn lib ts
dovgopoly Oct 28, 2024
34c24c3
added ecdsa dispatcher
dovgopoly Oct 29, 2024
47a9f2f
pretty
Arvolear Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
# Changelog

## [0.1.1]

* A handful of new algorithms are now supported. New constants have been added:
1. **Certificate dispatchers**

```solidity
C_RSA_SHA1_4096 = keccak256("C_RSA_SHA1_4096");
C_RSA_SHA1_2048 = keccak256("C_RSA_SHA1_2048");
C_RSAPSS_SHA2_2048 = keccak256("C_RSAPSS_SHA2_2048");
C_RSAPSS_SHA2_4096 = keccak256("C_RSAPSS_SHA2_4096");
C_RSAPSS_SHA512_2048 = keccak256("C_RSAPSS_SHA512_2048");
C_RSAPSS_SHA512_4096 = keccak256("C_RSAPSS_SHA512_4096");
C_ECDSA_SECP384R1_SHA2_512 = keccak256("C_ECDSA_SECP384R1_SHA2_512");
```

2. **Passport dispatchers**

```solidity
P_RSA_SHA2_2688 = keccak256("P_RSA_SHA2_2688");
P_RSA_SHA2_2688_3 = keccak256("P_RSA_SHA2_2688_3");
```

3. **Passport verifiers**

```solidity
// Per Passport
Z_PER_PASSPORT_1_256_3_5_576_248_NA = keccak256("Z_PER_PASSPORT_1_256_3_5_576_248_NA");
Z_PER_PASSPORT_1_256_3_6_576_248_1_2432_5_296 = keccak256("Z_PER_PASSPORT_1_256_3_6_576_248_1_2432_5_296");
Z_PER_PASSPORT_2_256_3_6_336_264_21_2448_6_2008 = keccak256("Z_PER_PASSPORT_2_256_3_6_336_264_21_2448_6_2008");
Z_PER_PASSPORT_21_256_3_7_336_264_21_3072_6_2008 = keccak256("Z_PER_PASSPORT_21_256_3_7_336_264_21_3072_6_2008");
Z_PER_PASSPORT_1_256_3_6_576_264_1_2448_3_256 = keccak256("Z_PER_PASSPORT_1_256_3_6_576_264_1_2448_3_256");
Z_PER_PASSPORT_2_256_3_6_336_248_1_2432_3_256 = keccak256("Z_PER_PASSPORT_2_256_3_6_336_248_1_2432_3_256");
Z_PER_PASSPORT_2_256_3_6_576_248_1_2432_3_256 = keccak256("Z_PER_PASSPORT_2_256_3_6_576_248_1_2432_3_256");
Z_PER_PASSPORT_11_256_3_3_576_248_1_1184_5_264 = keccak256("Z_PER_PASSPORT_11_256_3_3_576_248_1_1184_5_264");
Z_PER_PASSPORT_12_256_3_3_336_232_NA = keccak256("Z_PER_PASSPORT_12_256_3_3_336_232_NA");
Z_PER_PASSPORT_1_256_3_4_336_232_1_1480_5_296 = keccak256("Z_PER_PASSPORT_1_256_3_4_336_232_1_1480_5_296");
Z_PER_PASSPORT_1_256_3_4_600_248_1_1496_3_256 = keccak256("Z_PER_PASSPORT_1_256_3_4_600_248_1_1496_3_256");

// Universal
Z_UNIVERSAL_2048_V2 = keccak256("Z_UNIVERSAL_2048_V2");
Z_UNIVERSAL_PSS_2048_S32_E2 = keccak256("Z_UNIVERSAL_PSS_2048_S32_E2");
Z_UNIVERSAL_PSS_2048_S32_E17 = keccak256("Z_UNIVERSAL_PSS_2048_S32_E17");
Z_UNIVERSAL_PSS_2048_S64_E17 = keccak256("Z_UNIVERSAL_PSS_2048_S64_E17");

// Georgia
Z_INTERNAL_OPT = keccak256("Z_INTERNAL_OPT");

// Montenegro
Z_MNE_OPT = keccak256("Z_MNE_OPT");
Z_MNE_OPT_2 = keccak256("Z_MNE_OPT_2");
```

## [0.1.0]

* Changed `StateKeeper` interface to always accept passport public keys together with passport hashes. Previously if a passport didn't have AA, a passport public key would be treated as a passport hash. Now these are separate variables where a passport public key may be zero.
Expand Down
24 changes: 24 additions & 0 deletions contracts/certificate/dispatchers/CECDSADispatcher.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

import {AbstractCDispatcher} from "./abstract/AbstractCDispatcher.sol";

import {Bytes2Poseidon} from "../../utils/Bytes2Poseidon.sol";

contract CECDSADispatcher is AbstractCDispatcher {
using Bytes2Poseidon for bytes;

function __CECDSADispatcher_init(
address signer_,
uint256 keyByteLength_,
bytes calldata keyCheckPrefix_
) external initializer {
__AbstractCDispatcher_init(signer_, keyByteLength_, keyCheckPrefix_);
}

function getCertificateKey(
bytes memory certificatePublicKey_
) external pure override returns (uint256 keyHash_) {
return certificatePublicKey_.hash512();
}
}
63 changes: 3 additions & 60 deletions contracts/certificate/dispatchers/CRSADispatcher.sol
Original file line number Diff line number Diff line change
@@ -1,78 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

import {PoseidonUnit5L} from "@iden3/contracts/lib/Poseidon.sol";

import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

import {ICertificateDispatcher} from "../../interfaces/dispatchers/ICertificateDispatcher.sol";
import {ICertificateRSASigner} from "../../interfaces/signers/ICertificateRSASigner.sol";
import {AbstractCDispatcher} from "./abstract/AbstractCDispatcher.sol";

import {Bytes2Poseidon} from "../../utils/Bytes2Poseidon.sol";
import {RSA} from "../../utils/RSA.sol";
import {X509} from "../../utils/X509.sol";

contract CRSADispatcher is ICertificateDispatcher, Initializable {
contract CRSADispatcher is AbstractCDispatcher {
using Bytes2Poseidon for bytes;
using X509 for bytes;
using RSA for bytes;

uint256 public keyByteLength;
bytes public keyCheckPrefix;

address public signer;

function __CRSADispatcher_init(
address signer_,
uint256 keyByteLength_,
bytes calldata keyCheckPrefix_
) external initializer {
signer = signer_;
keyByteLength = keyByteLength_;
keyCheckPrefix = keyCheckPrefix_;
}

/**
* @notice Verifies the ICAO master signature over certificate's signed attributes
*/
function verifyICAOSignature(
bytes memory x509SignedAttributes_,
bytes memory icaoMemberSignature_,
bytes memory icaoMemberKey_
) external view override returns (bool) {
return
ICertificateRSASigner(signer).verifyICAOSignature(
x509SignedAttributes_,
icaoMemberSignature_,
icaoMemberKey_
);
}

/**
* @notice Extracts the certificate's expiration timestamp from its signed attributes
*/
function getCertificateExpirationTimestamp(
bytes memory x509SignedAttributes_,
uint256 byteOffset_
) external pure override returns (uint256) {
return x509SignedAttributes_.extractExpirationTimestamp(byteOffset_);
}

/**
* @notice Extracts the certificate's public key from its signed attributes
*/
function getCertificatePublicKey(
bytes memory x509SignedAttributes_,
uint256 byteOffset_
) external view override returns (bytes memory) {
return x509SignedAttributes_.extractPublicKey(keyCheckPrefix, byteOffset_, keyByteLength);
__AbstractCDispatcher_init(signer_, keyByteLength_, keyCheckPrefix_);
}

/**
* @notice Poseidon5 hash of the `x509KeyByteLength` long RSA X509 key.
*
* See X509 library for more information
*/
function getCertificateKey(
bytes memory certificatePublicKey_
) external pure override returns (uint256 keyHash_) {
Expand Down
73 changes: 73 additions & 0 deletions contracts/certificate/dispatchers/abstract/AbstractCDispatcher.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

import {ICertificateDispatcher} from "../../../interfaces/dispatchers/ICertificateDispatcher.sol";
import {ICertificateSigner} from "../../../interfaces/signers/ICertificateSigner.sol";

import {X509} from "../../../utils/X509.sol";

abstract contract AbstractCDispatcher is ICertificateDispatcher, Initializable {
using X509 for bytes;

uint256 public keyByteLength;
bytes public keyCheckPrefix;

address public signer;

function __AbstractCDispatcher_init(
address signer_,
uint256 keyByteLength_,
bytes calldata keyCheckPrefix_
) internal onlyInitializing {
signer = signer_;
keyByteLength = keyByteLength_;
keyCheckPrefix = keyCheckPrefix_;
}

/**
* @notice Verifies the ICAO master signature over certificate's signed attributes
*/
function verifyICAOSignature(
bytes memory x509SignedAttributes_,
bytes memory icaoMemberSignature_,
bytes memory icaoMemberKey_
) external view override returns (bool) {
return
ICertificateSigner(signer).verifyICAOSignature(
x509SignedAttributes_,
icaoMemberSignature_,
icaoMemberKey_
);
}

/**
* @notice Extracts the certificate's expiration timestamp from its signed attributes
*/
function getCertificateExpirationTimestamp(
bytes memory x509SignedAttributes_,
uint256 byteOffset_
) external pure override returns (uint256) {
return x509SignedAttributes_.extractExpirationTimestamp(byteOffset_);
}

/**
* @notice Extracts the certificate's public key from its signed attributes
*/
function getCertificatePublicKey(
bytes memory x509SignedAttributes_,
uint256 byteOffset_
) external view override returns (bytes memory) {
return x509SignedAttributes_.extractPublicKey(keyCheckPrefix, byteOffset_, keyByteLength);
}

/**
* @notice Poseidon5 hash of the `x509KeyByteLength` long RSA X509 key.
*
* See X509 library for more information
*/
function getCertificateKey(
bytes memory certificatePublicKey_
) external pure virtual override returns (uint256 keyHash_);
}
Loading
Loading