MCPcopy Create free account
hub / github.com/Mister-leo/fssh / deriveMasterKeyFromSeed

Function deriveMasterKeyFromSeed

cmd/fssh/otp_init.go:132–147  ·  view source on GitHub ↗

deriveMasterKeyFromSeed 从 OTP seed 派生 master key 使用与 OTPProvider 相同的方法,确保一致性

(seed []byte, opts *otp.InitOptions)

Source from the content-addressed store, hash-verified

130// deriveMasterKeyFromSeed 从 OTP seed 派生 master key
131// 使用与 OTPProvider 相同的方法,确保一致性
132func deriveMasterKeyFromSeed(seed []byte, opts *otp.InitOptions) ([]byte, error) {
133 // 从配置中读取 master key salt
134 cfg, err := otp.LoadConfig(otp.ConfigPath())
135 if err != nil {
136 return nil, fmt.Errorf("加载配置失败: %w", err)
137 }
138
139 masterKeySalt, err := base64.StdEncoding.DecodeString(cfg.MasterKeySalt)
140 if err != nil {
141 return nil, fmt.Errorf("解码 master key salt 失败: %w", err)
142 }
143
144 // 使用 HKDF 派生 master key
145 masterKey := crypt.HKDF(seed, masterKeySalt, []byte("fssh-master-key-v1"), 32)
146 return masterKey, nil
147}

Callers 1

initOTPModeFunction · 0.85

Calls 3

LoadConfigFunction · 0.92
ConfigPathFunction · 0.92
HKDFFunction · 0.92

Tested by

no test coverage detected