auth-data.h 806 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2022 Felix Fietkau <nbd@nbd.name>
  4. */
  5. #ifndef __AUTH_DATA_H
  6. #define __AUTH_DATA_H
  7. #include <stdint.h>
  8. #include <libubox/utils.h>
  9. #include "edsign.h"
  10. #include "curve25519.h"
  11. #define UNET_AUTH_MAGIC 0x754e6574
  12. struct unet_auth_hdr {
  13. uint32_t magic;
  14. uint8_t version;
  15. uint8_t _pad[3];
  16. uint8_t signature[EDSIGN_SIGNATURE_SIZE];
  17. } __packed;
  18. struct unet_auth_data {
  19. uint64_t timestamp;
  20. uint8_t pubkey[CURVE25519_KEY_SIZE];
  21. uint32_t flags;
  22. } __packed;
  23. int unet_auth_data_validate(const uint8_t *key, const void *buf, size_t len,
  24. uint64_t *timestamp, const char **json_data);
  25. static inline const struct unet_auth_data *
  26. net_data_auth_data_hdr(const void *net_data)
  27. {
  28. return net_data + sizeof(struct unet_auth_hdr);
  29. }
  30. #endif