mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Use sodium_bin2hex() instead of duplicating the same code everywhere.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user