| 1 | /* |
| 2 | * Copyright (c) 2014, Yawning Angel <yawning at schwanenlied dot me> |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * * Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * |
| 11 | * * Redistributions in binary form must reproduce the above copyright notice, |
| 12 | * this list of conditions and the following disclaimer in the documentation |
| 13 | * and/or other materials provided with the distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 25 | * POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | // Package uniformdh implements the Tor Project's UniformDH key exchange |
| 29 | // mechanism as defined in the obfs3 protocol specification. This |
| 30 | // implementation is suitable for obfuscation but MUST NOT BE USED when strong |
| 31 | // security is required as it is not constant time. |
| 32 | package uniformdhscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/ // import "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh" |
| 33 | |
| 34 | import ( |
| 35 | "fmtscip-go gomod github.com/golang/go/src go1.22.0 fmt/" |
| 36 | "ioscip-go gomod github.com/golang/go/src go1.22.0 io/" |
| 37 | "math/bigscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/" |
| 38 | ) |
| 39 | |
| 40 | const ( |
| 41 | // Size is the size of a UniformDH key or shared secret in bytes. |
| 42 | Sizescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/Size. = 1536 / 8 |
| 43 | |
| 44 | // modpStr is the RFC3526 1536-bit MODP Group (Group 5). |
| 45 | modpStrscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/modpStr. = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" + |
| 46 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" + |
| 47 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" + |
| 48 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" + |
| 49 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" + |
| 50 | "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" + |
| 51 | "83655D23DCA3AD961C62F356208552BB9ED529077096966D" + |
| 52 | "670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF" |
| 53 | |
| 54 | gscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/g. = 2 |
| 55 | ) |
| 56 | |
| 57 | var modpGroupscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/modpGroup. *bigscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int# |
| 58 | var genscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/gen. *bigscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int# |
| 59 | |
| 60 | // A PrivateKey represents a UniformDH private key. |
| 61 | type PrivateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PrivateKey# struct { |
| 62 | PublicKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PrivateKey#PublicKey. |
| 63 | privateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PrivateKey#privateKey. *bigscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int# |
| 64 | } |
| 65 | |
| 66 | // A PublicKey represents a UniformDH public key. |
| 67 | type PublicKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey# struct { |
| 68 | bytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#bytes. []byte |
| 69 | publicKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#publicKey. *bigscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int# |
| 70 | } |
| 71 | |
| 72 | // Bytes returns the byte representation of a PublicKey. |
| 73 | func (pub *PublicKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#) Bytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#Bytes().() (pubBytes []byte, err error) { |
| 74 | if len(pub.bytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#bytes.) != Sizescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/Size. || pub.bytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#bytes. == nil { |
| 75 | return nil, fmtscip-go gomod github.com/golang/go/src go1.22.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22.0 fmt/Errorf().("public key is not initialized") |
| 76 | } |
| 77 | pubBytes = make([]byte, Sizescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/Size.) |
| 78 | copy(pubBytes, pub.bytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#bytes.) |
| 79 | |
| 80 | return |
| 81 | } |
| 82 | |
| 83 | // SetBytes sets the PublicKey from a byte slice. |
| 84 | func (pub *PublicKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#) SetBytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#SetBytes().(pubBytes []byte) error { |
| 85 | if len(pubBytes) != Sizescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/Size. { |
| 86 | return fmtscip-go gomod github.com/golang/go/src go1.22.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22.0 fmt/Errorf().("public key length %d is not %d", len(pubBytes), Sizescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/Size.) |
| 87 | } |
| 88 | pub.bytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#bytes. = make([]byte, Sizescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/Size.) |
| 89 | copy(pub.bytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#bytes., pubBytes) |
| 90 | pub.publicKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#publicKey. = new(bigscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#).SetBytesscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#SetBytes().(pub.bytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#bytes.) |
| 91 | |
| 92 | return nil |
| 93 | } |
| 94 | |
| 95 | // GenerateKey generates a UniformDH keypair using the random source random. |
| 96 | func GenerateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/GenerateKey().(random ioscip-go gomod github.com/golang/go/src go1.22.0 io/.Readerscip-go gomod github.com/golang/go/src go1.22.0 io/Reader#) (priv *PrivateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PrivateKey#, err error) { |
| 97 | privBytes := make([]byte, Sizescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/Size.) |
| 98 | if _, err = ioscip-go gomod github.com/golang/go/src go1.22.0 io/.ReadFullscip-go gomod github.com/golang/go/src go1.22.0 io/ReadFull().(random, privBytes); err != nil { |
| 99 | return |
| 100 | } |
| 101 | priv, err = generateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/generateKey().(privBytes) |
| 102 | |
| 103 | return |
| 104 | } |
| 105 | |
| 106 | func generateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/generateKey().(privBytes []byte) (priv *PrivateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PrivateKey#, err error) { |
| 107 | // This function does all of the actual heavy lifting of creating a public |
| 108 | // key from a raw 192 byte private key. It is split so that the KAT tests |
| 109 | // can be written easily, and not exposed since non-ephemeral keys are a |
| 110 | // terrible idea. |
| 111 | |
| 112 | if len(privBytes) != Sizescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/Size. { |
| 113 | return nil, fmtscip-go gomod github.com/golang/go/src go1.22.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22.0 fmt/Errorf().("invalid private key size %d", len(privBytes)) |
| 114 | } |
| 115 | |
| 116 | // To pick a private UniformDH key, we pick a random 1536-bit number, |
| 117 | // and make it even by setting its low bit to 0 |
| 118 | privBn := new(bigscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#).SetBytesscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#SetBytes().(privBytes) |
| 119 | wasEven := privBn.Bitscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#Bit().(0) == 0 |
| 120 | privBn = privBn.SetBitscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#SetBit().(privBn, 0, 0) |
| 121 | |
| 122 | // Let x be that private key, and X = g^x (mod p). |
| 123 | pubBn := new(bigscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#).Expscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#Exp().(genscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/gen., privBn, modpGroupscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/modpGroup.) |
| 124 | pubAlt := new(bigscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#).Subscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#Sub().(modpGroupscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/modpGroup., pubBn) |
| 125 | |
| 126 | // When someone sends her public key to the other party, she randomly |
| 127 | // decides whether to send X or p-X. Use the lowest most bit of the |
| 128 | // private key here as the random coin flip since it is masked out and not |
| 129 | // used. |
| 130 | // |
| 131 | // Note: The spec doesn't explicitly specify it, but here we prepend zeros |
| 132 | // to the key so that it is always exactly Size bytes. |
| 133 | pubBytes := make([]byte, Sizescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/Size.) |
| 134 | if wasEven { |
| 135 | err = prependZeroBytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/prependZeroBytes().(pubBytes, pubBn.Bytesscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#Bytes().()) |
| 136 | } else { |
| 137 | err = prependZeroBytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/prependZeroBytes().(pubBytes, pubAlt.Bytesscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#Bytes().()) |
| 138 | } |
| 139 | if err != nil { |
| 140 | return |
| 141 | } |
| 142 | |
| 143 | priv = new(PrivateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PrivateKey#) |
| 144 | priv.PublicKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PrivateKey#PublicKey..bytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#bytes. = pubBytes |
| 145 | priv.PublicKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PrivateKey#PublicKey..publicKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#publicKey. = pubBn |
| 146 | priv.privateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PrivateKey#privateKey. = privBn |
| 147 | |
| 148 | return |
| 149 | } |
| 150 | |
| 151 | // Handshake generates a shared secret given a PrivateKey and PublicKey. |
| 152 | func Handshakescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/Handshake().(privateKey *PrivateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PrivateKey#, publicKey *PublicKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#) (sharedSecret []byte, err error) { |
| 153 | // When a party wants to calculate the shared secret, she raises the |
| 154 | // foreign public key to her private key. |
| 155 | secretBn := new(bigscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#).Expscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#Exp().(publicKey.publicKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PublicKey#publicKey., privateKey.privateKeyscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/PrivateKey#privateKey., modpGroupscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/modpGroup.) |
| 156 | sharedSecret = make([]byte, Sizescip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/Size.) |
| 157 | err = prependZeroBytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/prependZeroBytes().(sharedSecret, secretBn.Bytesscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#Bytes().()) |
| 158 | |
| 159 | return |
| 160 | } |
| 161 | |
| 162 | func prependZeroBytesscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/prependZeroBytes().(dst, src []byte) error { |
| 163 | zeros := len(dst) - len(src) |
| 164 | if zeros < 0 { |
| 165 | return fmtscip-go gomod github.com/golang/go/src go1.22.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22.0 fmt/Errorf().("src length is greater than destination: %d", zeros) |
| 166 | } |
| 167 | for i := 0; i < zeros; i++ { |
| 168 | dst[i] = 0 |
| 169 | } |
| 170 | copy(dst[zeros:], src) |
| 171 | |
| 172 | return nil |
| 173 | } |
| 174 | |
| 175 | func initscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/init().() { |
| 176 | // Load the MODP group and the generator. |
| 177 | var ok bool |
| 178 | modpGroupscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/modpGroup., ok = new(bigscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/.Intscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#).SetStringscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/Int#SetString().(modpStrscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/modpStr., 16) |
| 179 | if !ok { |
| 180 | panic("Failed to load the RFC3526 MODP Group") |
| 181 | } |
| 182 | genscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/gen. = bigscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/.NewIntscip-go gomod github.com/golang/go/src go1.22.0 `math/big`/NewInt().(gscip-go gomod gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird . `gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/lyrebird/common/uniformdh`/g.) |
| 183 | } |