base58

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 3 Imported by: 0

README

base58

base58 is a fast implementation of Base58 with resistance to side-channel attacks.

Benchmarks

$ go test -bench=5K .
goos: darwin
goarch: arm64
pkg: github.com/koba-e964/base58-go
BenchmarkDecode_ConstantTime_5K-8            660           1772633 ns/op           3.91 MB/s        5376 B/op          1 allocs/op
BenchmarkDecode_VariableTime_5K-8           8433            134081 ns/op          51.63 MB/s      338044 B/op        126 allocs/op
BenchmarkEncode_ConstantTime_5K-8            409           2905121 ns/op           1.72 MB/s       12288 B/op          2 allocs/op
BenchmarkEncode_VariableTime_5K-8            982           1216755 ns/op           4.11 MB/s       24664 B/op        686 allocs/op
PASS
ok      github.com/koba-e964/base58-go  5.459s

The performance of base58.VartimeEncode and base58.VartimeDecode is comparable to that of github.com/btcsuite/btcd/btcutil/base58:

$ go test -bench=5K .
goos: darwin
goarch: arm64
pkg: github.com/btcsuite/btcd/btcutil/base58
BenchmarkBase58Encode_5K-8           974           1222350 ns/op           4.09 MB/s
BenchmarkBase58Decode_5K-8          8229            131085 ns/op          52.10 MB/s
PASS
ok      github.com/btcsuite/btcd/btcutil/base58 3.228s
$ git log --max-count=1
commit 13152b35e191385a874294a9dbc902e48b1d71b0 (HEAD -> master, origin/master, origin/HEAD)
Merge: 8e53942b e307ad12
Author: Olaoluwa Osuntokun <laolu32@gmail.com>
Date:   Tue Jan 23 20:25:55 2024 -0800

    Merge pull request #2089 from kcalvinalvin/2024-01-03-add-last-flush-time-on-initconsistentstate
    
    blockchain: set the lastflushtime when setting the lastflushhash
$ go version
go version go1.22.0 darwin/arm64

Besides, this package offers the constant-time version of these functions, namely base58.Encode and base58.Decode, which prevents side-channel attacks such as timing attacks.

Docs

https://pkg.go.dev/github.com/koba-e964/base58-go

Documentation

Overview

Package base58 handles encoding/decoding of Base58 (https://en.bitcoin.it/wiki/Base58Check_encoding). This package provides functions that work constant-time, as well as their variable-time counterparts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(encoded string, output []byte)

Decode writes into output.

If the resulting integer doesn't fit in output, the higher part will be truncated.

This function runs in constant time.

func Encode

func Encode(a []byte, resultLength int) string

Encode encodes a byte slice into a base58 string with length resultLength.

This function runs in constant time.

func VartimeDecode

func VartimeDecode(encoded string, output []byte)

VartimeDecode writes into output.

If the resulting integer doesn't fit in output, the higher part will be truncated.

This function does not have a constant-time guarantee, but it is faster than Decode.

func VartimeEncode

func VartimeEncode(a []byte, resultLength int) string

VartimeEncode encodes a byte slice into a base58 string with length resultLength.

This function does not have a constant-time guarantee.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL