-
Notifications
You must be signed in to change notification settings - Fork 16
feat: upgrade crypto from bcrypto to noble #197
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
Closed
Closed
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
d533fd8
fix: filter multiaddr in nodeAddresstostring
acolytec3 ee9f1c2
Clarify comments
acolytec3 5a9c9df
lint
acolytec3 6544378
Merge remote-tracking branch 'origin/master'
acolytec3 9952262
partial migration to noble/libp2p-crypto
acolytec3 c4f7e26
switch from libp2p aes to noble hashes
acolytec3 69c0020
More incomplete changes
acolytec3 338643e
More fixes
acolytec3 98d16b1
switch sign from async to sync
acolytec3 a2e6c1e
Remove async nonsense
acolytec3 d5a8102
Requested fixes
acolytec3 4dc5620
set correct opts on secp256k1.sign
acolytec3 d9ff963
Fix nodeId hashing
acolytec3 7f70f8d
Buffer constructor clean-up
acolytec3 37f6d62
remove redundant async logic
acolytec3 7624bf8
fix v4 signature
acolytec3 1c925d6
Remove redundant asyncs
acolytec3 5cc64ac
Remove even more redundant async logic
acolytec3 0098fac
Make handleIncoming an arrow function again
acolytec3 19b0721
Fix decodeHeader
acolytec3 9c9fee6
Remove redundant async logic
acolytec3 855277b
restore arrow function
acolytec3 bb2e797
Remove bcrypto and dgram deps
acolytec3 89e1a45
Remove redundant Uint8Array conversions
acolytec3 5d24880
Use buffer.from view
acolytec3 aaec0e8
lint fixes
acolytec3 384adb5
add lint:fix script :-)
acolytec3 af5c232
Make linter happy
acolytec3 f4572f4
consolidate secp in crypto utility
acolytec3 66c1753
Use crypto instead of noble re-export
acolytec3 ad5c5df
Fix aes cipher mode
acolytec3 1035bfd
add benchmark script
acolytec3 612a76d
Add more complete crypto benchmark suite
acolytec3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
import { itBench } from "@dapplion/benchmark"; | ||
import { expect } from "chai"; | ||
import { randomBytes } from "crypto"; | ||
import { | ||
decryptMessage, | ||
encryptMessage, | ||
createKeypair, | ||
KeypairType, | ||
idSign, | ||
idVerify, | ||
v4, | ||
Secp256k1Keypair, | ||
deriveKey, | ||
generateIdSignatureInput, | ||
} from "../../lib/index.js"; | ||
import { hash } from "../../lib/enr/v4.js"; | ||
|
||
itBench("benchmark aes cipher encryption/decryptions", () => { | ||
const key = Buffer.from(randomBytes(16)); | ||
const nonce = Buffer.from(randomBytes(12)); | ||
const msg = Buffer.from(randomBytes(16)); | ||
const ad = Buffer.from(randomBytes(16)); | ||
|
||
const cipher = encryptMessage(key, nonce, msg, ad); | ||
const decrypted = decryptMessage(key, nonce, cipher, ad); | ||
expect(decrypted).to.deep.equal(msg); | ||
}); | ||
|
||
itBench("benchmark sign/verify", () => { | ||
const expected = Buffer.from( | ||
"94852a1e2318c4e5e9d422c98eaf19d1d90d876b29cd06ca7cb7546d0fff7b484fe86c09a064fe72bdbef73ba8e9c34df0cd2b53e9d65528c2c7f336d5dfc6e6", | ||
"hex" | ||
); | ||
|
||
const localSK = Buffer.from("fb757dc581730490a1d7a00deea65e9b1936924caaea8f44d476014856b68736", "hex"); | ||
const challengeData = Buffer.from( | ||
"000000000000000000000000000000006469736376350001010102030405060708090a0b0c00180102030405060708090a0b0c0d0e0f100000000000000000", | ||
"hex" | ||
); | ||
const ephemPK = Buffer.from("039961e4c2356d61bedb83052c115d311acb3a96f5777296dcf297351130266231", "hex"); | ||
const nodeIdB = "bbbb9d047f0488c0b5a93c1c3f2d8bafc7c8ff337024a55434a0d0555de64db9"; | ||
const keypair = createKeypair(KeypairType.Secp256k1, localSK); | ||
const actual = idSign(keypair, challengeData, ephemPK, nodeIdB); | ||
expect(actual).to.deep.equal(expected); | ||
expect( | ||
idVerify( | ||
createKeypair(KeypairType.Secp256k1, undefined, v4.publicKey(localSK)), | ||
challengeData, | ||
ephemPK, | ||
nodeIdB, | ||
actual | ||
) | ||
).to.be.true; | ||
}); | ||
|
||
itBench("benchmark key derivation", () => { | ||
const secret = Buffer.from("022c82f214eb37159111712add00040fcdf73fd4d7d0b7c0f980da4d099aa59ba4"); | ||
const firstNodeId = "aaaa8419e9f49d0083561b48287df592939a8d19947d8c0ef88f2a4856a69fbb"; | ||
const secondNodeId = "bbbb9d047f0488c0b5a93c1c3f2d8bafc7c8ff337024a55434a0d0555de64db9"; | ||
const challengeData = Buffer.from( | ||
"000000000000000000000000000000006469736376350001010102030405060708090a0b0c00180102030405060708090a0b0c0d0e0f100000000000000000", | ||
"hex" | ||
); | ||
|
||
deriveKey(Buffer.from(secret), firstNodeId, secondNodeId, challengeData); | ||
}); | ||
|
||
itBench("benchmark secp256k1.generatePrivateKey", () => { | ||
Secp256k1Keypair.generate(); | ||
}); | ||
|
||
itBench("benchmark keccak hash", () => { | ||
hash(Buffer.from("secret message")); | ||
}); | ||
|
||
itBench("benchmark sha256 hash", () => { | ||
const challengeData = Buffer.from( | ||
"000000000000000000000000000000006469736376350001010102030405060708090a0b0c00180102030405060708090a0b0c0d0e0f100000000000000000", | ||
"hex" | ||
); | ||
const ephemPK = Buffer.from("039961e4c2356d61bedb83052c115d311acb3a96f5777296dcf297351130266231", "hex"); | ||
const nodeId = "bbbb9d047f0488c0b5a93c1c3f2d8bafc7c8ff337024a55434a0d0555de64db9"; | ||
generateIdSignatureInput(challengeData, ephemPK, nodeId); | ||
}) |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.