File: ec_key_openssl.go

package info (click to toggle)
golang-github-containers-libtrust 0.0~git20230121.c1716e8-2~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 336 kB
  • sloc: makefile: 3
file content (24 lines) | stat: -rw-r--r-- 471 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// +build libtrust_openssl

package libtrust

import (
	"bytes"
	"crypto"
	"crypto/ecdsa"
	"crypto/rand"
	"fmt"
	"io"
	"math/big"
)

func (k *ecPrivateKey) sign(data io.Reader, hashID crypto.Hash) (r, s *big.Int, err error) {
	hId := k.signatureAlgorithm.HashID()
	buf := new(bytes.Buffer)
	_, err = buf.ReadFrom(data)
	if err != nil {
		return nil, nil, fmt.Errorf("error reading data: %s", err)
	}

	return ecdsa.HashSign(rand.Reader, k.PrivateKey, buf.Bytes(), hId)
}