Skip to content

Incorrect HOST_ID input to cSHAKE128 #10

Description

@kc2rxo

Looking at RFC9374, the hash input is defined as follows:

cSHAKE128(Input, L, "", Context ID)

Input      :=  Prefix | Additional Information | OGA ID | HOST_ID
L          :=  Length in bits of the hash portion of ORCHID

The combination of Prefix | Additional Information | OGA ID are implemented as the variable h_orchid_left in det_orchid().

HOST_ID is, per RFC9374, defined as:

   0                   1                   2                   3
   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |         EdDSA Curve           |             NULL              |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  |                         Public Key                            |
  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

In det_orchid() the call

shake.update((h_orchid_left + hi))

with hi = prkey.public_key().export_key(format="raw") does not match the Input for cSHAKE128 as the HOST_ID is missing both the 2-byte EdDSA Curve enumeration and 2-bytes of null padding before the public key (hi).

The correct call is: shake.update((h_orchid_left + bytes([0, 1, 0, 0]) + hi)) -- assuming the EdDSA Curve in use for this script is always Ed25519, enumerated as the value of 1.

@rgmhtt please confirm.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingquestionFurther information is requested

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions