3d6621304705e880e972455da12a4cd2d5cef4c8
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2022 Felix Fietkau <nbd@nbd.name>
9 int unet_auth_data_validate(const uint8_t *key
, const void *buf
, size_t len
,
10 uint64_t *timestamp
, const char **json_data
)
12 const struct unet_auth_hdr
*hdr
= buf
;
13 const struct unet_auth_data
*data
= net_data_auth_data_hdr(buf
);
14 struct edsign_verify_state vst
;
16 if (len
<= sizeof(*hdr
) + sizeof(*data
))
21 if (hdr
->magic
!= cpu_to_be32(UNET_AUTH_MAGIC
) ||
22 hdr
->version
!= 0 || data
->flags
!= 0 ||
26 if (key
&& memcmp(data
->pubkey
, key
, EDSIGN_PUBLIC_KEY_SIZE
) != 0)
29 edsign_verify_init(&vst
, hdr
->signature
, data
->pubkey
);
30 edsign_verify_add(&vst
, data
, len
);
31 if (!edsign_verify(&vst
, hdr
->signature
, data
->pubkey
))
34 if (*(char *)(data
+ len
- 1) != 0)
38 *timestamp
= be64_to_cpu(data
->timestamp
);
41 *json_data
= (const char *)(data
+ 1);