1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
From: =?utf-8?b?SmFuIE1vasW+w63FoQ==?= <jan.mojzis@gmail.com>
Date: Mon, 9 May 2022 15:29:24 +0200
Subject: reject primitives with alignment problems
---
crypto_onetimeauth/try.c | 9 +++++++++
crypto_scalarmult/try.c | 10 ++++++++++
crypto_stream/try.c | 12 ++++++++++++
3 files changed, 31 insertions(+)
diff --git a/crypto_onetimeauth/try.c b/crypto_onetimeauth/try.c
index 54f4396..697f993 100644
--- a/crypto_onetimeauth/try.c
+++ b/crypto_onetimeauth/try.c
@@ -21,6 +21,9 @@ static unsigned char *k;
static unsigned char *h2;
static unsigned char *m2;
static unsigned char *k2;
+static unsigned char *ha;
+static unsigned char *ma;
+static unsigned char *ka;
void preallocate(void)
{
@@ -34,6 +37,9 @@ void allocate(void)
h2 = alignedcalloc(crypto_onetimeauth_BYTES);
m2 = alignedcalloc(MAXTEST_BYTES + crypto_onetimeauth_BYTES);
k2 = alignedcalloc(crypto_onetimeauth_KEYBYTES + crypto_onetimeauth_BYTES);
+ ha = alignedcalloc(crypto_onetimeauth_BYTES + 16);
+ ma = alignedcalloc(MAXTEST_BYTES + 16);
+ ka = alignedcalloc(crypto_onetimeauth_KEYBYTES + 16);
}
void predoit(void)
@@ -53,6 +59,9 @@ const char *checksum_compute(void)
long long i;
long long j;
+ /* alignment check */
+ for (j = 0;j < 16;++j) if (crypto_onetimeauth(ha + j,ma + j,MAXTEST_BYTES,ka + j) != 0) return "crypto_onetimeauth with unaligned input returns nonzero";
+
for (i = 0;i < CHECKSUM_BYTES;++i) {
long long mlen = i;
long long klen = crypto_onetimeauth_KEYBYTES;
diff --git a/crypto_scalarmult/try.c b/crypto_scalarmult/try.c
index 560ce49..488fac6 100644
--- a/crypto_scalarmult/try.c
+++ b/crypto_scalarmult/try.c
@@ -29,6 +29,10 @@ static unsigned char *p2;
static unsigned char *q2;
static unsigned char *r2;
+static unsigned char *na;
+static unsigned char *pa;
+static unsigned char *qa;
+
void preallocate(void)
{
}
@@ -45,6 +49,9 @@ void allocate(void)
p2 = alignedcalloc(plen + crypto_scalarmult_BYTES);
q2 = alignedcalloc(qlen + crypto_scalarmult_BYTES);
r2 = alignedcalloc(rlen + crypto_scalarmult_BYTES);
+ na = alignedcalloc(mlen + 16);
+ pa = alignedcalloc(plen + 16);
+ qa = alignedcalloc(qlen + 16);
}
void predoit(void)
@@ -65,6 +72,9 @@ const char *checksum_compute(void)
long long j;
long long tests;
+ for (j = 0;j < 16;++j) if (crypto_scalarmult_base(pa + j,na + j) != 0) return "crypto_scalarmult_base with unaligned input returns nonzero";
+ for (j = 0;j < 16;++j) if (crypto_scalarmult(qa + j,na + j,pa + j) != 0) return "crypto_scalarmult with unaligned input returns nonzero";
+
for (i = 0;i < mlen;++i) m[i] = i;
for (i = 0;i < nlen;++i) n[i] = i + 1;
for (i = 0;i < plen;++i) p[i] = i + 2;
diff --git a/crypto_stream/try.c b/crypto_stream/try.c
index 9a36d76..162a1e5 100644
--- a/crypto_stream/try.c
+++ b/crypto_stream/try.c
@@ -25,6 +25,10 @@ static unsigned char *n2;
static unsigned char *m2;
static unsigned char *c2;
static unsigned char *s2;
+static unsigned char *ka;
+static unsigned char *na;
+static unsigned char *ma;
+static unsigned char *ca;
void preallocate(void)
{
@@ -42,6 +46,10 @@ void allocate(void)
m2 = alignedcalloc(MAXTEST_BYTES);
c2 = alignedcalloc(MAXTEST_BYTES);
s2 = alignedcalloc(MAXTEST_BYTES);
+ ka = alignedcalloc(crypto_stream_KEYBYTES + 16);
+ na = alignedcalloc(crypto_stream_NONCEBYTES + 16);
+ ma = alignedcalloc(MAXTEST_BYTES + 16);
+ ca = alignedcalloc(MAXTEST_BYTES + 16);
}
void predoit(void)
@@ -60,6 +68,10 @@ const char *checksum_compute(void)
long long i;
long long j;
+ /* alignment check */
+ for (j = 0;j < 16;++j) crypto_stream_xor(ca + j,ma + j,MAXTEST_BYTES,na + j,ka + j);
+ for (j = 0;j < 16;++j) crypto_stream(ma + j,MAXTEST_BYTES,na + j,ka + j);
+
for (i = 0;i < CHECKSUM_BYTES;++i) {
long long mlen = i;
long long clen = i;
|