func signWithKey()

in sks_windows.go [65:89]


func signWithKey(label, tag string, _, digest []byte) ([]byte, error) {
	key, err := findPrivateKey(label)
	if err != nil {
		return nil, fmt.Errorf(ErrSignWithKey, label, tag, err)
	}
	if key == nil {
		return nil, fmt.Errorf("failed to find key with label %q and tag %q", label, tag)
	}
	key = key.(*tpm.EcdsaKey)
	sig, err := key.SignRaw(digest)
	if err != nil {
		return nil, fmt.Errorf(ErrSignWithKey, label, tag, err)
	}
	// https://stackoverflow.com/questions/38702169/c-sharp-ecdsacng-signdata-use-signature-in-openssl
	// windows encodes an ecdsa signature as concatenating r and s in the array.
	// the output sig will always be of even length
	r := new(big.Int).SetBytes(sig[0 : len(sig)/2])
	s := new(big.Int).SetBytes(sig[len(sig)/2:])
	// https://golang.org/src/crypto/ecdsa/ecdsa.go?s=2196:2295#L65
	sig, err = asn1.Marshal(utils.ECCSignature{r, s})
	if err != nil {
		return nil, fmt.Errorf(ErrSignWithKey, label, tag, err)
	}
	return sig, nil
}