1 /* Copyright (C) 2001-2006 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied, modified
8    or distributed except as expressly authorized under the terms of that
9    license.  Refer to licensing information at http://www.artifex.com/
10    or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11    San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12 */
13 
14 /* $Id: gscrypt1.h 8022 2007-06-05 22:23:38Z giles $ */
15 /* Interface to Adobe Type 1 encryption/decryption. */
16 
17 #ifndef gscrypt1_INCLUDED
18 #  define gscrypt1_INCLUDED
19 
20 /* Normal public interface */
21 typedef ushort crypt_state;
22 int gs_type1_encrypt(byte * dest, const byte * src, uint len,
23 		     crypt_state * pstate);
24 int gs_type1_decrypt(byte * dest, const byte * src, uint len,
25 		     crypt_state * pstate);
26 
27 /* Define the encryption parameters and procedures. */
28 #define crypt_c1 ((ushort)52845)
29 #define crypt_c2 ((ushort)22719)
30 /* c1 * c1' == 1 mod 2^16. */
31 #define crypt_c1_inverse ((ushort)27493)
32 #define encrypt_next(ch, state, chvar)\
33   (chvar = ((ch) ^ (state >> 8)),\
34    state = (chvar + state) * crypt_c1 + crypt_c2)
35 #define decrypt_this(ch, state)\
36   ((ch) ^ (state >> 8))
37 #define decrypt_next(ch, state, chvar)\
38   (chvar = decrypt_this(ch, state),\
39    decrypt_skip_next(ch, state))
40 #define decrypt_skip_next(ch, state)\
41   (state = ((ch) + state) * crypt_c1 + crypt_c2)
42 #define decrypt_skip_previous(ch, state)\
43   (state = (state - crypt_c2) * crypt_c1_inverse - (ch))
44 
45 #endif /* gscrypt1_INCLUDED */
46