From 1e574942d586bb26f659f9ebee9ec90d778ecb97 Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Sat, 23 Aug 2014 05:33:23 +0000 Subject: Change all the arguments to use base16 from base64. WARNING: THIS BREAKS BACKWARD COMPATIBILITY. This is primarily to work around bug #12930. Base16 was chosen over unpadded Base64 because the go runtime Base64 decoder does not handle omitting the padding. May $deity have mercy on anyone who needs to hand-enter an obfs4 bridge line because I will not. --- common/drbg/hash_drbg.go | 14 +++++++------- common/ntor/ntor.go | 38 +++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 26 deletions(-) (limited to 'common') diff --git a/common/drbg/hash_drbg.go b/common/drbg/hash_drbg.go index 5329828..2cd1ec7 100644 --- a/common/drbg/hash_drbg.go +++ b/common/drbg/hash_drbg.go @@ -30,7 +30,7 @@ package drbg import ( - "encoding/base64" + "encoding/hex" "encoding/binary" "fmt" "hash" @@ -55,9 +55,9 @@ func (seed *Seed) Bytes() *[SeedLength]byte { return (*[SeedLength]byte)(seed) } -// Base64 returns the Base64 representation of the seed. -func (seed *Seed) Base64() string { - return base64.StdEncoding.EncodeToString(seed.Bytes()[:]) +// Hex returns the hexdecimal representation of the seed. +func (seed *Seed) Hex() string { + return hex.EncodeToString(seed.Bytes()[:]) } // NewSeed returns a Seed initialized with the runtime CSPRNG. @@ -83,11 +83,11 @@ func SeedFromBytes(src []byte) (seed *Seed, err error) { return } -// SeedFromBase64 creates a Seed from the Base64 representation, truncating to +// SeedFromHex creates a Seed from the hexdecimal representation, truncating to // SeedLength as appropriate. -func SeedFromBase64(encoded string) (seed *Seed, err error) { +func SeedFromHex(encoded string) (seed *Seed, err error) { var raw []byte - if raw, err = base64.StdEncoding.DecodeString(encoded); err != nil { + if raw, err = hex.DecodeString(encoded); err != nil { return nil, err } diff --git a/common/ntor/ntor.go b/common/ntor/ntor.go index 37cfe88..d123f38 100644 --- a/common/ntor/ntor.go +++ b/common/ntor/ntor.go @@ -39,7 +39,7 @@ import ( "crypto/hmac" "crypto/sha256" "crypto/subtle" - "encoding/base64" + "encoding/hex" "fmt" "io" @@ -137,9 +137,9 @@ func NewNodeID(raw []byte) (*NodeID, error) { return nodeID, nil } -// NodeIDFromBase64 creates a new NodeID from the Base64 encoded representation. -func NodeIDFromBase64(encoded string) (*NodeID, error) { - raw, err := base64.StdEncoding.DecodeString(encoded) +// NodeIDFromHex creates a new NodeID from the hexdecimal representation. +func NodeIDFromHex(encoded string) (*NodeID, error) { + raw, err := hex.DecodeString(encoded) if err != nil { return nil, err } @@ -151,9 +151,9 @@ func (id *NodeID) Bytes() *[NodeIDLength]byte { return (*[NodeIDLength]byte)(id) } -// Base64 returns the Base64 representation of the NodeID. -func (id *NodeID) Base64() string { - return base64.StdEncoding.EncodeToString(id[:]) +// Hex returns the hexdecimal representation of the NodeID. +func (id *NodeID) Hex() string { + return hex.EncodeToString(id[:]) } // PublicKey is a Curve25519 public key in little-endian byte order. @@ -164,9 +164,9 @@ func (public *PublicKey) Bytes() *[PublicKeyLength]byte { return (*[PublicKeyLength]byte)(public) } -// Base64 returns the Base64 representation of the Curve25519 public key. -func (public *PublicKey) Base64() string { - return base64.StdEncoding.EncodeToString(public.Bytes()[:]) +// Hex returns the hexdecimal representation of the Curve25519 public key. +func (public *PublicKey) Hex() string { + return hex.EncodeToString(public.Bytes()[:]) } // NewPublicKey creates a PublicKey from the raw bytes. @@ -181,9 +181,9 @@ func NewPublicKey(raw []byte) (*PublicKey, error) { return pubKey, nil } -// PublicKeyFromBase64 returns a PublicKey from a Base64 representation. -func PublicKeyFromBase64(encoded string) (*PublicKey, error) { - raw, err := base64.StdEncoding.DecodeString(encoded) +// PublicKeyFromHex returns a PublicKey from the hexdecimal representation. +func PublicKeyFromHex(encoded string) (*PublicKey, error) { + raw, err := hex.DecodeString(encoded) if err != nil { return nil, err } @@ -216,9 +216,9 @@ func (private *PrivateKey) Bytes() *[PrivateKeyLength]byte { return (*[PrivateKeyLength]byte)(private) } -// Base64 returns the Base64 representation of the Curve25519 private key. -func (private *PrivateKey) Base64() string { - return base64.StdEncoding.EncodeToString(private.Bytes()[:]) +// Hex returns the hexdecimal representation of the Curve25519 private key. +func (private *PrivateKey) Hex() string { + return hex.EncodeToString(private.Bytes()[:]) } // Keypair is a Curve25519 keypair with an optional Elligator representative. @@ -291,10 +291,10 @@ func NewKeypair(elligator bool) (*Keypair, error) { } } -// KeypairFromBase64 returns a Keypair from a Base64 representation of the +// KeypairFromHex returns a Keypair from the hexdecimal representation of the // private key. -func KeypairFromBase64(encoded string) (*Keypair, error) { - raw, err := base64.StdEncoding.DecodeString(encoded) +func KeypairFromHex(encoded string) (*Keypair, error) { + raw, err := hex.DecodeString(encoded) if err != nil { return nil, err } -- cgit v1.2.3