cosmos-sdk/crypto/keys/mintkey
Alessio Treglia 9bd603ae88
crypto: cleanup, more testing
crypto.LedgerShowAddress() is a ledger specific function
and should takes acc address prefix instead of depending
on a sdk.Config singleton.

crypto/keys/mintkey:
- decryptPrivKey() return error instead of os.Exit()ing.
- encryptPrivKey() should panic instead of os.Exit() when
  bcrypt.GenerateFromPassword() call fails so that the
  caller is given a chance to recover().

crypto/keys:
- SignWithLedger() does not need to be method of
  baseKeybase. Method receiver is unused.
- ledgerInfo objecta may be pointers, type switch
  should handle both to avoid panics.
- keyringKeybase should not provide Update() at all.

More test cases are added to increase package crypto
and subpackages overall coverage.
2020-03-02 11:09:52 +00:00
..
README.md Address @alexanderbez comments 2019-02-13 17:26:14 +01:00
mintkey.go crypto: cleanup, more testing 2020-03-02 11:09:52 +00:00
mintkey_bench_test.go Merge PR #4687: Changed replace directive to specific revision of tendermint crypto 2019-07-09 15:04:30 -07:00
mintkey_test.go crypto: cleanup, more testing 2020-03-02 11:09:52 +00:00

README.md

Security parameter choice

The present Bcrypt security parameter used is 12, which should take about a quarter of a second on midrange consumer hardware (see Benchmarking section below).

For some background into security parameter considerations, see here and here.

Given our security model, where an attacker would need to already have access to a victim's computer and copy the ~/.gaiacli directory (as opposed to e.g. web authentication), this parameter choice seems sufficient for the time being. Bcrypt always generates a 448-bit key, so the security in practice is determined by the length & complexity of a user's password and the time taken to generate a Bcrypt key from their password (which we can choose with the security parameter). Users would be well-advised to use difficult-to-guess passwords.

Benchmarking

To run Bcrypt benchmarks:

go test -v --bench github.com/cosmos/cosmos-sdk/crypto/keys/mintkey

On the test machine (midrange ThinkPad; i7 6600U), this results in:

goos: linux
goarch: amd64
pkg: github.com/cosmos/cosmos-sdk/crypto/keys/mintkey
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-9-4         	      50	  34609268 ns/op
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-10-4        	      20	  67874471 ns/op
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-11-4        	      10	 135515404 ns/op
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-12-4        	       5	 274824600 ns/op
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-13-4        	       2	 547012903 ns/op
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-14-4        	       1	1083685904 ns/op
BenchmarkBcryptGenerateFromPassword/benchmark-security-param-15-4        	       1	2183674041 ns/op
PASS
ok  	github.com/cosmos/cosmos-sdk/crypto/keys/mintkey	12.093s

Benchmark results are in nanoseconds, so security parameter 12 takes about a quarter of a second to generate the Bcrypt key, security param 13 takes half a second, and so on.