Debian Codegraph @

others/mbedtls/tf-psa-crypto/drivers/pqcp/mldsa-native/test/src/test_stack.c

raw symbols SCIP
1 /*
2 * Copyright (c) The mldsa-native project authors
3 * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
4 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 #include "mldsa_native.h"
10
11 static void test_keygen_only(void)
12 {
13 unsigned char pk[CRYPTO_PUBLICKEYBYTES];
14 unsigned char sk[CRYPTO_SECRETKEYBYTES];
15
16 /* Only call keypair - this is what we're measuring */
17 /* Uses the notrandombytes implementation for deterministic randomness */
18 int ret = crypto_sign_keypair(pk, sk);
19 (void)ret; /* Ignore return value - we only care about stack measurement */
20 }
21
22 static void test_sign_only(void)
23 {
24 unsigned char sk[CRYPTO_SECRETKEYBYTES] = {0};
25 unsigned char sig[CRYPTO_BYTES];
26 size_t siglen;
27 const unsigned char msg[] = "test message for stack measurement";
28 const unsigned char ctx[] = "test context";
29
30 /* Only call signature - this is what we're measuring */
31 /* sk is zero-initialized (invalid key, but OK for stack measurement) */
32 int ret = crypto_sign_signature(sig, &siglen, msg, sizeof(msg) - 1, ctx,
33 sizeof(ctx) - 1, sk);
34 (void)ret; /* Ignore return value - we only care about stack measurement */
35 }
36
37 static void test_verify_only(void)
38 {
39 unsigned char pk[CRYPTO_PUBLICKEYBYTES] = {0};
40 unsigned char sig[CRYPTO_BYTES] = {0};
41 const unsigned char msg[] = "test message for stack measurement";
42 const unsigned char ctx[] = "test context";
43
44 /* Only call verify - this is what we're measuring */
45 /* pk and sig are zero-initialized (invalid, but OK for stack measurement) */
46 int ret = crypto_sign_verify(sig, CRYPTO_BYTES, msg, sizeof(msg) - 1, ctx,
47 sizeof(ctx) - 1, pk);
48 (void)ret; /* Ignore return value - we only care about stack measurement */
49 }
50
51 int main(int argc, char *argv[])
52 {
53 if (argc != 2)
54 {
55 fprintf(stderr, "Usage: %s <keygen|sign|verify>\n", argv[0]);
56 return 1;
57 }
58
59 if (strcmp(argv[1], "keygen") == 0)
60 {
61 test_keygen_only();
62 }
63 else if (strcmp(argv[1], "sign") == 0)
64 {
65 test_sign_only();
66 }
67 else if (strcmp(argv[1], "verify") == 0)
68 {
69 test_verify_only();
70 }
71 else
72 {
73 fprintf(stderr, "Unknown test: %s\n", argv[1]);
74 return 1;
75 }
76
77 return 0;
78 }