libtomcrypt icon indicating copy to clipboard operation
libtomcrypt copied to clipboard

Stream functions in separate files

Open buggywhip opened this issue 7 years ago • 4 comments

Some stream ciphers had multiple functions in a file. This PR breaks each callable function out into separate files. Common declarations and some definitions unique to that cipher will be found in a separate local .h file for that cipher. Some guards were added to avoid warnings. Leading underscores were added to the names of sober128's helper functions.

Checklist

  • [ N/A ] documentation is added or updated
  • [ N/A ] tests are added or updated

buggywhip avatar Oct 15 '18 01:10 buggywhip

I suggest just keeping separate NN_memory, NN_test, NN_keystream and perhaps NN_done like:

Old style                         This PR                                  Karel's suggestion 
================================= =======================================  ====================================
rabbit/rabbit.c                                                            rabbit/rabbit.c
                                  rabbit/rabbit_common.h                  
                                  rabbit/rabbit_setup.c                   
                                  rabbit/rabbit_setiv.c                   
                                  rabbit/rabbit_crypt.c                   
                                  rabbit/rabbit_done.c                    +rabbit/rabbit_done.c
                                  rabbit/rabbit_keystream.c               +rabbit/rabbit_keystream.c
rabbit/rabbit_memory.c            rabbit/rabbit_memory.c                   rabbit/rabbit_memory.c
                                  rabbit/rabbit_test.c                    +rabbit/rabbit_test.c
================================= =======================================  ====================================
rc4/rc4_stream.c                                                           rc4/rc4_stream.c
                                  rc4/rc4_stream_setup.c                  
                                  rc4/rc4_stream_crypt.c                   
                                  rc4/rc4_stream_done.c                   +rc4/rc4_stream_done.c
                                  rc4/rc4_stream_keystream.c              +rc4/rc4_stream_keystream.c
rc4/rc4_stream_memory.c           rc4/rc4_stream_memory.c                  rc4/rc4_stream_memory.c
rc4/rc4_test.c                    rc4/rc4_test.c                           rc4/rc4_test.c
================================= =======================================  ====================================
sober128/sober128_stream.c                                                 sober128/sober128_stream.c
                                  sober128/sober128_stream_common.h       
                                  sober128/sober128_stream_setup.c        
                                  sober128/sober128_stream_setiv.c        
                                  sober128/sober128_stream_crypt.c        
                                  sober128/sober128_stream_done.c         +sober128/sober128_stream_done.c
                                  sober128/sober128_stream_keystream.c    +sober128/sober128_stream_keystream.c
sober128/sober128_stream_memory.c sober128/sober128_stream_memory.c        sober128/sober128_stream_memory.c
sober128/sober128_test.c          sober128/sober128_test.c                 sober128/sober128_test.c
sober128/sober128tab.c            sober128/sober128tab.c                   sober128/sober128tab.c
================================= =======================================  ====================================
sosemanuk/sosemanuk.c                                                      sosemanuk/sosemanuk.c
                                  sosemanuk/sosemanuk_common.h            
                                  sosemanuk/sosemanuk_setup.c             
                                  sosemanuk/sosemanuk_setiv.c             
                                  sosemanuk/sosemanuk_crypt.c             
                                  sosemanuk/sosemanuk_done.c              +sosemanuk/sosemanuk_done.c
                                  sosemanuk/sosemanuk_keystream.c         +sosemanuk/sosemanuk_keystream.c
sosemanuk/sosemanuk_memory.c      sosemanuk/sosemanuk_memory.c             sosemanuk/sosemanuk_memory.c
sosemanuk/sosemanuk_test.c        sosemanuk/sosemanuk_test.c               sosemanuk/sosemanuk_test.c
================================= =======================================  ====================================

karel-m avatar Nov 06 '18 21:11 karel-m

plus perhaps also get rid of sober128tab.c

karel-m avatar Nov 06 '18 21:11 karel-m

On 6Nov, 2018, at 1:47 PM, karel-m [email protected] wrote: I suggest just keeping separate NN_memory, NN_test, NN_keystream and perhaps NN_done like:

[snip]

After careful consideration I'm leaning toward each callable function in its own file for reasons of consistency. IMO there is not sufficient advantage to combining some functions, each cipher differently, when some optional and sometine required functions need to be called out for linking individually. For example, the inconsistent model for...

streams combining _setup(), setiv(), and _crypt(): rabbit, sober128, sosemanuk streams combining _setup(),and _crypt(): rc4 streams combining none: chacha, (x)salsa20

...requires calling out what you need that wasn't combined. Confusing.

Implementing the PR as written makes the decision rule consistent, "if you call it, link it".

buggywhip avatar Nov 11 '18 06:11 buggywhip

I see your point but to me this is "over-consistent" for no (or very little) gain.

Anyway, I am strongly against introducing new headers - <something>_common.h. I suggest either to merge those .c files sharing the same <something>_common.h header (which I prefer) or perhaps to use tomcrypt_private.h (but I somehow feel that @sjaeckel might not like it as it may not comply with the original tomcrypt_private.h idea).

karel-m avatar Nov 30 '18 20:11 karel-m