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

ckem: pass xof to elliptic.GenerateKey directly #403

Merged
merged 1 commit into from Feb 16, 2023
Merged

Conversation

bwesterb
Copy link
Member

No description provided.

Copy link
Contributor

@Lekensteyn Lekensteyn left a comment

Choose a reason for hiding this comment

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

Change looks reasonable, perhaps the commit message could include a further motivation.

_, _ = h.Read(buf)
rnd := bytes.NewReader(buf)
key, x, y, err := elliptic.GenerateKey(sch.curve, rnd)
key, x, y, err := elliptic.GenerateKey(sch.curve, h)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a bugfix? Previously, only enough randomness was provided for exactly one "private key". After this change, it could sample another key if the first secret was invalid:

func GenerateKey(curve Curve, rand io.Reader) (priv []byte, x, y *big.Int, err error) {
	N := curve.Params().N
	bitSize := N.BitLen()
	byteLen := (bitSize + 7) / 8
	priv = make([]byte, byteLen)

	for x == nil {
		_, err = io.ReadFull(rand, priv)
// ...
		// If the scalar is out of range, sample another random number.
		if new(big.Int).SetBytes(priv).Cmp(N) >= 0 {
			continue
		}

		x, y = curve.ScalarBaseMult(priv)
	}

For reference, sch.PrivateKeySize() ends up with the same size:

func (sch *cScheme) scSize() int {
	return (sch.curve.Params().N.BitLen() + 7) / 8
}
// ...
func (sch *cScheme) PrivateKeySize() int {
	return sch.scSize()
}

@bwesterb bwesterb merged commit d5f5e29 into main Feb 16, 2023
@bwesterb bwesterb deleted the bas/fix-ckem branch February 16, 2023 13:46
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.

None yet

2 participants