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