1 /* Copyright (C) 2001-2012 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,
8    modified or distributed except as expressly authorized under the terms
9    of the license contained in the file LICENSE in this distribution.
10 
11    Refer to licensing information at http://www.artifex.com or contact
12    Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134, San Rafael,
13    CA  94903, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 
17 /* Interface to Adobe Type 1 encryption/decryption. */
18 
19 #ifndef gscrypt1_INCLUDED
20 #  define gscrypt1_INCLUDED
21 
22 /* Normal public interface */
23 typedef ushort crypt_state;
24 int gs_type1_encrypt(byte * dest, const byte * src, uint len,
25                      crypt_state * pstate);
26 int gs_type1_decrypt(byte * dest, const byte * src, uint len,
27                      crypt_state * pstate);
28 
29 /* Define the encryption parameters and procedures. */
30 #define crypt_c1 ((ushort)52845)
31 #define crypt_c2 ((ushort)22719)
32 /* c1 * c1' == 1 mod 2^16. */
33 #define crypt_c1_inverse ((ushort)27493)
34 #define encrypt_next(ch, state, chvar)\
35   (chvar = ((ch) ^ (state >> 8)),\
36    state = (chvar + state) * crypt_c1 + crypt_c2)
37 #define decrypt_this(ch, state)\
38   ((ch) ^ (state >> 8))
39 #define decrypt_next(ch, state, chvar)\
40   (chvar = decrypt_this(ch, state),\
41    decrypt_skip_next(ch, state))
42 #define decrypt_skip_next(ch, state)\
43   (state = ((ch) + state) * crypt_c1 + crypt_c2)
44 #define decrypt_skip_previous(ch, state)\
45   (state = (state - crypt_c2) * crypt_c1_inverse - (ch))
46 
47 #endif /* gscrypt1_INCLUDED */
48