2023-04-28 23:36:17

by Eric Biggers

[permalink] [raw]
Subject: Re: [PATCH 1/3] crypto: LEA block cipher implementation

Hi Dongsoo,

On Fri, Apr 28, 2023 at 08:00:56PM +0900, Dongsoo Lee wrote:
> The LEA is a Korean national standard block cipher, described in
> "KS X 3246" and is also included in the international standard, "ISO/IEC
> 29192-2:2019 standard (Information security - Lightweight cryptography
> - Part 2: Block ciphers)".
>
> The LEA algorithm is a symmetric key cipher that processes data blocks
> of 128-bits and has three different key lengths, each with a different
> number of rounds:
>
> - LEA-128: 128-bit key, 24 rounds,
> - LEA-192: 192-bit key, 28 rounds, and
> - LEA-256: 256-bit key, 32 rounds.
>
> The round function of LEA consists of 32-bit ARX(modular Addition,
> bitwise Rotation, and bitwise XOR) operations.
>
> The implementation same as submitted generic C implementation is
> distributed through the Korea Internet & Security Agency (KISA).
>
> - https://seed.kisa.or.kr/kisa/algorithm/EgovLeaInfo.do
> - https://seed.kisa.or.kr/kisa/Board/20/detailView.do
>
> Signed-off-by: Dongsoo Lee <[email protected]>
> ---
> crypto/Kconfig | 12 +
> crypto/Makefile | 1 +
> crypto/lea_generic.c | 915 +++++++++++++++++++++++++++++++++++++++++++
> include/crypto/lea.h | 39 ++
> 4 files changed, 967 insertions(+)
> create mode 100644 crypto/lea_generic.c
> create mode 100644 include/crypto/lea.h

This implementation is very ugly. There's no need to unroll all the rounds in
the source code as you're doing. It also makes it very difficult to check the
implementation against the original paper.

I happened to write an LEA implementation several years ago, and IMO it's much
cleaner than this one. It's less than half the lines of code, despite having a
lot more comments. I also implemented (and documented) some optimizations, some
of which were recommended in the original LEA paper, IIRC. Maybe you'd like to
take a look at my implementation for some ideas, or even just use it outright?
You can get it from here:
https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/commit/?h=old/wip-lea&id=1d1cbba14380f8a1abc76baf939b9e51de047fb6

- Eric