File: testvectors.go

package info (click to toggle)
golang-github-google-go-tpm 0.9.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,932 kB
  • sloc: makefile: 13
file content (73 lines) | stat: -rw-r--r-- 1,936 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Package testvectors contains test vectors for TPM crypto.
package testvectors

import (
	_ "embed"
	"encoding/hex"
	"encoding/json"
	"strings"
	"testing"
)

// This package contains test vectors from https://github.com/chrisfenner/tpm-test-vectors.
// These test vectors were validated against the TCG Reference Implementation.

type hexBytes []byte

func (h *hexBytes) UnmarshalJSON(data []byte) error {
	var err error
	*h, err = hex.DecodeString(strings.Trim(string(data), "\""))
	return err
}

//go:embed ecc_labeled_encaps.json
var eccLabeledEncapsJSON []byte

// ECCLabeledEncapsTestCase is a test case for ECC Labeled Encapsulation (Secret Sharing).
type ECCLabeledEncapsTestCase struct {
	Name             string
	Description      string
	Label            string
	EphemeralPrivate hexBytes
	PublicKey        hexBytes
	Secret           hexBytes
	Ciphertext       hexBytes
}

// ECCLabeledEncapsulation iterates the ECC Labeled Encapsulation test cases.
func ECCLabeledEncapsulation(t *testing.T) []ECCLabeledEncapsTestCase {
	t.Helper()

	var testCases []ECCLabeledEncapsTestCase
	if err := json.Unmarshal(eccLabeledEncapsJSON, &testCases); err != nil {
		t.Fatalf("could not unmarshal JSON: %v", err)
	}

	return testCases
}

//go:embed rsa_labeled_encaps.json
var rsaLabeledEncapsJSON []byte

// RSALabeledEncapsTestCase is a test case for RSA Labeled Encapsulation (Secret Sharing).
type RSALabeledEncapsTestCase struct {
	Name        string
	Description string
	Label       string
	OAEPSalt    hexBytes
	PublicKey   hexBytes
	Secret      hexBytes
	Ciphertext  hexBytes
}

// RSALabeledEncapsulation iterates the RSA Labeled Encapsulation test cases.
func RSALabeledEncapsulation(t *testing.T) []RSALabeledEncapsTestCase {
	t.Helper()

	var testCases []RSALabeledEncapsTestCase
	if err := json.Unmarshal(rsaLabeledEncapsJSON, &testCases); err != nil {
		t.Fatalf("could not unmarshal JSON: %v", err)
	}

	return testCases
}