Skip to content

Will there be support for SM2 and SM4 algo? #564

@hksfho

Description

@hksfho

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions