Skip to content

Clarify the bit shift in gfp_little_endian_bytes_from_scalar. - #248

Closed
Ms2ger wants to merge 1 commit into
briansmith:masterfrom
Ms2ger:bitshift
Closed

Ms2ger wants to merge 1 commit into
briansmith:masterfrom
Ms2ger:bitshift

Conversation

@Ms2ger

@Ms2ger Ms2ger commented Jul 11, 2016

Copy link
Copy Markdown
Contributor

The bitshift-assignment in the middle of an expression is
unneccesarily confusing, and in any case is not necessary if BN_BYTES
is not 8.

I agree to license my contributions to each file under the terms given
at the top of each file I changed.

@coveralls

coveralls commented Jul 11, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.5%) to 88.351% when pulling 18b532126106a68cd8e734eb4b4fff03bdb85dd7 on Ms2ger:bitshift into 9a468a7 on briansmith:master.

The bitshift-assignment in the middle of an expression is
unneccesarily confusing, and in any case is not necessary if BN_BYTES
is not 8.

I agree to license my contributions to each file under the terms given
at the top of each file I changed.
@coveralls

coveralls commented Jul 12, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 88.816% when pulling 2319ca4 on Ms2ger:bitshift into 9a468a7 on briansmith:master.

Comment thread crypto/ec/ecp_nistz.c
str[i + 7] = (d >> 24) & 0xff;
}
str[i + 3] = (d >> 24) & 0xff;
#if BN_BYTES == 8

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hi. AGL decided that we should avoid #if in favor of using if in these situations. I don't know if it is in the official style guide or not. Basically, we only use the preprocessor the minimal amount.

Otherwise, I agree with the main part of your change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That was what I did first, but then you get a warning-as-error about shifting by the width of the integer. I could try to trick that warning if you prefer.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I see.

Let's zoom out a bit. In the Rust code, we store private keys as arrays of bytes already. For P-256 and P-384, we store them in big-endian order, for Curve25519 we store them in little-endian order. For P-256 and P-384, we take the big-endian byte arrays and convert them to an array of Limbs (Limb == GFp_Limb == BN_ULONG). Then, this function converts them into a little-endian byte array. So, you see, it is circuitous.

In the p384 branch, I have new code that builds on this code. And, in the upcoming ecdsa_verify branch I will have more code to make it easier to switch the callers of this code to pass in byte arrays instead of Limb arrays. So, it doesn't look like this code will have a long life. Maybe we should just leave it as it is, and wait for this grossness to die a natural death?

(FWIW, this isn't new code, but instead code that was inherited from BoringSSL & OpenSSL.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That works for me.

@briansmith

Copy link
Copy Markdown
Owner

OK, I'm going to close this. The discussion above showed why the code is the way it is; it's basically an unfortunate artifact of the BoringSSL coding style. I don't think it's worth changing just this little bit, especially because I expect soon we'll be able to get rid of this function completely.

@briansmith briansmith closed this Jul 24, 2016
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.

3 participants