github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/libkb/passphrase_stream_test.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package libkb 5 6 import ( 7 "encoding/hex" 8 "testing" 9 ) 10 11 type dktest struct { 12 name string 13 passphrase string 14 salt string 15 pwh string 16 ekey string 17 dkey string 18 lkey string 19 } 20 21 var dktests = []dktest{ 22 { 23 name: "simple 1", 24 passphrase: "my passphrase", 25 salt: "random salt zxcv", 26 pwh: "eb92a4bc72cbce98b80c5bfb391b353c37af5f3398e52c7cb436b73de97abc48", 27 ekey: "248f73a3645486c7d2c327da2bb7bb3129cf2347494d54ca9e35083f325ab57e", 28 dkey: "b4f8ffced85c240c4833afac527ce1f9be37e2e645fc020d41c31d8179ff7ef2", 29 lkey: "daf502dcc05af15e8c9b4c36a195566e1cfdd5dbb7593e268e0053e89ed74c0f", 30 }, 31 { 32 name: "simple 2", 33 passphrase: "my passphrase", 34 salt: "random salt qwer", 35 pwh: "5c44c619c7f29bc446af06ecd2d5c8d0a58db04970891aa18084fac8014c717a", 36 ekey: "c93b7470701a0623a062b849f0527b68faa568549926b77320e9030b12d29197", 37 dkey: "77375b7d2e59b9fdd4733dbead5ba66116cec508e05919b98332b97e437a75b0", 38 lkey: "5fec13005cca4f12ce0b624db02488d9ea4e5ef54b67649620c810e6b4e01376", 39 }, 40 { 41 name: "simple 3", 42 passphrase: "my passphrase is longer", 43 salt: "random salt zxcv", 44 pwh: "de526ef302f50283d0a0aecdc303e1f42c3b206060657bf03f781f076eec1459", 45 ekey: "199c9e10e5c9505c431cd2d3235873e7e113918511178afc341d28d48f1b5dd7", 46 dkey: "1c2c2d040fc743f939b1af6e90dde1a0e9181e2d6a0e584c75f7d363100493d5", 47 lkey: "66647f005c89d55efbc4683b2a86210d545d77e6fadfd29b8aa9bcc53efc5a7f", 48 }, 49 } 50 51 func TestTSPassKey(t *testing.T) { 52 for _, test := range dktests { 53 _, dk, err := StretchPassphrase(nil, test.passphrase, []byte(test.salt)) 54 if err != nil { 55 t.Errorf("%s: got unexpected error: %s", test.name, err) 56 continue 57 } 58 if hex.EncodeToString(dk.PWHash()) != test.pwh { 59 t.Errorf("%s: pwh = %x, expected %q", test.name, dk.PWHash(), test.pwh) 60 } 61 if hex.EncodeToString(dk.EdDSASeed()) != test.ekey { 62 t.Errorf("%s: eddsa = %x, expected %q", test.name, dk.EdDSASeed(), test.ekey) 63 } 64 if hex.EncodeToString(dk.DHSeed()) != test.dkey { 65 t.Errorf("%s: dh = %x, expected %q", test.name, dk.DHSeed(), test.dkey) 66 } 67 if hex.EncodeToString(dk.LksClientHalf().Bytes()) != test.lkey { 68 t.Errorf("%s: lks = %x, expected %q", test.name, dk.LksClientHalf().Bytes(), test.lkey) 69 } 70 } 71 }