packet_valid_header.c 824 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* LibTomCrypt, modular cryptographic library -- Tom St Denis
  2. *
  3. * LibTomCrypt is a library that provides various cryptographic
  4. * algorithms in a highly modular and flexible manner.
  5. *
  6. * The library is free for all purposes without any express
  7. * guarantee it works.
  8. *
  9. * Tom St Denis, [email protected], http://libtomcrypt.org
  10. */
  11. #include "mycrypt.h"
  12. #ifdef PACKET
  13. int packet_valid_header(unsigned char *src, int section, int subsection)
  14. {
  15. unsigned long ver;
  16. _ARGCHK(src != NULL);
  17. /* check version */
  18. ver = ((unsigned long)src[0]) | ((unsigned long)src[1] << 8U);
  19. if (CRYPT < ver) {
  20. return CRYPT_INVALID_PACKET;
  21. }
  22. /* check section and subsection */
  23. if (section != (int)src[2] || subsection != (int)src[3]) {
  24. return CRYPT_INVALID_PACKET;
  25. }
  26. return CRYPT_OK;
  27. }
  28. #endif