1 /* Copyright (C) 2001-2019 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.,  1305 Grant Avenue - Suite 200, Novato,
13    CA 94945, 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 #include "stdpre.h"
23 
24 /* Normal public interface */
25 typedef ushort crypt_state;
26 int gs_type1_encrypt(byte * dest, const byte * src, uint len,
27                      crypt_state * pstate);
28 int gs_type1_decrypt(byte * dest, const byte * src, uint len,
29                      crypt_state * pstate);
30 
31 /* Define the encryption parameters and procedures. */
32 #define crypt_c1 ((ushort)52845)
33 #define crypt_c2 ((ushort)22719)
34 /* c1 * c1' == 1 mod 2^16. */
35 #define crypt_c1_inverse ((ushort)27493)
36 #define encrypt_next(ch, state, chvar)\
37   (chvar = ((ch) ^ (state >> 8)),\
38    state = (chvar + state) * crypt_c1 + crypt_c2)
39 #define decrypt_this(ch, state)\
40   ((ch) ^ (state >> 8))
41 #define decrypt_next(ch, state, chvar)\
42   (chvar = decrypt_this(ch, state),\
43    decrypt_skip_next(ch, state))
44 #define decrypt_skip_next(ch, state)\
45   (state = ((ch) + state) * crypt_c1 + crypt_c2)
46 #define decrypt_skip_previous(ch, state)\
47   (state = (state - crypt_c2) * crypt_c1_inverse - (ch))
48 
49 #endif /* gscrypt1_INCLUDED */
50