diff --git a/src/libsodium/crypto_auth/try.c b/src/libsodium/crypto_auth/try.c index d6e55607..c2f2c80f 100644 --- a/src/libsodium/crypto_auth/try.c +++ b/src/libsodium/crypto_auth/try.c @@ -7,6 +7,7 @@ #include #include "crypto_hash_sha256.h" #include "crypto_auth.h" +#include "utils.h" #include "windows/windows-quirks.h" extern unsigned char *alignedcalloc(unsigned long long); @@ -112,10 +113,7 @@ const char *checksum_compute(void) if (crypto_auth(h,m,CHECKSUM_BYTES,k) != 0) return "crypto_auth returns nonzero"; if (crypto_auth_verify(h,m,CHECKSUM_BYTES,k) != 0) return "crypto_auth_verify returns nonzero"; - for (i = 0;i < crypto_auth_BYTES;++i) { - checksum[2 * i] = "0123456789abcdef"[15 & (h[i] >> 4)]; - checksum[2 * i + 1] = "0123456789abcdef"[15 & h[i]]; - } - checksum[2 * i] = 0; + sodium_bin2hex(checksum, sizeof checksum, h, crypto_auth_BYTES); + return 0; } diff --git a/src/libsodium/crypto_box/try.c b/src/libsodium/crypto_box/try.c index b046b411..5f4b7cb9 100644 --- a/src/libsodium/crypto_box/try.c +++ b/src/libsodium/crypto_box/try.c @@ -6,6 +6,7 @@ #include #include "crypto_box.h" +#include "utils.h" #include "windows/windows-quirks.h" extern unsigned char *alignedcalloc(unsigned long long); @@ -188,10 +189,7 @@ const char *checksum_compute(void) for (j = 0;j < i;++j) m[j + crypto_box_ZEROBYTES] ^= c[j + crypto_box_BOXZEROBYTES]; } - for (i = 0;i < nlen;++i) { - checksum[2 * i] = "0123456789abcdef"[15 & (n[i] >> 4)]; - checksum[2 * i + 1] = "0123456789abcdef"[15 & n[i]]; - } - checksum[2 * i] = 0; + sodium_bin2hex(checksum, sizeof checksum, n, nlen); + return 0; } diff --git a/src/libsodium/crypto_hash/try.c b/src/libsodium/crypto_hash/try.c index 80e97dbc..5e8b5694 100644 --- a/src/libsodium/crypto_hash/try.c +++ b/src/libsodium/crypto_hash/try.c @@ -6,6 +6,7 @@ #include #include "crypto_hash.h" +#include "utils.h" #include "windows/windows-quirks.h" extern unsigned char *alignedcalloc(unsigned long long); @@ -69,10 +70,7 @@ const char *checksum_compute(void) } if (crypto_hash(h,m,CHECKSUM_BYTES) != 0) return "crypto_hash returns nonzero"; - for (i = 0;i < crypto_hash_BYTES;++i) { - checksum[2 * i] = "0123456789abcdef"[15 & (h[i] >> 4)]; - checksum[2 * i + 1] = "0123456789abcdef"[15 & h[i]]; - } - checksum[2 * i] = 0; + sodium_bin2hex(checksum, sizeof checksum, h, crypto_hash_BYTES); + return 0; } diff --git a/src/libsodium/crypto_hashblocks/try.c b/src/libsodium/crypto_hashblocks/try.c index 78bf40af..3c72cdd2 100644 --- a/src/libsodium/crypto_hashblocks/try.c +++ b/src/libsodium/crypto_hashblocks/try.c @@ -6,6 +6,7 @@ #include #include "crypto_hashblocks.h" +#include "utils.h" #include "windows/windows-quirks.h" extern unsigned char *alignedcalloc(unsigned long long); @@ -71,10 +72,7 @@ const char *checksum_compute(void) } if (crypto_hashblocks(h,m,CHECKSUM_BYTES) != 0) return "crypto_hashblocks returns nonzero"; - for (i = 0;i < crypto_hashblocks_STATEBYTES;++i) { - checksum[2 * i] = "0123456789abcdef"[15 & (h[i] >> 4)]; - checksum[2 * i + 1] = "0123456789abcdef"[15 & h[i]]; - } - checksum[2 * i] = 0; + sodium_bin2hex(checksum, sizeof checksum, h, crypto_hashblocks_STATEBYTES); + return 0; } diff --git a/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_try.c b/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_try.c index 72e0191f..cb5ca3ca 100644 --- a/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_try.c +++ b/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305_try.c @@ -110,11 +110,7 @@ checksum_compute(void) if (crypto_onetimeauth(h,m,CHECKSUM_BYTES,k) != 0) return "crypto_onetimeauth returns nonzero"; if (crypto_onetimeauth_verify(h,m,CHECKSUM_BYTES,k) != 0) return "crypto_onetimeauth_verify returns nonzero"; - for (i = 0;i < crypto_onetimeauth_BYTES;++i) { - checksum[2 * i] = "0123456789abcdef"[15 & (h[i] >> 4)]; - checksum[2 * i + 1] = "0123456789abcdef"[15 & h[i]]; - } - checksum[2 * i] = 0; + sodium_bin2hex(checksum, sizeof checksum, h, crypto_onetimeauth_BYTES); return NULL; } diff --git a/src/libsodium/crypto_scalarmult/try.c b/src/libsodium/crypto_scalarmult/try.c index 671b1089..1f75ab70 100644 --- a/src/libsodium/crypto_scalarmult/try.c +++ b/src/libsodium/crypto_scalarmult/try.c @@ -6,6 +6,7 @@ #include #include "crypto_scalarmult.h" +#include "utils.h" #include "windows/windows-quirks.h" extern unsigned char *alignedcalloc(unsigned long long); @@ -118,10 +119,7 @@ const char *checksum_compute(void) for (j = 0;j < nlen;++j) n[j] ^= p[j % plen]; } - for (i = 0;i < crypto_scalarmult_BYTES;++i) { - checksum[2 * i] = "0123456789abcdef"[15 & (p[i] >> 4)]; - checksum[2 * i + 1] = "0123456789abcdef"[15 & p[i]]; - } - checksum[2 * i] = 0; + sodium_bin2hex(checksum, sizeof checksum, p, crypto_scalarmult_BYTES); + return 0; } diff --git a/src/libsodium/crypto_secretbox/try.c b/src/libsodium/crypto_secretbox/try.c index 0a62949b..9478187e 100644 --- a/src/libsodium/crypto_secretbox/try.c +++ b/src/libsodium/crypto_secretbox/try.c @@ -6,6 +6,7 @@ #include #include "crypto_secretbox.h" +#include "utils.h" #include "windows/windows-quirks.h" extern unsigned char *alignedcalloc(unsigned long long); @@ -122,10 +123,7 @@ const char *checksum_compute(void) m[j + crypto_secretbox_ZEROBYTES] ^= c[j + crypto_secretbox_BOXZEROBYTES]; } - for (i = 0;i < klen;++i) { - checksum[2 * i] = "0123456789abcdef"[15 & (k[i] >> 4)]; - checksum[2 * i + 1] = "0123456789abcdef"[15 & k[i]]; - } - checksum[2 * i] = 0; + sodium_bin2hex(checksum, sizeof checksum, k, klen); + return 0; } diff --git a/src/libsodium/crypto_stream/try.c b/src/libsodium/crypto_stream/try.c index 3af36e3e..61bf8abb 100644 --- a/src/libsodium/crypto_stream/try.c +++ b/src/libsodium/crypto_stream/try.c @@ -6,6 +6,7 @@ #include #include "crypto_stream.h" +#include "utils.h" #include "windows/windows-quirks.h" extern unsigned char *alignedcalloc(unsigned long long); @@ -115,11 +116,7 @@ const char *checksum_compute(void) m[mlen] = 0; } - for (i = 0;i < crypto_stream_KEYBYTES;++i) { - checksum[2 * i] = "0123456789abcdef"[15 & (k[i] >> 4)]; - checksum[2 * i + 1] = "0123456789abcdef"[15 & k[i]]; - } - checksum[2 * i] = 0; + sodium_bin2hex(checksum, sizeof checksum, k, crypto_stream_KEYBYTES); return 0; }