xref: /plan9/sys/src/cmd/gs/src/gscrypt1.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1990, 1992, 1997 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gscrypt1.h,v 1.5 2002/06/16 08:45:42 lpd Exp $ */
18 /* Interface to Adobe Type 1 encryption/decryption. */
19 
20 #ifndef gscrypt1_INCLUDED
21 #  define gscrypt1_INCLUDED
22 
23 /* Normal public interface */
24 typedef ushort crypt_state;
25 int gs_type1_encrypt(byte * dest, const byte * src, uint len,
26 		     crypt_state * pstate);
27 int gs_type1_decrypt(byte * dest, const byte * src, uint len,
28 		     crypt_state * pstate);
29 
30 /* Define the encryption parameters and procedures. */
31 #define crypt_c1 ((ushort)52845)
32 #define crypt_c2 ((ushort)22719)
33 /* c1 * c1' == 1 mod 2^16. */
34 #define crypt_c1_inverse ((ushort)27493)
35 #define encrypt_next(ch, state, chvar)\
36   (chvar = ((ch) ^ (state >> 8)),\
37    state = (chvar + state) * crypt_c1 + crypt_c2)
38 #define decrypt_this(ch, state)\
39   ((ch) ^ (state >> 8))
40 #define decrypt_next(ch, state, chvar)\
41   (chvar = decrypt_this(ch, state),\
42    decrypt_skip_next(ch, state))
43 #define decrypt_skip_next(ch, state)\
44   (state = ((ch) + state) * crypt_c1 + crypt_c2)
45 #define decrypt_skip_previous(ch, state)\
46   (state = (state - crypt_c2) * crypt_c1_inverse - (ch))
47 
48 #endif /* gscrypt1_INCLUDED */
49