crypt.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* crypt.h -- base code for traditional PKWARE encryption
  2. Version 1.01e, February 12th, 2005
  3. Copyright (C) 1998-2005 Gilles Vollant
  4. Modifications for Info-ZIP crypting
  5. Copyright (C) 2003 Terry Thorsen
  6. This code is a modified version of crypting code in Info-ZIP distribution
  7. Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
  8. This program is distributed under the terms of the same license as zlib.
  9. See the accompanying LICENSE file for the full text of the license.
  10. */
  11. #ifndef _MINICRYPT_H
  12. #define _MINICRYPT_H
  13. #if ZLIB_VERNUM < 0x1270
  14. #if !defined(Z_U4)
  15. typedef unsigned long z_crc_t;
  16. #endif
  17. #endif
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #define RAND_HEAD_LEN 12
  22. /***************************************************************************/
  23. #define zdecode(pkeys,pcrc_32_tab,c) \
  24. (update_keys(pkeys,pcrc_32_tab, c ^= decrypt_byte(pkeys)))
  25. #define zencode(pkeys,pcrc_32_tab,c,t) \
  26. (t = decrypt_byte(pkeys), update_keys(pkeys,pcrc_32_tab,c), t^(c))
  27. /***************************************************************************/
  28. /* Return the next byte in the pseudo-random sequence */
  29. uint8_t decrypt_byte(uint32_t *pkeys);
  30. /* Update the encryption keys with the next byte of plain text */
  31. uint8_t update_keys(uint32_t *pkeys, const z_crc_t *pcrc_32_tab, int32_t c);
  32. /* Initialize the encryption keys and the random header according to the given password. */
  33. void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab);
  34. /* Generate cryptographically secure random numbers */
  35. int cryptrand(unsigned char *buf, unsigned int len);
  36. /* Create encryption header */
  37. int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
  38. const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2);
  39. /***************************************************************************/
  40. #ifdef __cplusplus
  41. }
  42. #endif
  43. #endif