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

Investigate Ed25519 Key Format Compatibility between Tendermint and libsodium #2

Closed
torao opened this issue Nov 15, 2019 · 2 comments
Closed
Assignees
Labels
C: enhancement Classification: New feature or its request, or improvement in maintainability of code

Comments

@torao
Copy link
Contributor

torao commented Nov 15, 2019

Tendermint and libsodium generate different keys for 32-bytes fixed zeros seed.

tendermint: private key: 66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925b1c4df1c17cce90a03cd4c057fc74d4e2ee24ddfe2a8c9c5fd8d0a45a1f082f3 (64 bytes)
libsodium : private key: 00000000000000000000000000000000000000000000000000000000000000003b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29 (64 bytes)
tendermint: public key: b1c4df1c17cce90a03cd4c057fc74d4e2ee24ddfe2a8c9c5fd8d0a45a1f082f3 (32 bytes)
libsodium : public key: 3b6a27bcceb6a42d62a3a8d02a6f0d73653215771de243a63ac048a18b59da29 (32 bytes)

Ed25519 is specified in RFC 8032, and its parameters are considered to be compatible. We need to convert them if we use the ED25519 key-pair of Tendermint. If it's not possible, another key must be used for the leader election.

@torao torao added the C: enhancement Classification: New feature or its request, or improvement in maintainability of code label Nov 15, 2019
@torao torao added this to the Evolve Leader Election into VRF milestone Nov 15, 2019
@torao torao self-assigned this Nov 15, 2019
@torao
Copy link
Contributor Author

torao commented Nov 15, 2019

Tendermint and libsodium use the same Ed25519 key-pair format. Both are RFC 8032 compliant.

private key: [ seed (32-bytes) ][ public key (32-bytes) ]
public key : [ public key (32-bytes) ]

The function KeyPairFromSeed(seed) on libsodium uses the given value as a seed directly. On the other hand, ed25519.GenPrivKeyFromSecret(secret) of Tendermint uses the secret with SHA-256 as the seed.

Thus, by using SHA-256 applied secret as libsodium seed,

var secret [SEEDBYTES]byte
tsk := ed25519.GenPrivKeyFromSecret(secret[:])
tpk, _ := tsk.PubKey().(ed25519.PubKeyEd25519)

var seed [SEEDBYTES]byte
hashedSecret := sha256.Sum256(secret[:])
copy(seed[:], hashedSecret[:])
var spk, ssk = KeyPairFromSeed(seed)

I've seen that Tendermint and libsodium generate exactly identical key-pairs.

tendermint: private key: 66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925b1c4df1c17cce90a03cd4c057fc74d4e2ee24ddfe2a8c9c5fd8d0a45a1f082f3 (64 bytes)
libsodium : private key: 66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925b1c4df1c17cce90a03cd4c057fc74d4e2ee24ddfe2a8c9c5fd8d0a45a1f082f3 (64 bytes)
tendermint: public key : b1c4df1c17cce90a03cd4c057fc74d4e2ee24ddfe2a8c9c5fd8d0a45a1f082f3 (32 bytes)
libsodium : public key : b1c4df1c17cce90a03cd4c057fc74d4e2ee24ddfe2a8c9c5fd8d0a45a1f082f3 (32 bytes)

In conclusion, the Ed25519 key-pair of Tendermint and libsodium is binary compatible.

@torao
Copy link
Contributor Author

torao commented Nov 15, 2019

Since the VRF API added in #1 is the same specification as libsodium, we need to change the private and public keys on them to ed25519.PrivKeyEd25519 and ed25519.PubKeyEd25519, respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: enhancement Classification: New feature or its request, or improvement in maintainability of code
Projects
None yet
Development

No branches or pull requests

1 participant