Skip to content

curve25519.c does not conform to the coding standards #7698

Closed

Description

@mattcaswell

While developing the fix in #7697 I noticed that the curve25519.c file does not conform to the coding standards - most obviously the indentation is wrong and functions have { on the end of the line instead of the next line.

Activity

  1. kaduk commented on Dec 1, 2018

    @kaduk
    Contributor

    From the history it looks like an import from Boring, and never got a full restyling.
    I could see arguments both for and against keeping it that way.

  2. mattcaswell commented on Dec 1, 2018

    @mattcaswell
    MemberAuthor

    We used to have a different style in every file and it was a nightmare. I think it should be fixed.

  3. t-j-h commented on Dec 1, 2018

    @t-j-h
    Member

    It must be fixed. We have a coding style for a reason. Run it through the script to fix up.

  4. mspncp commented on Dec 2, 2018

    @mspncp
    Contributor

    FWIW: I tried openssl-format-source and it should be used with care. The tool might be helpful a little with the indentation of the function bodies, but many of the other whitespace changes are more harmful than helpful. For example, it destroys this artful (and helpful) matrix structure in fe_mul() and turns it into a mess:

    openssl/crypto/ec/curve25519.c

    Lines 1140 to 1149 in 9b1c0e0

    int64_t h0 = f0g0+f1g9_38+f2g8_19+f3g7_38+f4g6_19+f5g5_38+f6g4_19+f7g3_38+f8g2_19+f9g1_38;
    int64_t h1 = f0g1+f1g0 +f2g9_19+f3g8_19+f4g7_19+f5g6_19+f6g5_19+f7g4_19+f8g3_19+f9g2_19;
    int64_t h2 = f0g2+f1g1_2 +f2g0 +f3g9_38+f4g8_19+f5g7_38+f6g6_19+f7g5_38+f8g4_19+f9g3_38;
    int64_t h3 = f0g3+f1g2 +f2g1 +f3g0 +f4g9_19+f5g8_19+f6g7_19+f7g6_19+f8g5_19+f9g4_19;
    int64_t h4 = f0g4+f1g3_2 +f2g2 +f3g1_2 +f4g0 +f5g9_38+f6g8_19+f7g7_38+f8g6_19+f9g5_38;
    int64_t h5 = f0g5+f1g4 +f2g3 +f3g2 +f4g1 +f5g0 +f6g9_19+f7g8_19+f8g7_19+f9g6_19;
    int64_t h6 = f0g6+f1g5_2 +f2g4 +f3g3_2 +f4g2 +f5g1_2 +f6g0 +f7g9_38+f8g8_19+f9g7_38;
    int64_t h7 = f0g7+f1g6 +f2g5 +f3g4 +f4g3 +f5g2 +f6g1 +f7g0 +f8g9_19+f9g8_19;
    int64_t h8 = f0g8+f1g7_2 +f2g6 +f3g5_2 +f4g4 +f5g3_2 +f6g2 +f7g1_2 +f8g0 +f9g9_38;
    int64_t h9 = f0g9+f1g8 +f2g7 +f3g6 +f4g5 +f5g4 +f6g3 +f7g2 +f8g1 +f9g0 ;

    So most of the changes it introduces must be carefully reviewed. Many of them need to be reverted and redone manually.

  5. levitte commented on Dec 2, 2018

    @levitte
    Member

    It's always possible to wrap "artful" sections with /**INDENT-OFF**/ and /**INDENT-ON**/
    I suggest doing so.

  6. mspncp commented on Dec 2, 2018

    @mspncp
    Contributor

    Sure, one could do that. But apart from that I'm not sure whether the script still reflects our current coding standards. Just running it on crypto/ec yields a lot of diffs...

     crypto/ec/curve25519.c                       | 8994 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------
     crypto/ec/curve448/arch_32/arch_intrinsics.h |    4 +-
     crypto/ec/curve448/arch_32/f_impl.h          |    2 +-
     crypto/ec/curve448/curve448.c                |   56 +-
     crypto/ec/curve448/curve448_lcl.h            |    2 +-
     crypto/ec/curve448/curve448_tables.c         | 1244 ++++++++++++-------
     crypto/ec/curve448/curve448utils.h           |    4 +-
     crypto/ec/curve448/ed448.h                   |   85 +-
     crypto/ec/curve448/eddsa.c                   |  105 +-
     crypto/ec/curve448/f_generic.c               |    7 +-
     crypto/ec/curve448/field.h                   |   15 +-
     crypto/ec/curve448/point_448.h               |   12 +-
     crypto/ec/curve448/scalar.c                  |   54 +-
     crypto/ec/curve448/word.h                    |    2 +-
     crypto/ec/ec2_oct.c                          |    3 +-
     crypto/ec/ec2_smpl.c                         |   42 +-
     crypto/ec/ec_ameth.c                         |    9 +-
     crypto/ec/ec_asn1.c                          |   79 +-
     crypto/ec/ec_curve.c                         | 3967 +++++++++++++++++++++++++++++-------------------------------
     crypto/ec/ec_err.c                           |   46 +-
     crypto/ec/ec_key.c                           |   11 +-
     crypto/ec/ec_kmeth.c                         |  166 ++-
     crypto/ec/ec_lcl.h                           |  100 +-
     crypto/ec/ec_lib.c                           |   33 +-
     crypto/ec/ec_oct.c                           |    3 +-
     crypto/ec/ecdh_kdf.c                         |    3 +-
     crypto/ec/ecdsa_ossl.c                       |    3 +-
     crypto/ec/ecdsa_sign.c                       |    6 +-
     crypto/ec/eck_prn.c                          |   15 +-
     crypto/ec/ecp_mont.c                         |   11 +-
     crypto/ec/ecp_nist.c                         |    8 +-
     crypto/ec/ecp_nistp224.c                     |  254 ++--
     crypto/ec/ecp_nistp256.c                     |   47 +-
     crypto/ec/ecp_nistp521.c                     |  409 +++----
     crypto/ec/ecp_nistputil.c                    |    3 +-
     crypto/ec/ecp_oct.c                          |    3 +-
     crypto/ec/ecp_smpl.c                         |   34 +-
     crypto/ec/ecx_meth.c                         |   35 +-
     38 files changed, 8154 insertions(+), 7722 deletions(-)
    
  7. levitte commented on Dec 2, 2018

    @levitte
    Member

    BTW, it's recommended to run the script with -c, which is kinder to comments

  8. levitte commented on Dec 2, 2018

    @levitte
    Member

    ... also, i've been pondering for a while if we shouldn't use something other than indent... there are better indenters these days...

  9. levitte commented on Dec 2, 2018

    @levitte
    Member

    I just ran the script on crypto/ec, and the result is not only messy, but wrong in some places. When I see this kind of crap, it's definitely time to look at hand editing...

    +      {FIELD_LITERAL(0x00303cda6feea532, 0x00860f1d5a3850e4, 0x00226b9fa4728ccd,
    +                     0x00e822938a0a0c0c, 0x00263a61c9ea9216, 0x001204029321b828,
    +                     0x006a468360983c65, 0x0002846f0a782143)},
    +      {FIELD_LITERAL(0x00303cda6feea532, 0x00860f1d5a3850e4, 0x00226b9fa4728ccd,
    +                     0x006822938a0a0c0c, 0x00263a61c9ea9215, 0x001204029321b828,
    +                     0x006a468360983c65, 0x0082846f0a782143)},
    +      {FIELD_LITERAL(0x00ef8e22b275198d, 0x00b0eb141a0b0e8b, 0x001f6789da3cb38c,
    +                     0x006d2ff8ed39073e, 0x00610bdb69a167f3, 0x00571f306c9689b4,
    +                     0x00f557e6f84b2df8, 0x002affd38b2c86db)},
    +      }}, {{
    +            {FIELD_LITERAL
    +             (0x00cea0fc8d2e88b5, 0x00821612d69f1862, 0x0074c283b3e67522,
    +              0x005a195ba05a876d, 0x000cddfe557feea4, 0x008046c795bcc5e5,
    +              0x00540969f4d6e119, 0x00d27f96d6b143d5)},
    +            {FIELD_LITERAL
    +             (0x000c3b1019d474e8, 0x00e19533e4952284, 0x00cc9810ba7c920a,
    +              0x00f103d2785945ac, 0x00bfa5696cc69b34, 0x00a8d3d51e9ca839,
    +              0x005623cb459586b9, 0x00eae7ce1cd52e9e)},
    +            {FIELD_LITERAL
    +             (0x0005a178751dd7d8, 0x002cc3844c69c42f, 0x00acbfe5efe10539,
    +              0x009c20f43431a65a, 0x008435d96374a7b3, 0x009ee57566877bd3,
    +              0x0044691725ed4757, 0x001e87bb2fe2c6b2)},
    +            }}, {{
    +                  {FIELD_LITERAL
    +                   (0x000cedc4debf7a04, 0x002ffa45000470ac, 0x002e9f9678201915,
    +                    0x0017da1208c4fe72, 0x007d558cc7d656cb, 0x0037a827287cf289,
    +                    0x00142472d3441819, 0x009c21f166cf8dd1)},
    +                  {FIELD_LITERAL
    +                   (0x003ef83af164b2f2, 0x000949a5a0525d0d, 0x00f4498186cac051,
    +                    0x00e77ac09ef126d2, 0x0073ae0b2c9296e9, 0x001c163f6922e3ed,
    +                    0x0062946159321bea, 0x00cfb79b22990b39)},
    +                  {FIELD_LITERAL
    +                   (0x00b001431ca9e654, 0x002d7e5eabcc9a3a, 0x0052e8114c2f6747,
    +                    0x0079ac4f94487f92, 0x00bffd919b5d749c, 0x00261f92ad15e620,
    +                    0x00718397b7a97895, 0x00c1443e6ebbc0c4)},
    +                  }}, {{
    +                        {FIELD_LITERAL(0x00eacd90c1e0a049, 0x008977935b149fbe,
    +                                       0x0004cb9ba11c93dc, 0x009fbd5b3470844d,
    +                                       0x004bc18c9bfc22cf, 0x0057679a991839f3,
    +                                       0x00ef15b76fb4092e, 0x0074a5173a225041)},
    +                        {FIELD_LITERAL(0x003f5f9d7ec4777b, 0x00ab2e733c919c94,
    +                                       0x001bb6c035245ae5, 0x00a325a49a883630,
    +                                       0x0033e9a9ea3cea2f, 0x00e442a1eaa0e844,
    +                                       0x00b2116d5b0e71b8, 0x00c16abed6d64047)},
    +                        {FIELD_LITERAL(0x00c560b5ed051165, 0x001945adc5d65094,
    +                                       0x00e221865710f910, 0x00cc12bc9e9b8ceb,
    +                                       0x004faa9518914e35, 0x0017476d89d42f6d,
    +                                       0x00b8f637c8fa1c8b, 0x0088c7d2790864b8)},
    +                        }}, {{
    +                              {FIELD_LITERAL
    +                               (0x00ef7eafc1c69be6, 0x0085d3855778fbea,
    
  10. mspncp commented on Dec 2, 2018

    @mspncp
    Contributor

    That‘s what I meant.

  11. mspncp commented on Dec 2, 2018

    @mspncp
    Contributor

    I can give it a try with emacs‘ indent-region, whitespace-cleanup, and a little manual editing, if you give me one or two days. Of course you can do it yourself, if you prefer.

  12. levitte commented on Dec 2, 2018

    @levitte
    Member

    I have a gazillion things on my plate, so if you're willing, I'll take it!

  13. mspncp commented on Dec 3, 2018

    @mspncp
    Contributor

    Please take a look at #7750.

  14. mspncp commented on Dec 6, 2018

    @mspncp
    Contributor

    Note: The cherry-pick to 1.1.1 had a conflict which still needs to be resolved. I was interrupted in the middle of doing it.

  15. added a commit that references this issue on Dec 6, 2018
    6a1ed7a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions