Skip to content

bug: hash algorithm defaults to SHA256 for most algorithms #628

@mrjoelkamp

Description

@mrjoelkamp

I am using tuf-on-ci and running into issues when the key scheme is ecdsa-sha2-nistp384 (worth noting that these tests aren't failing when using the python tuf client)

I've root caused the issue to the hash algorithm basically hardcoded to use SHA256 here:

go-tuf/metadata/metadata.go

Lines 312 to 316 in 48216cf

// use corresponding hash function for key type
hash := crypto.Hash(0)
if key.Type != KeyTypeEd25519 {
hash = crypto.SHA256
}

It looks like mainly the 256-bit curves are supported here but with a slight change this would also support ECDSA P384.

I've modified this code to the following locally and clear the error using ecdsa-sha2-nistp384 as the key scheme:

// use corresponding hash function for key type
hash := crypto.Hash(0)
if key.Type != KeyTypeEd25519 {
	switch key.Scheme {
	case KeySchemeECDSA_SHA2_P256:
		hash = crypto.SHA256
	case KeySchemeECDSA_SHA2_P384:
		hash = crypto.SHA384
	default:
		hash = crypto.SHA256
	}
}

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