Skip to content

Commit d25a7d1

Browse files
authored
Merge pull request #567 from pq-code-package/unaligned-test
Add test exercising top-level API with unaligned buffers
2 parents 257c38d + de16e88 commit d25a7d1

File tree

4 files changed

+55
-16
lines changed

4 files changed

+55
-16
lines changed

.github/workflows/all.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ jobs:
1919
id-token: 'write'
2020
uses: ./.github/workflows/base.yml
2121
secrets: inherit
22+
lint-markdown:
23+
name: Lint Markdown
24+
permissions:
25+
contents: 'read'
26+
id-token: 'write'
27+
uses: ./.github/workflows/lint_markdown.yml
2228
nix:
2329
name: Nix
2430
permissions:

.github/workflows/base.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ jobs:
2424
nix-shell: ci-linter
2525
gh_token: ${{ secrets.GITHUB_TOKEN }}
2626
cross-prefix: "aarch64-unknown-linux-gnu-"
27-
lint-markdown-link:
28-
runs-on: ubuntu-latest
29-
steps:
30-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
31-
- uses: gaurav-nelson/github-action-markdown-link-check@3c3b66f1f7d0900e37b71eca45b63ea9eedfce31 # v1.0.17
3227
quickcheck:
3328
strategy:
3429
fail-fast: false
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
2+
3+
name: Lint-Markdown
4+
permissions:
5+
contents: read
6+
on:
7+
workflow_call:
8+
workflow_dispatch:
9+
10+
jobs:
11+
lint-markdown-link:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
15+
- uses: gaurav-nelson/github-action-markdown-link-check@3c3b66f1f7d0900e37b71eca45b63ea9eedfce31 # v1.0.17

test/test_mldsa.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,31 @@
2828
} \
2929
} while (0)
3030

31-
static int test_sign(void)
31+
32+
static int test_sign_core(uint8_t pk[CRYPTO_PUBLICKEYBYTES],
33+
uint8_t sk[CRYPTO_SECRETKEYBYTES],
34+
uint8_t sm[MLEN + CRYPTO_BYTES], uint8_t m[MLEN],
35+
uint8_t m2[MLEN + CRYPTO_BYTES], uint8_t ctx[CTXLEN])
3236
{
33-
uint8_t pk[CRYPTO_PUBLICKEYBYTES];
34-
uint8_t sk[CRYPTO_SECRETKEYBYTES];
35-
uint8_t sm[MLEN + CRYPTO_BYTES];
36-
uint8_t m[MLEN];
37-
uint8_t m2[MLEN + CRYPTO_BYTES];
38-
uint8_t ctx[CTXLEN];
3937
size_t smlen;
4038
size_t mlen;
4139
int rc;
4240

4341

4442
CHECK(crypto_sign_keypair(pk, sk) == 0);
4543
randombytes(ctx, CTXLEN);
46-
MLD_CT_TESTING_SECRET(ctx, sizeof(ctx));
44+
MLD_CT_TESTING_SECRET(ctx, CTXLEN);
4745
randombytes(m, MLEN);
48-
MLD_CT_TESTING_SECRET(m, sizeof(m));
46+
MLD_CT_TESTING_SECRET(m, MLEN);
4947

5048
CHECK(crypto_sign(sm, &smlen, m, MLEN, ctx, CTXLEN, sk) == 0);
5149

5250
rc = crypto_sign_open(m2, &mlen, sm, smlen, ctx, CTXLEN, pk);
5351

5452
/* Constant time: Declassify outputs to check them. */
5553
MLD_CT_TESTING_DECLASSIFY(rc, sizeof(int));
56-
MLD_CT_TESTING_DECLASSIFY(m, sizeof(m));
57-
MLD_CT_TESTING_DECLASSIFY(m2, sizeof(m2));
54+
MLD_CT_TESTING_DECLASSIFY(m, MLEN);
55+
MLD_CT_TESTING_DECLASSIFY(m2, (MLEN + CRYPTO_BYTES));
5856

5957
if (rc)
6058
{
@@ -83,6 +81,30 @@ static int test_sign(void)
8381
return 0;
8482
}
8583

84+
static int test_sign(void)
85+
{
86+
uint8_t pk[CRYPTO_PUBLICKEYBYTES];
87+
uint8_t sk[CRYPTO_SECRETKEYBYTES];
88+
uint8_t sm[MLEN + CRYPTO_BYTES];
89+
uint8_t m[MLEN];
90+
uint8_t m2[MLEN + CRYPTO_BYTES];
91+
uint8_t ctx[CTXLEN];
92+
93+
return test_sign_core(pk, sk, sm, m, m2, ctx);
94+
}
95+
96+
static int test_sign_unaligned(void)
97+
{
98+
MLD_ALIGN uint8_t pk[CRYPTO_PUBLICKEYBYTES + 1];
99+
MLD_ALIGN uint8_t sk[CRYPTO_SECRETKEYBYTES + 1];
100+
MLD_ALIGN uint8_t sm[MLEN + CRYPTO_BYTES + 1];
101+
MLD_ALIGN uint8_t m[MLEN + 1];
102+
MLD_ALIGN uint8_t m2[MLEN + CRYPTO_BYTES + 1];
103+
MLD_ALIGN uint8_t ctx[CTXLEN + 1];
104+
105+
return test_sign_core(pk + 1, sk + 1, sm + 1, m + 1, m2 + 1, ctx + 1);
106+
}
107+
86108
static int test_wrong_pk(void)
87109
{
88110
uint8_t pk[CRYPTO_PUBLICKEYBYTES];
@@ -249,6 +271,7 @@ int main(void)
249271
for (i = 0; i < NTESTS; i++)
250272
{
251273
r = test_sign();
274+
r |= test_sign_unaligned();
252275
r |= test_wrong_pk();
253276
r |= test_wrong_sig();
254277
r |= test_wrong_ctx();

0 commit comments

Comments
 (0)