From 0f8e034f976640b812a2fb8337d8eaf6c8f8e74d Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Wed, 23 Oct 2019 20:03:01 +0200 Subject: [PATCH] Reorganize aead_aegis256 a bit --- .../msvc/vs2010/libsodium/libsodium.vcxproj | 3 + .../libsodium/libsodium.vcxproj.filters | 12 +++ .../msvc/vs2012/libsodium/libsodium.vcxproj | 3 + .../libsodium/libsodium.vcxproj.filters | 12 +++ .../msvc/vs2013/libsodium/libsodium.vcxproj | 3 + .../libsodium/libsodium.vcxproj.filters | 12 +++ .../msvc/vs2015/libsodium/libsodium.vcxproj | 3 + .../libsodium/libsodium.vcxproj.filters | 12 +++ .../msvc/vs2017/libsodium/libsodium.vcxproj | 3 + .../libsodium/libsodium.vcxproj.filters | 12 +++ .../msvc/vs2019/libsodium/libsodium.vcxproj | 3 + .../libsodium/libsodium.vcxproj.filters | 12 +++ libsodium.vcxproj | 3 + libsodium.vcxproj.filters | 9 ++ src/libsodium/Makefile.am | 3 +- .../crypto_aead/aegis256/aead_aegis256.c | 97 +++++++++++++++++++ .../aegis256/aesni/aead_aegis256_aesni.c | 91 +---------------- .../aead_aegis256_armcrypto.c | 10 +- 18 files changed, 211 insertions(+), 92 deletions(-) create mode 100644 src/libsodium/crypto_aead/aegis256/aead_aegis256.c rename src/libsodium/crypto_aead/aegis256/{arm-crypto => armcrypto}/aead_aegis256_armcrypto.c (98%) diff --git a/builds/msvc/vs2010/libsodium/libsodium.vcxproj b/builds/msvc/vs2010/libsodium/libsodium.vcxproj index 7213fbf3..50bc014e 100644 --- a/builds/msvc/vs2010/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2010/libsodium/libsodium.vcxproj @@ -173,7 +173,9 @@ + + @@ -202,6 +204,7 @@ + diff --git a/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters index e13debad..d4d663e3 100644 --- a/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters @@ -312,9 +312,15 @@ crypto_aead\xchacha20poly1305\sodium + + crypto_aead\aegis256 + crypto_aead\aegis256\aesni + + crypto_aead\aegis256\armcrypto + crypto_aead\aes256gcm\aesni @@ -395,6 +401,9 @@ include\sodium + + include\sodium + include\sodium @@ -757,6 +766,9 @@ {53f55581-bb1c-3fe5-8c1b-1dd4243765ef} + + {d8e5d430-b695-3e19-81bd-31fd1e6445da} + {3e53394c-b59c-30cc-ae69-a4f46f9edfa3} diff --git a/builds/msvc/vs2012/libsodium/libsodium.vcxproj b/builds/msvc/vs2012/libsodium/libsodium.vcxproj index fee23f34..d6a9c537 100644 --- a/builds/msvc/vs2012/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2012/libsodium/libsodium.vcxproj @@ -173,7 +173,9 @@ + + @@ -202,6 +204,7 @@ + diff --git a/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters index e13debad..d4d663e3 100644 --- a/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters @@ -312,9 +312,15 @@ crypto_aead\xchacha20poly1305\sodium + + crypto_aead\aegis256 + crypto_aead\aegis256\aesni + + crypto_aead\aegis256\armcrypto + crypto_aead\aes256gcm\aesni @@ -395,6 +401,9 @@ include\sodium + + include\sodium + include\sodium @@ -757,6 +766,9 @@ {53f55581-bb1c-3fe5-8c1b-1dd4243765ef} + + {d8e5d430-b695-3e19-81bd-31fd1e6445da} + {3e53394c-b59c-30cc-ae69-a4f46f9edfa3} diff --git a/builds/msvc/vs2013/libsodium/libsodium.vcxproj b/builds/msvc/vs2013/libsodium/libsodium.vcxproj index deec6006..9cb89f1e 100644 --- a/builds/msvc/vs2013/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2013/libsodium/libsodium.vcxproj @@ -173,7 +173,9 @@ + + @@ -202,6 +204,7 @@ + diff --git a/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters index e13debad..d4d663e3 100644 --- a/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters @@ -312,9 +312,15 @@ crypto_aead\xchacha20poly1305\sodium + + crypto_aead\aegis256 + crypto_aead\aegis256\aesni + + crypto_aead\aegis256\armcrypto + crypto_aead\aes256gcm\aesni @@ -395,6 +401,9 @@ include\sodium + + include\sodium + include\sodium @@ -757,6 +766,9 @@ {53f55581-bb1c-3fe5-8c1b-1dd4243765ef} + + {d8e5d430-b695-3e19-81bd-31fd1e6445da} + {3e53394c-b59c-30cc-ae69-a4f46f9edfa3} diff --git a/builds/msvc/vs2015/libsodium/libsodium.vcxproj b/builds/msvc/vs2015/libsodium/libsodium.vcxproj index 5acd99e5..e895c053 100644 --- a/builds/msvc/vs2015/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2015/libsodium/libsodium.vcxproj @@ -173,7 +173,9 @@ + + @@ -202,6 +204,7 @@ + diff --git a/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters index e13debad..d4d663e3 100644 --- a/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters @@ -312,9 +312,15 @@ crypto_aead\xchacha20poly1305\sodium + + crypto_aead\aegis256 + crypto_aead\aegis256\aesni + + crypto_aead\aegis256\armcrypto + crypto_aead\aes256gcm\aesni @@ -395,6 +401,9 @@ include\sodium + + include\sodium + include\sodium @@ -757,6 +766,9 @@ {53f55581-bb1c-3fe5-8c1b-1dd4243765ef} + + {d8e5d430-b695-3e19-81bd-31fd1e6445da} + {3e53394c-b59c-30cc-ae69-a4f46f9edfa3} diff --git a/builds/msvc/vs2017/libsodium/libsodium.vcxproj b/builds/msvc/vs2017/libsodium/libsodium.vcxproj index 8d11cde2..ea4ca4db 100644 --- a/builds/msvc/vs2017/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2017/libsodium/libsodium.vcxproj @@ -173,7 +173,9 @@ + + @@ -202,6 +204,7 @@ + diff --git a/builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters index e13debad..d4d663e3 100644 --- a/builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters @@ -312,9 +312,15 @@ crypto_aead\xchacha20poly1305\sodium + + crypto_aead\aegis256 + crypto_aead\aegis256\aesni + + crypto_aead\aegis256\armcrypto + crypto_aead\aes256gcm\aesni @@ -395,6 +401,9 @@ include\sodium + + include\sodium + include\sodium @@ -757,6 +766,9 @@ {53f55581-bb1c-3fe5-8c1b-1dd4243765ef} + + {d8e5d430-b695-3e19-81bd-31fd1e6445da} + {3e53394c-b59c-30cc-ae69-a4f46f9edfa3} diff --git a/builds/msvc/vs2019/libsodium/libsodium.vcxproj b/builds/msvc/vs2019/libsodium/libsodium.vcxproj index dac5deb2..896a9a2c 100644 --- a/builds/msvc/vs2019/libsodium/libsodium.vcxproj +++ b/builds/msvc/vs2019/libsodium/libsodium.vcxproj @@ -173,7 +173,9 @@ + + @@ -202,6 +204,7 @@ + diff --git a/builds/msvc/vs2019/libsodium/libsodium.vcxproj.filters b/builds/msvc/vs2019/libsodium/libsodium.vcxproj.filters index e13debad..d4d663e3 100644 --- a/builds/msvc/vs2019/libsodium/libsodium.vcxproj.filters +++ b/builds/msvc/vs2019/libsodium/libsodium.vcxproj.filters @@ -312,9 +312,15 @@ crypto_aead\xchacha20poly1305\sodium + + crypto_aead\aegis256 + crypto_aead\aegis256\aesni + + crypto_aead\aegis256\armcrypto + crypto_aead\aes256gcm\aesni @@ -395,6 +401,9 @@ include\sodium + + include\sodium + include\sodium @@ -757,6 +766,9 @@ {53f55581-bb1c-3fe5-8c1b-1dd4243765ef} + + {d8e5d430-b695-3e19-81bd-31fd1e6445da} + {3e53394c-b59c-30cc-ae69-a4f46f9edfa3} diff --git a/libsodium.vcxproj b/libsodium.vcxproj index 7ddc6e5f..3dacc0bb 100644 --- a/libsodium.vcxproj +++ b/libsodium.vcxproj @@ -411,7 +411,9 @@ + + @@ -440,6 +442,7 @@ + diff --git a/libsodium.vcxproj.filters b/libsodium.vcxproj.filters index 3ae7e702..e6e103a1 100644 --- a/libsodium.vcxproj.filters +++ b/libsodium.vcxproj.filters @@ -303,9 +303,15 @@ Source Files + + Source Files + Source Files + + Source Files + Source Files @@ -386,6 +392,9 @@ Header Files + + Header Files + Header Files diff --git a/src/libsodium/Makefile.am b/src/libsodium/Makefile.am index e0b8343a..1b9eca79 100644 --- a/src/libsodium/Makefile.am +++ b/src/libsodium/Makefile.am @@ -2,6 +2,7 @@ lib_LTLIBRARIES = \ libsodium.la libsodium_la_SOURCES = \ + crypto_aead/aegis256/aead_aegis256.c \ crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c \ crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c \ crypto_auth/crypto_auth.c \ @@ -220,7 +221,7 @@ libarmcrypto_la_LDFLAGS = $(libsodium_la_LDFLAGS) libarmcrypto_la_CPPFLAGS = $(libsodium_la_CPPFLAGS) \ @CFLAGS_ARMCRYPTO@ libarmcrypto_la_SOURCES = \ - crypto_aead/aegis256/arm-crypto/aead_aegis256_armcrypto.c + crypto_aead/aegis256/armcrypto/aead_aegis256_armcrypto.c libaesni_la_LDFLAGS = $(libsodium_la_LDFLAGS) libaesni_la_CPPFLAGS = $(libsodium_la_CPPFLAGS) \ diff --git a/src/libsodium/crypto_aead/aegis256/aead_aegis256.c b/src/libsodium/crypto_aead/aegis256/aead_aegis256.c new file mode 100644 index 00000000..aee51ff7 --- /dev/null +++ b/src/libsodium/crypto_aead/aegis256/aead_aegis256.c @@ -0,0 +1,97 @@ + +#include +#include + +#include "crypto_aead_aegis256.h" + +size_t +crypto_aead_aegis256_keybytes(void) +{ + return crypto_aead_aegis256_KEYBYTES; +} + +size_t +crypto_aead_aegis256_nsecbytes(void) +{ + return crypto_aead_aegis256_NSECBYTES; +} + +size_t +crypto_aead_aegis256_npubbytes(void) +{ + return crypto_aead_aegis256_NPUBBYTES; +} + +size_t +crypto_aead_aegis256_abytes(void) +{ + return crypto_aead_aegis256_ABYTES; +} + +size_t +crypto_aead_aegis256_messagebytes_max(void) +{ + return crypto_aead_aegis256_MESSAGEBYTES_MAX; +} + +void +crypto_aead_aegis256_keygen(unsigned char k[crypto_aead_aegis256_KEYBYTES]) +{ + randombytes_buf(k, crypto_aead_aegis256_KEYBYTES); +} + +#if !((defined(HAVE_TMMINTRIN_H) && defined(HAVE_WMMINTRIN_H)) || \ + defined(HAVE_ARMCRYPTO)) + +#ifndef ENOSYS +# define ENOSYS ENXIO +#endif + +int +crypto_aead_aegis256_encrypt_detached(unsigned char *c, unsigned char *mac, + unsigned long long *maclen_p, const unsigned char *m, + unsigned long long mlen, const unsigned char *ad, + unsigned long long adlen, const unsigned char *nsec, + const unsigned char *npub, const unsigned char *k) +{ + errno = ENOSYS; + return -1; +} + +int +crypto_aead_aegis256_encrypt(unsigned char *c, unsigned long long *clen_p, const unsigned char *m, + unsigned long long mlen, const unsigned char *ad, + unsigned long long adlen, const unsigned char *nsec, + const unsigned char *npub, const unsigned char *k) +{ + errno = ENOSYS; + return -1; +} + +int +crypto_aead_aegis256_decrypt_detached(unsigned char *m, unsigned char *nsec, const unsigned char *c, + unsigned long long clen, const unsigned char *mac, + const unsigned char *ad, unsigned long long adlen, + const unsigned char *npub, const unsigned char *k) +{ + errno = ENOSYS; + return -1; +} + +int +crypto_aead_aegis256_decrypt(unsigned char *m, unsigned long long *mlen_p, unsigned char *nsec, + const unsigned char *c, unsigned long long clen, + const unsigned char *ad, unsigned long long adlen, + const unsigned char *npub, const unsigned char *k) +{ + errno = ENOSYS; + return -1; +} + +int +crypto_aead_aegis256_is_available(void) +{ + return 0; +} + +#endif diff --git a/src/libsodium/crypto_aead/aegis256/aesni/aead_aegis256_aesni.c b/src/libsodium/crypto_aead/aegis256/aesni/aead_aegis256_aesni.c index a9bd18db..e6d23974 100644 --- a/src/libsodium/crypto_aead/aegis256/aesni/aead_aegis256_aesni.c +++ b/src/libsodium/crypto_aead/aegis256/aesni/aead_aegis256_aesni.c @@ -282,96 +282,7 @@ crypto_aead_aegis256_decrypt(unsigned char *m, unsigned long long *mlen_p, unsig int crypto_aead_aegis256_is_available(void) { - return sodium_runtime_has_aesni(); -} - -#else - -#ifndef ENOSYS -# define ENOSYS ENXIO -#endif - -int -crypto_aead_aegis256_encrypt_detached(unsigned char *c, unsigned char *mac, - unsigned long long *maclen_p, const unsigned char *m, - unsigned long long mlen, const unsigned char *ad, - unsigned long long adlen, const unsigned char *nsec, - const unsigned char *npub, const unsigned char *k) -{ - errno = ENOSYS; - return -1; -} - -int -crypto_aead_aegis256_encrypt(unsigned char *c, unsigned long long *clen_p, const unsigned char *m, - unsigned long long mlen, const unsigned char *ad, - unsigned long long adlen, const unsigned char *nsec, - const unsigned char *npub, const unsigned char *k) -{ - errno = ENOSYS; - return -1; -} - -int -crypto_aead_aegis256_decrypt_detached(unsigned char *m, unsigned char *nsec, const unsigned char *c, - unsigned long long clen, const unsigned char *mac, - const unsigned char *ad, unsigned long long adlen, - const unsigned char *npub, const unsigned char *k) -{ - errno = ENOSYS; - return -1; -} - -int -crypto_aead_aegis256_decrypt(unsigned char *m, unsigned long long *mlen_p, unsigned char *nsec, - const unsigned char *c, unsigned long long clen, - const unsigned char *ad, unsigned long long adlen, - const unsigned char *npub, const unsigned char *k) -{ - errno = ENOSYS; - return -1; -} - -int -crypto_aead_aegis256_is_available(void) -{ - return 0; + return sodium_runtime_has_armcrypto(); } #endif - -size_t -crypto_aead_aegis256_keybytes(void) -{ - return crypto_aead_aegis256_KEYBYTES; -} - -size_t -crypto_aead_aegis256_nsecbytes(void) -{ - return crypto_aead_aegis256_NSECBYTES; -} - -size_t -crypto_aead_aegis256_npubbytes(void) -{ - return crypto_aead_aegis256_NPUBBYTES; -} - -size_t -crypto_aead_aegis256_abytes(void) -{ - return crypto_aead_aegis256_ABYTES; -} - -size_t -crypto_aead_aegis256_messagebytes_max(void) -{ - return crypto_aead_aegis256_MESSAGEBYTES_MAX; -} - -void -crypto_aead_aegis256_keygen(unsigned char k[crypto_aead_aegis256_KEYBYTES]) -{ - randombytes_buf(k, crypto_aead_aegis256_KEYBYTES); -} diff --git a/src/libsodium/crypto_aead/aegis256/arm-crypto/aead_aegis256_armcrypto.c b/src/libsodium/crypto_aead/aegis256/armcrypto/aead_aegis256_armcrypto.c similarity index 98% rename from src/libsodium/crypto_aead/aegis256/arm-crypto/aead_aegis256_armcrypto.c rename to src/libsodium/crypto_aead/aegis256/armcrypto/aead_aegis256_armcrypto.c index 8832fadc..e73c3769 100644 --- a/src/libsodium/crypto_aead/aegis256/arm-crypto/aead_aegis256_armcrypto.c +++ b/src/libsodium/crypto_aead/aegis256/armcrypto/aead_aegis256_armcrypto.c @@ -12,7 +12,8 @@ #include "private/common.h" -#ifdef HAVE_ARM_CRYPTO +#ifdef HAVE_ARMCRYPTO + # include static inline void @@ -278,4 +279,11 @@ crypto_aead_aegis256_decrypt(unsigned char *m, unsigned long long *mlen_p, unsig } return ret; } + +int +crypto_aead_aegis256_is_available(void) +{ + return sodium_runtime_has_aesni(); +} + #endif