package main // A key generator that generates magic keys // go run sm-ipmi-key.go import ( "crypto/hmac" "crypto/sha1" "encoding/hex" "fmt" "os" "strings" ) const secretKey = "8544E3B47ECA58F9583043F8" func mustUnhex(s string) []byte { o, err := hex.DecodeString(s) if err != nil { panic(err) } return o } func main() { // Cleanup mac mac := strings.ReplaceAll(strings.ToLower(os.Args[1]), ":", "") // Create hash hash := hmac.New(sha1.New, mustUnhex(secretKey)) hash.Write(mustUnhex(mac)) res := hex.EncodeToString(hash.Sum(nil)) // Cut into groups of 4 characters out := make([]string, 24/4) for i := 0; i < 24/4; i++ { out[i] = res[:24][i*4 : i*4+4] } // Print the groups with spaces between them fmt.Println(strings.Join(out, " ")) }