Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose signature.Signer hash algorithm #860

Open
tri-adam opened this issue Dec 12, 2022 · 3 comments
Open

Expose signature.Signer hash algorithm #860

tri-adam opened this issue Dec 12, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@tri-adam
Copy link

Description

I'd like to obtain the hash algorithm used by a signature.Signer. I have a use case where the caller passes me a signature.Signer and I need to generate a signature and then wrap it in a descriptor that includes the hash algorithm. The implementation currently ignores the value in the signature.Signer to get around the fact that this value isn't exposed (sylabs/sif#249).

I appreciate that signature.Signer itself can't be extended without breaking v1 module compatibility, but I'm wondering whether concrete types that implement it such as ED25519Signer could expose the hash algorithm, by implementing crypto.SIgnerOpts or similar? If that would be acceptable, I'd be happy to submit a PR for that.

Thanks!

@tri-adam tri-adam added the enhancement New feature or request label Dec 12, 2022
@znewman01
Copy link
Contributor

znewman01 commented Dec 21, 2022

I have no objections to a PR adding SignerOpts to the concrete Signer types.

CC @haydentherapper any thoughts?

EDIT: I forgot to how the signature.Signer API worked, please disregard

@haydentherapper
Copy link
Contributor

Currently, the hash function is specified per signing (invocation of Sign or SignMessage), not per Signer. Is this proposing allowing you to set the hash function once for the Signer?

@znewman01
Copy link
Contributor

Oh, that's a great point. There's a number of related features here:

  • Signer.SignMessage takes a SignOption:

    SignMessage(message io.Reader, opts ...SignOption) ([]byte, error)

    which AFAICT doesn't directly let you change the hash function used. It does let you provide a digest directly instead of a message:
    ApplyDigest(*[]byte)

    In some cases, Signers have only one specific hash function; ECDSASigner is a good example:

    type ECDSASigner struct {
    hashFunc crypto.Hash
    priv *ecdsa.PrivateKey
    }

    In other cases, however, the Signers do not (e.g., kms/gcp.SignerVerifier):
    signerOpts, err = g.client.getHashFunc()

    I see no reason why we couldn't implement SignerOpts in the former case.

  • There's a struct signature.SignerOpts which implements crypto.SignerOpts but additionally lets you change the hash function used:

    // HashFunc returns the hash function for this object
    func (s SignerOpts) HashFunc() crypto.Hash {
    return s.Hash
    }

    There are a number of structs in sigstore/sigstore that implement crypto.Signer including the Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) interface. These can be used with signature.SignOpts to tweak the hash function. These structs don't have a defined hash function to use.

IIUC the FR, it's to expose the crypto.Hash used in cases where the hash function is hardcoded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants