Why Does My Go ed25519 Public Key Differ From the Expected BEP Data?

Patricia Arquette
Release: 2024-10-31 07:23:29
Original
964 people have browsed it

Why Does My Go ed25519 Public Key Differ From the Expected BEP Data?

Generating Public Key Matching BEP for ed25519 Key

Problem:
Using the Go crypto/ed25519 package, the generated public key differs from the expected one provided in a test case using the BEP data.

Cause:
Differing private key formats exist for ed25519. The BEP data uses a 64-byte hashed private key, while the Go package uses a 32-byte hashed private key (prefixed by the 32-byte seed).

Solution:
While it's not possible to convert the BEP private keys to the Go format, a modified version of the Go library can be created to handle the hashed private keys used in the BEP.

Code Modification:

The modified code includes the following functions:

  1. getPublicKey: Generates the public key from a 64-byte hashed private key.
  2. sign: Computes the signature using the hashed private key, public key, and message.
<code class="go">func getPublicKey(privateKey []byte) []byte {
    // ... (extraction of 32-byte hash from 64-byte hashed private key and publicKey generation) ...
}

func sign(privateKey, publicKey, message []byte) []byte {
    // ... (extraction of 32-byte hash from 64-byte hashed private key and signature computation) ...
}</code>
Copy after login

Usage:

With this modified code, the test case can be run, demonstrating that the generated public key and signature match the expected BEP data:

<code class="go">// Using the modified code...

fmt.Printf("Calculated key: %x\n", publicKey)
fmt.Printf("Expected key:   %s\n", expectedPublicKey)
keyMatches := expectedPublicKey == hex.EncodeToString(publicKey)
fmt.Printf("Public key matches expected: %v\n", keyMatches)

// Similarly, check for signature match</code>
Copy after login

The above is the detailed content of Why Does My Go ed25519 Public Key Differ From the Expected BEP Data?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!