google / google/go-tpm-tools

Will there be support for SM2 and SM4 algo?

Open
#564 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
307
Forks
118
Avg merge
1d 16h
Merged PRs (30d)
33

Description

I have tried hardcoding algo ids for tpm2.Public template but still unable to create sm2 curve ECC primary key on windows 11

```
fmt.Fprintf(debugOutput(), "Start\n")
_, public, _, _, _, err := tpm2.CreateKey(rwc, key.Handle(), tpm2.PCRSelection{}, "", "", AKTemplateECC())
if err != nil {
fmt.Fprintf(debugOutput(), "failed to create key: %w\n", err)
} else {
fmt.Fprintf(debugOutput(), "%s\n", public)
}
fmt.Fprintf(debugOutput(), "End\n")

func AKTemplateECC() tpm2.Public {
return tpm2.Public{
Type: tpm2.AlgECC,
NameAlg: 0x0012, //SM3
Attributes: tpm2.FlagRestricted | tpm2.FlagSign | tpm2.FlagFixedTPM | tpm2.FlagFixedParent | tpm2.FlagSensitiveDataOrigin | tpm2.FlagUserWithAuth,
ECCParameters: &tpm2.ECCParams{
CurveID: tpm2.CurveSM2P256, //SM2
Symmetric: &tpm2.SymScheme{
Alg: 0x0013, //SM4
KeyBits: 128,
Mode: tpm2.AlgCFB,
},
Sign: &tpm2.SigScheme{
Alg: tpm2.AlgNull,
Hash: tpm2.AlgNull,
},
KDF: &tpm2.KDFScheme{
Alg: tpm2.AlgNull,
Hash: tpm2.AlgNull,
},
},
}
}
```

error shown as below:
```
PS source\repos\go-tpm-tools\cmd\gotpm> .\gotpm.exe pubkey owner --algo ecc --verbose
Using hierarchy 0x40000001
Start
failed to create key: %!w(tpm2.HandleError={3 0})
End
PS source\repos\go-tpm-tools\cmd\gotpm>
```

Contributor guide

Open the contributing guide

Research direction

Start at the gotpm pubkey owner command and trace its use of tpm2.CreateKey with the AKTemplateECC template. Check how tpm2.Public represents the SM2 curve, SM3 name algorithm, and SM4 symmetric scheme, then reproduce the Windows 11 failure shown in the issue. Done should establish whether these algorithms can be supported and identify the required project changes or limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cryptography, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.