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

为 ed25519 更换实现 #285

Merged
merged 8 commits into from
Mar 19, 2025
Merged

为 ed25519 更换实现 #285

merged 8 commits into from
Mar 19, 2025

Conversation

ForteScarlet
Copy link
Member

@ForteScarlet ForteScarlet commented Mar 19, 2025

参考 #284 , 目前使用的 libsodium bindings 在 JVM 平台表现不佳。由于它通过JNA绑定libsodium链库,而库文件储存在 resources 中,这会导致两个问题:

  1. 依赖包体积会比较大。
  2. 不适合将应用打包为 fatjar, 例如 SpringBoot fatjar, 可能会导致找不到目标资源文件(资源读取的逻辑是依赖库内部的,没有提供覆盖接口或外部传入的接口)

因此,现在分离出一个内部使用的模块 simbot-component-qq-guild-internal-ed25519 并将 ed25519 的实现多平台化:

非 JVM 平台中,均使用 libsodium bindings 作为实现。

JVM 平台中,优先尝试检测是否存在以下类:

  • org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters
  • org.bouncycastle.crypto.params.Ed25519PublicKeyParameters
  • org.bouncycastle.crypto.signers.Ed25519Signer

如果存在,则使用这些类进行签名操作,也就是使用 BouncyCastle (编译时使用的是 org.bouncycastle:bcprov-jdk18on:1.80) 进行密钥的生成或签名/验签。

如果 BouncyCastle 的相关类不存在,则使用 ed25519-java 作为实现库。此库默认作为 implementation 加载于 classpath 中。
相比于 BouncyCastle (≈8,480 KB ≈8.48 MB),它轻量得多 (≈62 KB)。

resolve #284

Verified

This commit was signed with the committer’s verified signature.
ForteScarlet ForteScarlet

Verified

This commit was signed with the committer’s verified signature.
ForteScarlet ForteScarlet

Verified

This commit was signed with the committer’s verified signature.
ForteScarlet ForteScarlet

Verified

This commit was signed with the committer’s verified signature.
ForteScarlet ForteScarlet

Verified

This commit was signed with the committer’s verified signature.
ForteScarlet ForteScarlet

Verified

This commit was signed with the committer’s verified signature.
ForteScarlet ForteScarlet
@ForteScarlet ForteScarlet enabled auto-merge March 19, 2025 16:46
@ForteScarlet ForteScarlet self-assigned this Mar 19, 2025

Verified

This commit was signed with the committer’s verified signature.
ForteScarlet ForteScarlet

Verified

This commit was signed with the committer’s verified signature.
ForteScarlet ForteScarlet
@ForteScarlet ForteScarlet merged commit 48f519b into dev/main Mar 19, 2025
3 of 4 checks passed
@ForteScarlet ForteScarlet deleted the dev/improve-ed25519 branch March 19, 2025 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ed25519的多平台库 kotlin-multiplatform-libsodium 在 JVM 上表现不佳
1 participant