xref: /plan9/sys/src/cmd/gs/src/gscrypt1.c (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1999 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.c,v 1.4 2002/02/21 22:24:52 giles Exp $ */
18 /* Adobe Type 1 encryption/decryption. */
19 #include "stdpre.h"
20 #include "gstypes.h"
21 #include "gscrypt1.h"
22 
23 /* Encrypt a string. */
24 int
gs_type1_encrypt(byte * dest,const byte * src,uint len,crypt_state * pstate)25 gs_type1_encrypt(byte * dest, const byte * src, uint len, crypt_state * pstate)
26 {
27     crypt_state state = *pstate;
28     const byte *from = src;
29     byte *to = dest;
30     uint count = len;
31 
32     while (count) {
33 	encrypt_next(*from, state, *to);
34 	from++, to++, count--;
35     }
36     *pstate = state;
37     return 0;
38 }
39 /* Decrypt a string. */
40 int
gs_type1_decrypt(byte * dest,const byte * src,uint len,crypt_state * pstate)41 gs_type1_decrypt(byte * dest, const byte * src, uint len, crypt_state * pstate)
42 {
43     crypt_state state = *pstate;
44     const byte *from = src;
45     byte *to = dest;
46     uint count = len;
47 
48     while (count) {
49 	/* If from == to, we can't use the obvious */
50 	/*      decrypt_next(*from, state, *to);        */
51 	byte ch = *from++;
52 
53 	decrypt_next(ch, state, *to);
54 	to++, count--;
55     }
56     *pstate = state;
57     return 0;
58 }
59