| 1 | // Package ed25519 implements Tor/BitTorrent-like ed25519 keys. |
| 2 | // |
| 3 | // See the following stack overflow post for details on why |
| 4 | // golang.org/x/crypto/ed25519 can't be used: |
| 5 | // https://stackoverflow.com/questions/44810708/ed25519-public-result-is-different |
| 6 | package ed25519scip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/ |
| 7 | |
| 8 | import ( |
| 9 | "cryptoscip-go gomod github.com/golang/go/src go1.15 crypto/" |
| 10 | "crypto/randscip-go gomod github.com/golang/go/src go1.15 `crypto/rand`/" |
| 11 | "crypto/sha512scip-go gomod github.com/golang/go/src go1.15 `crypto/sha512`/" |
| 12 | "errorsscip-go gomod github.com/golang/go/src go1.15 errors/" |
| 13 | "ioscip-go gomod github.com/golang/go/src go1.15 io/" |
| 14 | |
| 15 | "github.com/cretz/bine/torutil/ed25519/internal/edwards25519scip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/" |
| 16 | "golang.org/x/crypto/ed25519scip-go gomod golang.org/x/crypto c07d793c2f9a `golang.org/x/crypto/ed25519`/" |
| 17 | ) |
| 18 | |
| 19 | const ( |
| 20 | // PublicKeySize is the size, in bytes, of public keys as used in this package. |
| 21 | PublicKeySizescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKeySize. = 32 |
| 22 | // PrivateKeySize is the size, in bytes, of private keys as used in this package. |
| 23 | PrivateKeySizescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKeySize. = 64 |
| 24 | // SignatureSize is the size, in bytes, of signatures generated and verified by this package. |
| 25 | SignatureSizescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/SignatureSize. = 64 |
| 26 | ) |
| 27 | |
| 28 | // PrivateKey is a 64-byte Ed25519 private key. Unlike |
| 29 | // golang.org/x/crypto/ed25519, this is just the digest and does not contain |
| 30 | // the public key within it. Instead call PublicKey() or better, call KeyPair() |
| 31 | // which stores the precomputed public key. |
| 32 | type PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey# []byte |
| 33 | |
| 34 | // PublicKey is a 32-byte Ed25519 public key. |
| 35 | type PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKey# []byte |
| 36 | |
| 37 | // FromCryptoPrivateKey converts a Go private key to the one in this package. |
| 38 | func FromCryptoPrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/FromCryptoPrivateKey().(key ed25519scip-go gomod golang.org/x/crypto c07d793c2f9a `golang.org/x/crypto/ed25519`/.PrivateKeyscip-go gomod golang.org/x/crypto c07d793c2f9a `golang.org/x/crypto/ed25519`/PrivateKey#) KeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/KeyPair# { |
| 39 | digest := sha512scip-go gomod github.com/golang/go/src go1.15 `crypto/sha512`/.Sum512scip-go gomod github.com/golang/go/src go1.15 `crypto/sha512`/Sum512().(key[:32]) |
| 40 | digest[0] &= 248 |
| 41 | digest[31] &= 127 |
| 42 | digest[31] |= 64 |
| 43 | return &precomputedKeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#{PrivateKeyBytesscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#PrivateKeyBytes.: digest[:], PublicKeyBytesscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#PublicKeyBytes.: PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKey#(key[32:])} |
| 44 | } |
| 45 | |
| 46 | // FromCryptoPublicKey converts a Go public key to the one in this package. |
| 47 | func FromCryptoPublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/FromCryptoPublicKey().(key ed25519scip-go gomod golang.org/x/crypto c07d793c2f9a `golang.org/x/crypto/ed25519`/.PublicKeyscip-go gomod golang.org/x/crypto c07d793c2f9a `golang.org/x/crypto/ed25519`/PublicKey#) PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKey# { |
| 48 | return PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKey#(key) |
| 49 | } |
| 50 | |
| 51 | // KeyPair returns a new key pair with the public key precomputed. |
| 52 | func (p PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#) KeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#KeyPair().() KeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/KeyPair# { |
| 53 | return &precomputedKeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#{PrivateKeyBytesscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#PrivateKeyBytes.: p, PublicKeyBytesscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#PublicKeyBytes.: p.PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#PublicKey().()} |
| 54 | } |
| 55 | |
| 56 | // PrivateKey simply returns itself. Implements KeyPair.PrivateKey. |
| 57 | func (p PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#) PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#PrivateKey().() PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey# { return p } |
| 58 | |
| 59 | // Public simply delegates to PublicKey() to satisfy crypto.Signer. This method |
| 60 | // does a bit more work than the traditional Go ed25519's private key's Public() |
| 61 | // method so developers are encouraged to reuse the result or use KeyPair() |
| 62 | // which stores this value. |
| 63 | func (p PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#) Publicscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#Public().() cryptoscip-go gomod github.com/golang/go/src go1.15 crypto/.PublicKeyscip-go gomod github.com/golang/go/src go1.15 crypto/PublicKey# { return p.PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#PublicKey().() } |
| 64 | |
| 65 | // PublicKey generates a public key for this private key. This method does a bit |
| 66 | // more work than the traditional Go ed25519's private key's Public() method so |
| 67 | // developers are encouraged to reuse the result or use KeyPair() which stores |
| 68 | // this value. Implements KeyPair.PublicKey. |
| 69 | func (p PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#) PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#PublicKey().() PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKey# { |
| 70 | var A edwards25519scip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/.ExtendedGroupElementscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/ExtendedGroupElement# |
| 71 | var hBytes [32]byte |
| 72 | copy(hBytes[:], p[:]) |
| 73 | edwards25519scip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/.GeScalarMultBasescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/GeScalarMultBase().(&A, &hBytes) |
| 74 | var publicKeyBytes [32]byte |
| 75 | A.ToBytesscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/ExtendedGroupElement#ToBytes().(&publicKeyBytes) |
| 76 | return publicKeyBytes[:] |
| 77 | } |
| 78 | |
| 79 | // Sign signs the given message with priv. Ed25519 performs two passes over |
| 80 | // messages to be signed and therefore cannot handle pre-hashed messages. Thus |
| 81 | // opts.HashFunc() must return zero to indicate the message hasn't been hashed. |
| 82 | // This can be achieved by passing crypto.Hash(0) as the value for opts. |
| 83 | func (p PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#) Signscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#Sign().(rand ioscip-go gomod github.com/golang/go/src go1.15 io/.Readerscip-go gomod github.com/golang/go/src go1.15 io/Reader#, message []byte, opts cryptoscip-go gomod github.com/golang/go/src go1.15 crypto/.SignerOptsscip-go gomod github.com/golang/go/src go1.15 crypto/SignerOpts#) ([]byte, error) { |
| 84 | if opts.HashFuncscip-go gomod github.com/golang/go/src go1.15 crypto/SignerOpts#HashFunc().() != cryptoscip-go gomod github.com/golang/go/src go1.15 crypto/.Hashscip-go gomod github.com/golang/go/src go1.15 crypto/Hash#(0) { |
| 85 | return nil, errorsscip-go gomod github.com/golang/go/src go1.15 errors/.Newscip-go gomod github.com/golang/go/src go1.15 errors/New().("ed25519: cannot sign hashed message") |
| 86 | } |
| 87 | return Signscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/Sign().(p, message), nil |
| 88 | } |
| 89 | |
| 90 | // Verify simply calls PublicKey().Verify(). Callers are encouraged to instead |
| 91 | // store a precomputed KeyPair (via KeyPair() or GenerateKey()) and call Verify |
| 92 | // on that. |
| 93 | func (p PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#) Verifyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#Verify().(message []byte, sig []byte) bool { |
| 94 | return p.PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#PublicKey().().Verifyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKey#Verify().(message, sig) |
| 95 | } |
| 96 | |
| 97 | // Verify simply calls the package-level function Verify(). |
| 98 | func (p PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKey#) Verifyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKey#Verify().(message []byte, sig []byte) bool { |
| 99 | return Verifyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/Verify().(p, message, sig) |
| 100 | } |
| 101 | |
| 102 | // KeyPair is an interface for types with both keys. While PrivateKey does |
| 103 | // implement this, it generates the PublicKey on demand. For better performance, |
| 104 | // use the result of GenerateKey directly or call PrivateKey.KeyPair(). |
| 105 | type KeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/KeyPair# interface { |
| 106 | cryptoscip-go gomod github.com/golang/go/src go1.15 crypto/.Signerscip-go gomod github.com/golang/go/src go1.15 crypto/Signer# |
| 107 | PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/KeyPair#PrivateKey.() PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey# |
| 108 | PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/KeyPair#PublicKey.() PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKey# |
| 109 | Verifyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/KeyPair#Verify.(message []byte, sig []byte) bool |
| 110 | } |
| 111 | |
| 112 | type precomputedKeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair# struct { |
| 113 | PrivateKeyBytesscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#PrivateKeyBytes. PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey# |
| 114 | PublicKeyBytesscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#PublicKeyBytes. PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKey# |
| 115 | } |
| 116 | |
| 117 | func (p *precomputedKeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#) PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#PrivateKey().() PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey# { return p.PrivateKeyBytesscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#PrivateKeyBytes. } |
| 118 | func (p *precomputedKeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#) PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#PublicKey().() PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKey# { return p.PublicKeyBytesscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#PublicKeyBytes. } |
| 119 | func (p *precomputedKeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#) Publicscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#Public().() cryptoscip-go gomod github.com/golang/go/src go1.15 crypto/.PublicKeyscip-go gomod github.com/golang/go/src go1.15 crypto/PublicKey# { return p.PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#PublicKey().() } |
| 120 | func (p *precomputedKeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#) Signscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#Sign().(rand ioscip-go gomod github.com/golang/go/src go1.15 io/.Readerscip-go gomod github.com/golang/go/src go1.15 io/Reader#, message []byte, opts cryptoscip-go gomod github.com/golang/go/src go1.15 crypto/.SignerOptsscip-go gomod github.com/golang/go/src go1.15 crypto/SignerOpts#) ([]byte, error) { |
| 121 | if opts.HashFuncscip-go gomod github.com/golang/go/src go1.15 crypto/SignerOpts#HashFunc().() != cryptoscip-go gomod github.com/golang/go/src go1.15 crypto/.Hashscip-go gomod github.com/golang/go/src go1.15 crypto/Hash#(0) { |
| 122 | return nil, errorsscip-go gomod github.com/golang/go/src go1.15 errors/.Newscip-go gomod github.com/golang/go/src go1.15 errors/New().("ed25519: cannot sign hashed message") |
| 123 | } |
| 124 | return Signscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/Sign().(p, message), nil |
| 125 | } |
| 126 | func (p *precomputedKeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#) Verifyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#Verify().(message []byte, sig []byte) bool { |
| 127 | return p.PublicKeyBytesscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/precomputedKeyPair#PublicKeyBytes..Verifyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKey#Verify().(message, sig) |
| 128 | } |
| 129 | |
| 130 | // GenerateKey generates a public/private key pair using entropy from rand. |
| 131 | // If rand is nil, crypto/rand.Reader will be used. |
| 132 | func GenerateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/GenerateKey().(rnd ioscip-go gomod github.com/golang/go/src go1.15 io/.Readerscip-go gomod github.com/golang/go/src go1.15 io/Reader#) (KeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/KeyPair#, error) { |
| 133 | if rnd == nil { |
| 134 | rnd = randscip-go gomod github.com/golang/go/src go1.15 `crypto/rand`/.Readerscip-go gomod github.com/golang/go/src go1.15 `crypto/rand`/Reader. |
| 135 | } |
| 136 | rndByts := make([]byte, 32) |
| 137 | if _, err := ioscip-go gomod github.com/golang/go/src go1.15 io/.ReadFullscip-go gomod github.com/golang/go/src go1.15 io/ReadFull().(rnd, rndByts); err != nil { |
| 138 | return nil, err |
| 139 | } |
| 140 | digest := sha512scip-go gomod github.com/golang/go/src go1.15 `crypto/sha512`/.Sum512scip-go gomod github.com/golang/go/src go1.15 `crypto/sha512`/Sum512().(rndByts) |
| 141 | digest[0] &= 248 |
| 142 | digest[31] &= 127 |
| 143 | digest[31] |= 64 |
| 144 | return PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#(digest[:]).KeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PrivateKey#KeyPair().(), nil |
| 145 | } |
| 146 | |
| 147 | // Sign signs the message with the given key pair. |
| 148 | func Signscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/Sign().(keyPair KeyPairscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/KeyPair#, message []byte) []byte { |
| 149 | // Ref: https://stackoverflow.com/questions/44810708/ed25519-public-result-is-different |
| 150 | |
| 151 | var privateKeyA [32]byte |
| 152 | copy(privateKeyA[:], keyPair.PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/KeyPair#PrivateKey.()) // we need this in an array later |
| 153 | var messageDigest, hramDigest [64]byte |
| 154 | |
| 155 | h := sha512scip-go gomod github.com/golang/go/src go1.15 `crypto/sha512`/.Newscip-go gomod github.com/golang/go/src go1.15 `crypto/sha512`/New().() |
| 156 | h.Writescip-go gomod github.com/golang/go/src go1.15 io/Writer#Write().(keyPair.PrivateKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/KeyPair#PrivateKey.()[32:]) |
| 157 | h.Writescip-go gomod github.com/golang/go/src go1.15 io/Writer#Write().(message) |
| 158 | h.Sumscip-go gomod github.com/golang/go/src go1.15 hash/Hash#Sum().(messageDigest[:0]) |
| 159 | |
| 160 | var messageDigestReduced [32]byte |
| 161 | edwards25519scip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/.ScReducescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/ScReduce().(&messageDigestReduced, &messageDigest) |
| 162 | var R edwards25519scip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/.ExtendedGroupElementscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/ExtendedGroupElement# |
| 163 | edwards25519scip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/.GeScalarMultBasescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/GeScalarMultBase().(&R, &messageDigestReduced) |
| 164 | |
| 165 | var encodedR [32]byte |
| 166 | R.ToBytesscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/ExtendedGroupElement#ToBytes().(&encodedR) |
| 167 | |
| 168 | h.Resetscip-go gomod github.com/golang/go/src go1.15 hash/Hash#Reset().() |
| 169 | h.Writescip-go gomod github.com/golang/go/src go1.15 io/Writer#Write().(encodedR[:]) |
| 170 | h.Writescip-go gomod github.com/golang/go/src go1.15 io/Writer#Write().(keyPair.PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/KeyPair#PublicKey.()) |
| 171 | h.Writescip-go gomod github.com/golang/go/src go1.15 io/Writer#Write().(message) |
| 172 | h.Sumscip-go gomod github.com/golang/go/src go1.15 hash/Hash#Sum().(hramDigest[:0]) |
| 173 | var hramDigestReduced [32]byte |
| 174 | edwards25519scip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/.ScReducescip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/ScReduce().(&hramDigestReduced, &hramDigest) |
| 175 | |
| 176 | var s [32]byte |
| 177 | edwards25519scip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/.ScMulAddscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519/internal/edwards25519`/ScMulAdd().(&s, &hramDigestReduced, &privateKeyA, &messageDigestReduced) |
| 178 | |
| 179 | signature := make([]byte, 64) |
| 180 | copy(signature[:], encodedR[:]) |
| 181 | copy(signature[32:], s[:]) |
| 182 | |
| 183 | return signature |
| 184 | } |
| 185 | |
| 186 | // Verify verifies a signed message. |
| 187 | func Verifyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/Verify().(p PublicKeyscip-go gomod github.com/cretz/bine . `github.com/cretz/bine/torutil/ed25519`/PublicKey#, message []byte, sig []byte) bool { |
| 188 | return ed25519scip-go gomod golang.org/x/crypto c07d793c2f9a `golang.org/x/crypto/ed25519`/.Verifyscip-go gomod golang.org/x/crypto c07d793c2f9a `golang.org/x/crypto/ed25519`/Verify().(ed25519scip-go gomod golang.org/x/crypto c07d793c2f9a `golang.org/x/crypto/ed25519`/.PublicKeyscip-go gomod golang.org/x/crypto c07d793c2f9a `golang.org/x/crypto/ed25519`/PublicKey#(p), message, sig) |
| 189 | } |