Skip to content

Export Signify methods, support BLAKE2s - #38

Open
mchack-work wants to merge 13 commits into
mainfrom
signify-methods
Open

Export Signify methods, support BLAKE2s#38
mchack-work wants to merge 13 commits into
mainfrom
signify-methods

Conversation

@mchack-work

@mchack-work mchack-work commented Feb 2, 2026

Copy link
Copy Markdown
Member

Description

  • Make Signify types like public key and signatures available externally, for instance for use in sign-tool, tkey-mgt, tkeyimage and the like. And, of course, external project who would like to read and write to these this kind of files.

  • Write methods to handle import and export more gracefully.

  • Add tests for signify methods.

  • Change the tkey-sign command accordingly.

  • Add support for choice of hash algoritm (-a flag)

  • Add support for BLAKE2s algorithm.

Fixes #36

See also:

Type of change

  • Feature (non breaking change which adds functionality)

Submission checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my changes
  • I have tested and verified my changes on target
  • My changes are well written and CI is passing
  • I have squashed my work to relevant commits and rebased on main for linear history
  • I have added a "Co-authored-by: x" if several people contributed, either pair programming or by squashing commits from different authors.
  • I have updated the documentation where relevant (readme, dev.tillitis.se etc.)
  • QEMU is updated to reflect changes

@mchack-work
mchack-work requested a review from agren February 2, 2026 21:26
@mchack-work
mchack-work force-pushed the signify-methods branch 3 times, most recently from 55951e6 to e1e3779 Compare February 3, 2026 12:15
@mchack-work
mchack-work force-pushed the signify-methods branch 3 times, most recently from d26286c to 2dd940a Compare February 4, 2026 15:29
@mchack-work mchack-work changed the title Export Signify methods Export Signify methods, support BLAKE2s Feb 4, 2026
@mchack-work
mchack-work marked this pull request as ready for review February 24, 2026 16:58
@mchack-work
mchack-work force-pushed the signify-methods branch 3 times, most recently from c251ce0 to 36039e8 Compare April 14, 2026 17:19
@mchack-work
mchack-work requested a review from dehanj April 14, 2026 17:20

@agren agren left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this and the signing functionality seems intact. I have a few comments on added functionality.

Comment thread signify/signify.go Outdated
func (p *PubKey) ToBuffer(comment string) ([]byte, error) {
signifyKey := signifyPubKey{
Alg: [2]uint8{'E', 'd'},
KeyNum: [8]uint8{0x1, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to hard code KeyNum here? Since we're exporting this for use elsewhere we should avoid to force it on the user if we can. So instead of setting KeyNum here we could set in cmd/tkey-sign.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably means we need to represent it in either the PubKey and Signature types in the signify package, too. What do you think?

AFAIU the KeyNum is basically just used as an extra check that a specific key pair corresponds to a certain signature.

I had a look at how the OpenBSD signify command generates it and handles it. It's in signify.c:generate():

	crypto_sign_ed25519_keypair(pubkey.pubkey, enckey.seckey);
	arc4random_buf(keynum, sizeof(keynum));

which means it's just some random numbers generated when the key pair is created.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have addresses this by adding support for KeyNum in the way both signify and minisign supports them.

See commit messages.

Comment thread signify/signify.go Outdated
return fmt.Errorf("%w", err)
}

if pubKey.Alg != [2]byte{'E', 'd'} || pubKey.KeyNum != [8]byte{1, 7} {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check seems new. AFAIK previous versions of tkey-sign doesn't expect KeyNum to be a specific value. Do we need to check it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the old tkey-sign the KeyNum was at least hardcoded to 1,7 when generating the files.

It's probably better to handle it some other way and make it visible in the types, as per the former comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. If the user has just a slice from, say, signer in TKey KeyNum will be randomized from NewPubKey(). If they want to set it themselves they have to instantiate a PubKey variable themselves. Documented in the function.

Comment thread cmd/tkey-sign/main.go Outdated
Comment thread cmd/tkey-sign/main.go Outdated
Comment thread cmd/tkey-sign/main.go Outdated
Comment thread cmd/tkey-sign/main.go Outdated
- Make public key and signatures available externally.

- Add methods to import and export these types to and from buffers and
  files.

- Add tests for parsing and generating.

- Move writeRetry() to util.go

- Signify uses "Ed", we use "Eb", indicating to us that our message
  should be hashed with BLAKE2s.
- Clean up the main function and hide the complexities of all the
  commands in their own functions. Also reduces the cyclomatic
  complexity.

- Hide some args, like device path, device speed, USS filename and
  request USS from user, in structs.
- Introduce new function getMessage() that produces the message to be
  signed or verified.

- Use message produced by getMessage() in Sign() and Verified() and
  dependent helper functions.
Choose hash algorithm to use with -a/--alg. Options are "ed" (default,
SHA-512) and "b2s" (BLAKE2s).
- The Digest takes Alg for algorithm. We change the getMessage() to
  getDigest() and set the alg type when calling. We pass a Digest around
  to all consumers, so we know the algorithm type all the way to export.

- Compare digest algo from command line with algo from sig file.
@mchack-work
mchack-work requested a review from agren June 23, 2026 15:55
@dehanj

dehanj commented Jul 3, 2026

Copy link
Copy Markdown
Member

Made a proof of concept to export the pubkey in binary format.

#48

- Don't repeat the manual page. Instead refer to it.

- Describe how tkey-sign differs in signing from signify.
In signify the KeyNum is used to associate a signature with a keypair.
Do the same thing here:

- When we get a public key from the Tkey, assign a random KeyNum and
  store in the public key file.
- When we do a signature, get the same KeyNum from the public key file
  we force the user to provide and store in the signature file.
- When verifying signatures, first compare the KeyNum in the public
  key file against what's in the signature file and bail early if
  they're different.

Change the type of signify.PubKey to a struct including a KeyNum both
to that and to Signature. We change the FromBuffer() and ToBuffer()
methods accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support BLAKE2s digests

3 participants