aezeed: expose BirthdayTime conversion from offset

This commit is contained in:
Conner Fromknecht 2018-03-26 14:02:51 -07:00
parent c54a91f44d
commit c824af11a1
No known key found for this signature in database
GPG Key ID: 39DE78FBE6ACB0EF
2 changed files with 12 additions and 5 deletions

View File

@ -126,12 +126,12 @@ var (
)
var (
// bitcoinGenesisDate is the timestamp of Bitcoin's genesis block.
// BitcoinGenesisDate is the timestamp of Bitcoin's genesis block.
// We'll use this value in order to create a compact birthday for the
// seed. The birthday will be interested as the number of days since
// the genesis date. We refer to this time period as ABE (after Bitcoin
// era).
bitcoinGenesisDate = time.Unix(1231006505, 0)
BitcoinGenesisDate = time.Unix(1231006505, 0)
)
// CipherSeed is a fully decoded instance of the aezeed scheme. At a high
@ -201,7 +201,7 @@ func New(internalVersion uint8, entropy *[EntropySize]byte,
// To compute our "birthday", we'll first use the current time, then
// subtract that from the Bitcoin Genesis Date. We'll then convert that
// value to days.
birthday := uint16(now.Sub(bitcoinGenesisDate) / (time.Hour * 24))
birthday := uint16(now.Sub(BitcoinGenesisDate) / (time.Hour * 24))
c := &CipherSeed{
InternalVersion: internalVersion,
@ -384,6 +384,13 @@ func (c *CipherSeed) Encipher(pass []byte) ([EncipheredCipherSeedSize]byte, erro
return c.encipher(pass)
}
// BirthdayTime returns the cipher seed's internal birthday format as a native
// golang Time struct.
func (c *CipherSeed) BirthdayTime() time.Time {
offset := time.Duration(c.Birthday) * 24 * time.Hour
return BitcoinGenesisDate.Add(offset)
}
// Mnemonic is a 24-word passphrase as of CipherSeedVersion zero. This
// passphrase encodes an encrypted seed triple (version, birthday, entropy).
// Additionally, we also encode the salt used with scrypt to derive the key

View File

@ -33,7 +33,7 @@ var (
version0TestVectors = []TestVector{
{
version: 0,
time: bitcoinGenesisDate,
time: BitcoinGenesisDate,
entropy: testEntropy,
salt: testSalt,
password: []byte{},
@ -466,7 +466,7 @@ func TestSeedEncodeDecode(t *testing.T) {
now := time.Unix(nowInt, 0)
seed := CipherSeed{
InternalVersion: version,
Birthday: uint16(now.Sub(bitcoinGenesisDate) / (time.Hour * 24)),
Birthday: uint16(now.Sub(BitcoinGenesisDate) / (time.Hour * 24)),
Entropy: entropy,
}