RFC 7539 - ChaCha20 and Poly1305 #171
No reviewers
Labels
No labels
bug
duplicate
enhancement
feature
help wanted
improve API
invalid
needs documentation
not-planned
rtfm
stale
support
wishlist
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libtom/libtomcrypt!171
Loading…
Reference in a new issue
No description provided.
Delete branch "pr/chacha20poly1305"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Basically the reference implementation adopted to our C macros and our calling conventions.
https://tools.ietf.org/html/rfc7539
as it's a stream cipher, would it make sense to integrate it in the prng environment as all the other stream ciphers?
or should we think about integrating resp. how to integrate the stream ciphers in the crypt environment?
or should we provide an alternative environment or re-think the entire approach?
what do you think about this?
In my opinion we shouldn't introduce new algorithms with
unsigned char*for in- or output data.I guess we should add a sanity check in the cleanup section
@ -0,0 +1,42 @@/* LibTomCrypt, modular cryptographic library -- Tom St Denisassignment please in a separate line
Ad
unsigned char*vs.void *I am not against that change but I prefer to make a BIG SWITCH and change all such cases in the whole libtomcrypt. Not just in a single function.I agree
@ -0,0 +1,42 @@/* LibTomCrypt, modular cryptographic library -- Tom St DenisI agree
Ad moving
chachaimplementation underprng:It would be probably logical to have all stream cipher in one place, however I am not a fan of the idea of having stream ciphers in
prngin general. It is IMO very confusing for newcomers and frankly speaking if you want to use RC4 or SOBER128 for encrypting/decrypting your first impression might be that libtomcrypt is not supporting it (users will be looking for a simplerc4_setup(key)>rc4_crypt(in, out)>rc4_crypt(in, out)>...interface which we do not have).We can create
src/streamand I can movesrc/cipher/chacha/*tosrc/stream/chacha/*What I would like more than current state of RC4 + SOBER128
src/stream/rc4.cand * havingsrc/stream/sober128.cwhich will provide cipher_setup/cipher_crypt interfacesrc/prngs/rc4.candsrc/prngs/sober128.cinto thin wrappers around the functions from previous pointLet's move
size_tdiscussion to #175 andunsigned char*vs.void *to #174 so that they do not block this PR.We have the following:
What's the best practice in these cases?
int poly1305_done(poly_state *st, unsigned char *mac, unsigned long *maclen)?int poly1305_done(poly_state *st, unsigned char *mac, unsigned long maclen)?int poly1305_done(poly_state *st, unsigned char *mac)?int poly1305_done(poly_state *st, unsigned char mac[16])?I'd say 1.
int poly1305_done(poly_state *st, unsigned char *mac, unsigned long *maclen)also I'd prefer
to use the established error codes
CRYPT_INVALID_ARGfor invalid buffer sizes like themaclenandCRYPT_INVALID_KEYSIZEin e.g.chacha_setup()et. al.to be less strict on these buffer sizes
so in
poly1305_done()it'd becomeinstead of
if (*maclen != 16) return CRYPT_ERROR;Ad
unsigned long outlenvs.unsigned long *outlenthere 3 more places I have found where we are not consistent (I'll create a separate issue)Agreed. IMO all stream ciphers would be better served under src/stream/, not under prng.
Many algorithms can be used in ways to produce output normally the province of other classes of algorithms, but without a formal ontology, a "typical"/"traditional" organization structure is probably best.
And it can get really messy trying to classify authenticated encryption. ...a unique classification by itself? ...a mode? Arrgghh. :-/
Rebased & squashed into 1 commit, travis-ci all green. I propose merging to develop.
@sjaeckel do you (dis)agree with merging this one?
Coverage decreased (-0.04%) to 87.44% when pulling 6ca293d6893b066f3396526d1a06b328e472ccb6 on pr/chacha20poly1305 into
4bcd48411aon develop.Can you please also add
@ -0,0 +1,45 @@/* LibTomCrypt, modular cryptographic library -- Tom St Denisassignment separate please
@ -0,0 +1,36 @@/* LibTomCrypt, modular cryptographic library -- Tom St Deniscan we probably test this as well?
@ -96,6 +96,26 @@ void pmac_shift_xor(pmac_state *pmac);I'd prefer
poly1305_state@ -477,6 +497,36 @@ int f9_test(void);also
chacha20poly1305_state@ -15,6 +15,15 @@ struct rc4_prng {};chacha20_prng@ -55,6 +64,9 @@ typedef union Prng_state {#ifdef LTC_RC4how about having a separate define
LTC_CHACHA20_PRNG?@ -0,0 +1,70 @@/* LibTomCrypt, modular cryptographic library -- Tom St Denisshould we make this 8196 somehow configurable/better?
by better I mean "can we easily get the pagesize of the running arch?" or similar
@ -0,0 +1,219 @@/* LibTomCrypt, modular cryptographic library -- Tom St DenisDid you follow some guide "how to use ChaCha as a prng" or is this all your work?
From my point of view it looks very good, but if you created this I'd like to have someone else with crypto expertise to review this code.
AFAIK the only unusual magic here is in
chacha_prng_add_entropy, either initially (before make_ready) and later (kind of rekey operation).The implementation (namely the rekey operation) is based on chacha-based arc4random implemented in OpenBSD/FreeBSD (I do not have a link handy but you can easily google it).
Seeing:
I am in doubts whether you have pulled (you might need
pull --force) the latest version as I have movedsrc/ciphers/chachatosrc/stream/chacha.simply
s/ciphers/stream/gin the diff and applying the patch is successful@ -0,0 +21,4 @@#ifndef LTC_TESTreturn CRYPT_NOP;#elseunsigned long len;why should we duplicate the same test-result?
@ -0,0 +1,45 @@/* LibTomCrypt, modular cryptographic library -- Tom St Denisdone
@ -0,0 +1,36 @@/* LibTomCrypt, modular cryptographic library -- Tom St Denisand perhaps also
chacha20poly1305_memory@ -0,0 +1,36 @@/* LibTomCrypt, modular cryptographic library -- Tom St DenisIf you're upto it, sure 👍
@ -0,0 +1,36 @@/* LibTomCrypt, modular cryptographic library -- Tom St Denisdone
@ -96,6 +96,26 @@ void pmac_shift_xor(pmac_state *pmac);done
@ -477,6 +497,36 @@ int f9_test(void);done
@ -15,6 +15,15 @@ struct rc4_prng {};done
@ -55,6 +64,9 @@ typedef union Prng_state {#ifdef LTC_RC4done
Coverage increased (+0.2%) to 87.666% when pulling e969a10bd92410c34d5ef134b5e4f61963af700d on pr/chacha20poly1305 into
4bcd48411aon develop.@ -0,0 +1,70 @@/* LibTomCrypt, modular cryptographic library -- Tom St DenisLike
somewhere in
tomcrypt_custom.h?@ -0,0 +1,219 @@/* LibTomCrypt, modular cryptographic library -- Tom St DenisA review would be great.
Should I create a separate issue like
Call for reviewers - PRNG/ChaCha20?done
@ -0,0 +1,70 @@/* LibTomCrypt, modular cryptographic library -- Tom St Denisdone cd5e4e8
@ -535,7 +550,12 @@Coverage increased (+0.2%) to 87.666% when pulling cd5e4e8b83435c81a706048dbb0711909b2afc26 on pr/chacha20poly1305 into
4bcd48411aon develop.@ -535,7 +550,12 @@done e57ca44
BTW do we have a fixed file which I can use as an input in a test for
poly1305_file(..)?we don't have tests for any of the
***_file()API's... we can leave it like that I'd say... or use one of the testvector files?test vector files are sometimes changing (see sha3)
I was thinking about creating let's say
testprof/fixed-test-file.txtwith 10000 bytes of random text.You are perhaps right the *_file functions need a facelift anyway (to use the same read buffer style) which is worth a separate PR where we can add more tests as well.
Coverage increased (+0.2%) to 87.666% when pulling e57ca441cdeb4dc6b5b5033a07630d05ec7f7efd on pr/chacha20poly1305 into
4bcd48411aon develop.Coverage increased (+0.2%) to 87.739% when pulling b6648e5218877edf3becad2808907642a6d0fb77 on pr/chacha20poly1305 into
77019928ddon develop.Coverage increased (+0.2%) to 87.739% when pulling 5b40b62c0229631cf5e3d0f338c12ff73f72c528 on pr/chacha20poly1305 into
77019928ddon develop.@sjaeckel can I merge this PR?
Coverage increased (+0.2%) to 87.799% when pulling
08a028ab04on pr/chacha20poly1305 into6844275e82on develop.Looks like I missed these in the first review... sorry :)
After these changes I think it's fine to merge
@ -0,0 +1,70 @@/* LibTomCrypt, modular cryptographic library -- Tom St Denissizeof(buf)is either 4 or 8... :)@ -0,0 +1,219 @@/* LibTomCrypt, modular cryptographic library -- Tom St DenisI'd say we should also rename all these occurrences to
chacha20_prng***Sure, can you then please also link the existing implementation(s).
@ -0,0 +1,219 @@/* LibTomCrypt, modular cryptographic library -- Tom St Denisfixed
ce37498@ -0,0 +1,70 @@/* LibTomCrypt, modular cryptographic library -- Tom St DenisOMG, fixed
7b93f04Coverage increased (+0.2%) to 87.799% when pulling
2520e6c061on pr/chacha20poly1305 into6844275e82on develop.