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

Keep HMAC case consistent #547

Merged
merged 1 commit into from
Feb 18, 2020
Merged

Conversation

OrfeasLitos
Copy link
Contributor

Change HMAC to lowercase in packet description, as it later appears in
lowercase. The uppercase version is used in the hops_data, so this
change helps avoid confusion.

Copy link
Collaborator

@sstone sstone left a comment

Choose a reason for hiding this comment

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

It would then be consistent to also use hmac instead of HMAC in the description of hops_data.

@OrfeasLitos
Copy link
Contributor Author

I couldn't find the exact spot, can you tell me the line?

@sstone
Copy link
Collaborator

sstone commented Jan 19, 2019

In the description of hops_data lines 171/175 we still have HMAC, it would be more consistent to use hmac here as well.

@OrfeasLitos
Copy link
Contributor Author

I was suggesting to use hmac for the single last HMAC at the end of an onion_packet and HMAC for each of the many HMACs that appear within hops_data. Do you suggest to change all HMAC occurrences to hmac instead?

Observe that the HMAC of lines 171 and 175 is of the kind that is within hops_data, hence according to the proposed convention it should remain uppercase.

@sstone
Copy link
Collaborator

sstone commented Jan 20, 2019

Yes I'm suggesting it's consistent to use lowercase here as well (we use lowercase for field names everywhere else).

@OrfeasLitos
Copy link
Contributor Author

In that case, would you consider some other way for differentiating the two kinds of HMAC, e.g. hop_hmac and packet_hmac? This is consistent with lowercase field names and helps differentiate the two kinds of HMAC, thus reducing confusion. Sorry for my insistence, but the point of this PR is to help the reader tell the two kinds of HMAC apart easily.

@sstone
Copy link
Collaborator

sstone commented Jan 20, 2019

Sorry for my insistence, but the point of this PR is to help the reader tell the two kinds of HMAC apart easily.

Yes but I don't think it's needed, though fixing naming inconsistencies may be useful. This part of the spec is fairly technical and probably harder to understand than other BOLTs but I don't think that people trying to implement it would get confused by the packet/hop data HMAC fields having the same name.

In other words, for me using lowercase for the hmac fields -> ACK, having hmac for one field and HMAC for the other -> NACK

@OrfeasLitos
Copy link
Contributor Author

Ok, I just changed all fields to lowercase hmac.

@TheBlueMatt
Copy link
Collaborator

IRC discussion indicated most folks prefer upper-case for cryptographic primitives, especially when they're acronyms.

@OrfeasLitos
Copy link
Contributor Author

Fixed

@OrfeasLitos
Copy link
Contributor Author

All HMAC are uppercase now, ready to merge

@niftynei niftynei added the spelling These changes may be merged without additional sign off from the weekly meeting label Jan 6, 2020
Copy link
Collaborator

@niftynei niftynei left a comment

Choose a reason for hiding this comment

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

also NACK'ing this; is inconsistent with all other field names.

@t-bast
Copy link
Collaborator

t-bast commented Jan 7, 2020

NACK too, I prefer consistency here.

@OrfeasLitos
Copy link
Contributor Author

@niftynei @t-bast what do you suggest? Summarizing options:

  • All HMAC fields lowercase
  • All HMAC fields uppercase
  • Lowercase for HMAC at the end of onion_packet, uppercase for HMAC in hop_payload (or vice-versa)
  • Rename fields to onion_hmac and hop_hmac (distinguishes two HMACs, keeps lowercase)
  • Any other ideas?

@t-bast
Copy link
Collaborator

t-bast commented Jan 7, 2020

I would not change anything (keep all hmac fields lowercase). I honestly didn't find this confusing when implementing.

@OrfeasLitos
Copy link
Contributor Author

Currently not all fields are lowercase. Initially this PR was just for lowercasing the HMAC of line (currently) 135, to make it consistent with line 149. Then we realized that there is a bigger inconsistency, e.g. line 160.

Given that a change is needed, we may as well choose something unambiguous for field names (I got confused when I first read this). My recommendation is to change the field names to onion_hmac and hop_hmac so that it is clear which HMAC authenticates what.

@t-bast
Copy link
Collaborator

t-bast commented Jan 7, 2020

Indeed, I didn't notice that in some struct fields it's upper-case.
My personal choice would be to have it lower-case in message types to be consistent with other fields in those types.

I don't like renaming those, I think it's more confusing: these macs always authenticate the whole onion. The outer one authenticates the onion before decryption, the inner one authenticates the new onion you obtain after decryption (the onion you will forward to the next node). Does that make sense?

@OrfeasLitos
Copy link
Contributor Author

Good point, those names would be confusing. I therefore support lowercasing all fields. @TheBlueMatt maybe the objections from IRC are now obsolete? Or are there still folks that prefer HMAC as a field name? (Note that I'm not referring to the use of the word outside backticks, there it will be kept uppercase "HMAC".)

Change `hmac` to `HMAC` fields in packet description to keep consistent
with the convention of uppercase cryptographic acronym field names
@OrfeasLitos
Copy link
Contributor Author

I changed all "HMAC"s to "hmac", ready to merge.

Copy link
Collaborator

@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

Thanks, ACK e3fc992.

@t-bast t-bast merged commit a2afdfd into lightning:master Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spelling These changes may be merged without additional sign off from the weekly meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants