1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
4 */
5
6 struct def {
7 const char *name;
8 unsigned long offset;
9 unsigned long indirection_offset;
10 };
11 extern const struct def defs[];
12
13 #ifdef __KERNEL__
14 #include "../drivers/net/wireguard/noise.h"
15
16 const struct def defs[] = {
17 { "LOCAL_STATIC_PRIVATE_KEY", offsetof(struct noise_static_identity, static_private), offsetof(struct noise_handshake, static_identity) },
18 { "LOCAL_EPHEMERAL_PRIVATE_KEY", offsetof(struct noise_handshake, ephemeral_private), -1 },
19 { "REMOTE_STATIC_PUBLIC_KEY", offsetof(struct noise_handshake, remote_static), -1 },
20 { "PRESHARED_KEY", offsetof(struct noise_handshake, preshared_key), -1 },
21 { NULL, 0 }
22 };
23 #else
24 #include <stdio.h>
main(int argc,char * argv[])25 int main(int argc, char *argv[])
26 {
27 puts("declare -A OFFSETS=(");
28 for (const struct def *def = defs; def->name; ++def) {
29 printf("\t[%s]=%ld", def->name, def->offset);
30 if (def->indirection_offset != -1)
31 printf(",%ld", def->indirection_offset);
32 putchar('\n');
33 }
34 puts(")");
35 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
36 puts("ENDIAN=big");
37 #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
38 puts("ENDIAN=little");
39 #else
40 #error "Unsupported endianness"
41 #endif
42 return 0;
43 }
44 #endif
45