[gs-cvs] rev 8698 - branches/mtrender/src
ray at ghostscript.com
ray at ghostscript.com
Sun May 4 10:50:48 PDT 2008
Author: ray
Date: 2008-05-04 10:50:39 -0700 (Sun, 04 May 2008)
New Revision: 8698
Modified:
branches/mtrender/src/Makefile.in
branches/mtrender/src/aes.c
branches/mtrender/src/aes.h
branches/mtrender/src/configure.ac
branches/mtrender/src/echogs.c
branches/mtrender/src/gdevddrw.c
branches/mtrender/src/gdevdjet.c
branches/mtrender/src/gdevfax.c
branches/mtrender/src/gdevp14.c
branches/mtrender/src/gdevpdfb.c
branches/mtrender/src/gdevpdfo.c
branches/mtrender/src/gdevpdfu.c
branches/mtrender/src/gdevpdtb.c
branches/mtrender/src/gdevpdtf.h
branches/mtrender/src/gdevpdti.c
branches/mtrender/src/gdevpdtv.c
branches/mtrender/src/gdevpdtv.h
branches/mtrender/src/gdevps.c
branches/mtrender/src/gdevpsf.h
branches/mtrender/src/gdevpsft.c
branches/mtrender/src/gdevrinkj.c
branches/mtrender/src/gdevvec.c
branches/mtrender/src/gs.mak
branches/mtrender/src/gscdevn.c
branches/mtrender/src/gscedata.c
branches/mtrender/src/gscedata.h
branches/mtrender/src/gscspace.c
branches/mtrender/src/gscspace.h
branches/mtrender/src/gsdps1.c
branches/mtrender/src/gsicc.c
branches/mtrender/src/gsimage.c
branches/mtrender/src/gsnamecl.c
branches/mtrender/src/gsnamecl.h
branches/mtrender/src/gsncdummy.c
branches/mtrender/src/gsptype1.c
branches/mtrender/src/gsptype1.h
branches/mtrender/src/gsptype2.c
branches/mtrender/src/gxacpath.c
branches/mtrender/src/gxcht.c
branches/mtrender/src/gxclimag.c
branches/mtrender/src/gxclist.c
branches/mtrender/src/gxclist.h
branches/mtrender/src/gxclpath.c
branches/mtrender/src/gxclrast.c
branches/mtrender/src/gxclread.c
branches/mtrender/src/gxcmap.c
branches/mtrender/src/gxcspace.h
branches/mtrender/src/gxdcolor.c
branches/mtrender/src/gxdcolor.h
branches/mtrender/src/gxdevcli.h
branches/mtrender/src/gxht.c
branches/mtrender/src/gxicolor.c
branches/mtrender/src/gximask.c
branches/mtrender/src/gxp1fill.c
branches/mtrender/src/gxpcmap.c
branches/mtrender/src/gxpcolor.h
branches/mtrender/src/gxstroke.c
branches/mtrender/src/gxwts.c
branches/mtrender/src/icontext.c
branches/mtrender/src/icstate.h
branches/mtrender/src/int.mak
branches/mtrender/src/jasper.mak
branches/mtrender/src/jbig2.mak
branches/mtrender/src/lib.mak
branches/mtrender/src/msvc32.mak
branches/mtrender/src/psromfs.mak
branches/mtrender/src/sjpx_luratech.c
branches/mtrender/src/ugcclib.mak
branches/mtrender/src/version.mak
branches/mtrender/src/winint.mak
branches/mtrender/src/zchar42.c
branches/mtrender/src/zdscpars.c
branches/mtrender/src/zfjpx.c
branches/mtrender/src/zicc.c
branches/mtrender/src/zusparam.c
Log:
Update / Merge to trunk rev 8695 in preparation for moving the mtrender code
to the main sequence (trunk).
Modified: branches/mtrender/src/Makefile.in
===================================================================
--- branches/mtrender/src/Makefile.in 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/Makefile.in 2008-05-04 17:50:39 UTC (rev 8698)
@@ -251,7 +251,7 @@
# and shared object builds.
CFLAGS_STANDARD=@OPT_CFLAGS@
-CFLAGS_DEBUG=-g -O
+CFLAGS_DEBUG=-g -O0
CFLAGS_PROFILE=-pg @OPT_CFLAGS@
CFLAGS_SO=@DYNAMIC_CFLAGS@
@@ -304,8 +304,11 @@
# All reasonable platforms require -lm, but Rhapsody and perhaps one or
# two others fold libm into libc and don't require any additional library.
-STDLIBS=@PTHREAD_LIBS@ -lm
+#STDLIBS=-lpthread -lm
+# Since the default build is for nosync, don't include pthread lib
+STDLIBS=-lm
+
# Define the include switch(es) for the X11 header files.
# This can be null if handled in some other way (e.g., the files are
# in /usr/include, or the directory is supplied by an environment variable)
@@ -336,11 +339,12 @@
# primitives for this platform.
# If POSIX sync primitives are used, also change the STDLIBS to include
-# the pthread library. Otherwise use SYNC=nosync
+# the pthread library.
#SYNC=posync
-#SYNC=nosync
-SYNC=@SYNC@
+# Default is No sync primitives since some platforms don't have it (HP-UX)
+SYNC=nosync
+
# programs we use
RM=rm -f
Modified: branches/mtrender/src/aes.c
===================================================================
--- branches/mtrender/src/aes.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/aes.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -1,783 +1,784 @@
-/*
- ---------------------------------------------------------------------------
- Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.
-
- LICENSE TERMS
-
- The free distribution and use of this software in both source and binary
- form is allowed (with or without changes) provided that:
-
- 1. distributions of this source code include the above copyright
- notice, this list of conditions and the following disclaimer;
-
- 2. distributions in binary form include the above copyright
- notice, this list of conditions and the following disclaimer
- in the documentation and/or other associated materials;
-
- 3. the copyright holder's name is not used to endorse products
- built using this software without specific written permission.
-
- ALTERNATIVELY, provided that this notice is retained in full, this product
- may be distributed under the terms of the GNU General Public License (GPL),
- in which case the provisions of the GPL apply INSTEAD OF those given above.
-
- DISCLAIMER
-
- This software is provided 'as is' with no explicit or implied warranties
- in respect of its properties, including, but not limited to, correctness
- and/or fitness for purpose.
- ---------------------------------------------------------------------------
- Issue 09/09/2006
-
- This is an AES implementation that uses only 8-bit byte operations on the
- cipher state (there are options to use 32-bit types if available).
-
- The combination of mix columns and byte substitution used here is based on
- that developed by Karl Malbrain. His contribution is acknowledged.
- */
-
-/* define if you have a fast memcpy function on your system */
-#if 1
-# define HAVE_MEMCPY
-# include <string.h>
-# if defined( _MSC_VER )
-# include <intrin.h>
-# pragma intrinsic( memcpy )
-# endif
-#endif
-
-/* define if you have fast 32-bit types on your system */
-#if 1
-# define HAVE_UINT_32T
-#endif
-
-/* alternative versions (test for performance on your system) */
-#if 1
-# define VERSION_1
-#endif
-
-#include "aes.h"
-
-#define sb_data(w) {\
- w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\
- w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\
- w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\
- w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\
- w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\
- w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\
- w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\
- w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\
- w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\
- w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\
- w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\
- w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\
- w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\
- w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\
- w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\
- w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\
- w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\
- w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\
- w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\
- w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\
- w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\
- w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\
- w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\
- w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\
- w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\
- w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\
- w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\
- w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\
- w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\
- w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\
- w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\
- w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) }
-
-#define isb_data(w) {\
- w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), w(0x38),\
- w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), w(0xd7), w(0xfb),\
- w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), w(0x2f), w(0xff), w(0x87),\
- w(0x34), w(0x8e), w(0x43), w(0x44), w(0xc4), w(0xde), w(0xe9), w(0xcb),\
- w(0x54), w(0x7b), w(0x94), w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d),\
- w(0xee), w(0x4c), w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e),\
- w(0x08), w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2),\
- w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), w(0x25),\
- w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), w(0x98), w(0x16),\
- w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), w(0x65), w(0xb6), w(0x92),\
- w(0x6c), w(0x70), w(0x48), w(0x50), w(0xfd), w(0xed), w(0xb9), w(0xda),\
- w(0x5e), w(0x15), w(0x46), w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84),\
- w(0x90), w(0xd8), w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a),\
- w(0xf7), w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06),\
- w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), w(0x02),\
- w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), w(0x8a), w(0x6b),\
- w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), w(0x67), w(0xdc), w(0xea),\
- w(0x97), w(0xf2), w(0xcf), w(0xce), w(0xf0), w(0xb4), w(0xe6), w(0x73),\
- w(0x96), w(0xac), w(0x74), w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85),\
- w(0xe2), w(0xf9), w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e),\
- w(0x47), w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89),\
- w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), w(0x1b),\
- w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), w(0x79), w(0x20),\
- w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), w(0xcd), w(0x5a), w(0xf4),\
- w(0x1f), w(0xdd), w(0xa8), w(0x33), w(0x88), w(0x07), w(0xc7), w(0x31),\
- w(0xb1), w(0x12), w(0x10), w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f),\
- w(0x60), w(0x51), w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d),\
- w(0x2d), w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef),\
- w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), w(0xb0),\
- w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), w(0x99), w(0x61),\
- w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), w(0x77), w(0xd6), w(0x26),\
- w(0xe1), w(0x69), w(0x14), w(0x63), w(0x55), w(0x21), w(0x0c), w(0x7d) }
-
-#define mm_data(w) {\
- w(0x00), w(0x01), w(0x02), w(0x03), w(0x04), w(0x05), w(0x06), w(0x07),\
- w(0x08), w(0x09), w(0x0a), w(0x0b), w(0x0c), w(0x0d), w(0x0e), w(0x0f),\
- w(0x10), w(0x11), w(0x12), w(0x13), w(0x14), w(0x15), w(0x16), w(0x17),\
- w(0x18), w(0x19), w(0x1a), w(0x1b), w(0x1c), w(0x1d), w(0x1e), w(0x1f),\
- w(0x20), w(0x21), w(0x22), w(0x23), w(0x24), w(0x25), w(0x26), w(0x27),\
- w(0x28), w(0x29), w(0x2a), w(0x2b), w(0x2c), w(0x2d), w(0x2e), w(0x2f),\
- w(0x30), w(0x31), w(0x32), w(0x33), w(0x34), w(0x35), w(0x36), w(0x37),\
- w(0x38), w(0x39), w(0x3a), w(0x3b), w(0x3c), w(0x3d), w(0x3e), w(0x3f),\
- w(0x40), w(0x41), w(0x42), w(0x43), w(0x44), w(0x45), w(0x46), w(0x47),\
- w(0x48), w(0x49), w(0x4a), w(0x4b), w(0x4c), w(0x4d), w(0x4e), w(0x4f),\
- w(0x50), w(0x51), w(0x52), w(0x53), w(0x54), w(0x55), w(0x56), w(0x57),\
- w(0x58), w(0x59), w(0x5a), w(0x5b), w(0x5c), w(0x5d), w(0x5e), w(0x5f),\
- w(0x60), w(0x61), w(0x62), w(0x63), w(0x64), w(0x65), w(0x66), w(0x67),\
- w(0x68), w(0x69), w(0x6a), w(0x6b), w(0x6c), w(0x6d), w(0x6e), w(0x6f),\
- w(0x70), w(0x71), w(0x72), w(0x73), w(0x74), w(0x75), w(0x76), w(0x77),\
- w(0x78), w(0x79), w(0x7a), w(0x7b), w(0x7c), w(0x7d), w(0x7e), w(0x7f),\
- w(0x80), w(0x81), w(0x82), w(0x83), w(0x84), w(0x85), w(0x86), w(0x87),\
- w(0x88), w(0x89), w(0x8a), w(0x8b), w(0x8c), w(0x8d), w(0x8e), w(0x8f),\
- w(0x90), w(0x91), w(0x92), w(0x93), w(0x94), w(0x95), w(0x96), w(0x97),\
- w(0x98), w(0x99), w(0x9a), w(0x9b), w(0x9c), w(0x9d), w(0x9e), w(0x9f),\
- w(0xa0), w(0xa1), w(0xa2), w(0xa3), w(0xa4), w(0xa5), w(0xa6), w(0xa7),\
- w(0xa8), w(0xa9), w(0xaa), w(0xab), w(0xac), w(0xad), w(0xae), w(0xaf),\
- w(0xb0), w(0xb1), w(0xb2), w(0xb3), w(0xb4), w(0xb5), w(0xb6), w(0xb7),\
- w(0xb8), w(0xb9), w(0xba), w(0xbb), w(0xbc), w(0xbd), w(0xbe), w(0xbf),\
- w(0xc0), w(0xc1), w(0xc2), w(0xc3), w(0xc4), w(0xc5), w(0xc6), w(0xc7),\
- w(0xc8), w(0xc9), w(0xca), w(0xcb), w(0xcc), w(0xcd), w(0xce), w(0xcf),\
- w(0xd0), w(0xd1), w(0xd2), w(0xd3), w(0xd4), w(0xd5), w(0xd6), w(0xd7),\
- w(0xd8), w(0xd9), w(0xda), w(0xdb), w(0xdc), w(0xdd), w(0xde), w(0xdf),\
- w(0xe0), w(0xe1), w(0xe2), w(0xe3), w(0xe4), w(0xe5), w(0xe6), w(0xe7),\
- w(0xe8), w(0xe9), w(0xea), w(0xeb), w(0xec), w(0xed), w(0xee), w(0xef),\
- w(0xf0), w(0xf1), w(0xf2), w(0xf3), w(0xf4), w(0xf5), w(0xf6), w(0xf7),\
- w(0xf8), w(0xf9), w(0xfa), w(0xfb), w(0xfc), w(0xfd), w(0xfe), w(0xff) }
-
-#define WPOLY 0x011b
-#define DPOLY 0x008d
-#define f1(x) (x)
-#define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY))
-#define f4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY))
-#define f8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) \
- ^ (((x>>5) & 4) * WPOLY))
-#define d2(x) (((x) >> 1) ^ ((x) & 1 ? DPOLY : 0))
-
-#define f3(x) (f2(x) ^ x)
-#define f9(x) (f8(x) ^ x)
-#define fb(x) (f8(x) ^ f2(x) ^ x)
-#define fd(x) (f8(x) ^ f4(x) ^ x)
-#define fe(x) (f8(x) ^ f4(x) ^ f2(x))
-
-static const uint_8t s_box[256] = sb_data(f1);
-static const uint_8t inv_s_box[256] = isb_data(f1);
-
-static const uint_8t gfm2_s_box[256] = sb_data(f2);
-static const uint_8t gfm3_s_box[256] = sb_data(f3);
-
-static const uint_8t gfmul_9[256] = mm_data(f9);
-static const uint_8t gfmul_b[256] = mm_data(fb);
-static const uint_8t gfmul_d[256] = mm_data(fd);
-static const uint_8t gfmul_e[256] = mm_data(fe);
-
-#if defined( HAVE_UINT_32T )
- typedef unsigned long uint_32t;
-#endif
-
-#if defined( HAVE_MEMCPY )
-# define block_copy(d, s, l) memcpy(d, s, l)
-# define block16_copy(d, s) memcpy(d, s, N_BLOCK)
-#else
-# define block_copy(d, s, l) copy_block(d, s, l)
-# define block16_copy(d, s) copy_block16(d, s)
-#endif
-
-/* block size 'nn' must be a multiple of four */
-
-static void copy_block16( void *d, const void *s )
-{
-#if defined( HAVE_UINT_32T )
- ((uint_32t*)d)[ 0] = ((uint_32t*)s)[ 0];
- ((uint_32t*)d)[ 1] = ((uint_32t*)s)[ 1];
- ((uint_32t*)d)[ 2] = ((uint_32t*)s)[ 2];
- ((uint_32t*)d)[ 3] = ((uint_32t*)s)[ 3];
-#else
- ((uint_8t*)d)[ 0] = ((uint_8t*)s)[ 0];
- ((uint_8t*)d)[ 1] = ((uint_8t*)s)[ 1];
- ((uint_8t*)d)[ 2] = ((uint_8t*)s)[ 2];
- ((uint_8t*)d)[ 3] = ((uint_8t*)s)[ 3];
- ((uint_8t*)d)[ 4] = ((uint_8t*)s)[ 4];
- ((uint_8t*)d)[ 5] = ((uint_8t*)s)[ 5];
- ((uint_8t*)d)[ 6] = ((uint_8t*)s)[ 6];
- ((uint_8t*)d)[ 7] = ((uint_8t*)s)[ 7];
- ((uint_8t*)d)[ 8] = ((uint_8t*)s)[ 8];
- ((uint_8t*)d)[ 9] = ((uint_8t*)s)[ 9];
- ((uint_8t*)d)[10] = ((uint_8t*)s)[10];
- ((uint_8t*)d)[11] = ((uint_8t*)s)[11];
- ((uint_8t*)d)[12] = ((uint_8t*)s)[12];
- ((uint_8t*)d)[13] = ((uint_8t*)s)[13];
- ((uint_8t*)d)[14] = ((uint_8t*)s)[14];
- ((uint_8t*)d)[15] = ((uint_8t*)s)[15];
-#endif
-}
-
-static void copy_block( void * d, void *s, uint_8t nn )
-{
- while( nn-- )
- *((uint_8t*)d)++ = *((uint_8t*)s)++;
-}
-
-static void xor_block( void *d, const void *s )
-{
-#if defined( HAVE_UINT_32T )
- ((uint_32t*)d)[ 0] ^= ((uint_32t*)s)[ 0];
- ((uint_32t*)d)[ 1] ^= ((uint_32t*)s)[ 1];
- ((uint_32t*)d)[ 2] ^= ((uint_32t*)s)[ 2];
- ((uint_32t*)d)[ 3] ^= ((uint_32t*)s)[ 3];
-#else
- ((uint_8t*)d)[ 0] ^= ((uint_8t*)s)[ 0];
- ((uint_8t*)d)[ 1] ^= ((uint_8t*)s)[ 1];
- ((uint_8t*)d)[ 2] ^= ((uint_8t*)s)[ 2];
- ((uint_8t*)d)[ 3] ^= ((uint_8t*)s)[ 3];
- ((uint_8t*)d)[ 4] ^= ((uint_8t*)s)[ 4];
- ((uint_8t*)d)[ 5] ^= ((uint_8t*)s)[ 5];
- ((uint_8t*)d)[ 6] ^= ((uint_8t*)s)[ 6];
- ((uint_8t*)d)[ 7] ^= ((uint_8t*)s)[ 7];
- ((uint_8t*)d)[ 8] ^= ((uint_8t*)s)[ 8];
- ((uint_8t*)d)[ 9] ^= ((uint_8t*)s)[ 9];
- ((uint_8t*)d)[10] ^= ((uint_8t*)s)[10];
- ((uint_8t*)d)[11] ^= ((uint_8t*)s)[11];
- ((uint_8t*)d)[12] ^= ((uint_8t*)s)[12];
- ((uint_8t*)d)[13] ^= ((uint_8t*)s)[13];
- ((uint_8t*)d)[14] ^= ((uint_8t*)s)[14];
- ((uint_8t*)d)[15] ^= ((uint_8t*)s)[15];
-#endif
-}
-
-static void copy_and_key( void *d, const void *s, const void *k )
-{
-#if defined( HAVE_UINT_32T )
- ((uint_32t*)d)[ 0] = ((uint_32t*)s)[ 0] ^ ((uint_32t*)k)[ 0];
- ((uint_32t*)d)[ 1] = ((uint_32t*)s)[ 1] ^ ((uint_32t*)k)[ 1];
- ((uint_32t*)d)[ 2] = ((uint_32t*)s)[ 2] ^ ((uint_32t*)k)[ 2];
- ((uint_32t*)d)[ 3] = ((uint_32t*)s)[ 3] ^ ((uint_32t*)k)[ 3];
-#elif 1
- ((uint_8t*)d)[ 0] = ((uint_8t*)s)[ 0] ^ ((uint_8t*)k)[ 0];
- ((uint_8t*)d)[ 1] = ((uint_8t*)s)[ 1] ^ ((uint_8t*)k)[ 1];
- ((uint_8t*)d)[ 2] = ((uint_8t*)s)[ 2] ^ ((uint_8t*)k)[ 2];
- ((uint_8t*)d)[ 3] = ((uint_8t*)s)[ 3] ^ ((uint_8t*)k)[ 3];
- ((uint_8t*)d)[ 4] = ((uint_8t*)s)[ 4] ^ ((uint_8t*)k)[ 4];
- ((uint_8t*)d)[ 5] = ((uint_8t*)s)[ 5] ^ ((uint_8t*)k)[ 5];
- ((uint_8t*)d)[ 6] = ((uint_8t*)s)[ 6] ^ ((uint_8t*)k)[ 6];
- ((uint_8t*)d)[ 7] = ((uint_8t*)s)[ 7] ^ ((uint_8t*)k)[ 7];
- ((uint_8t*)d)[ 8] = ((uint_8t*)s)[ 8] ^ ((uint_8t*)k)[ 8];
- ((uint_8t*)d)[ 9] = ((uint_8t*)s)[ 9] ^ ((uint_8t*)k)[ 9];
- ((uint_8t*)d)[10] = ((uint_8t*)s)[10] ^ ((uint_8t*)k)[10];
- ((uint_8t*)d)[11] = ((uint_8t*)s)[11] ^ ((uint_8t*)k)[11];
- ((uint_8t*)d)[12] = ((uint_8t*)s)[12] ^ ((uint_8t*)k)[12];
- ((uint_8t*)d)[13] = ((uint_8t*)s)[13] ^ ((uint_8t*)k)[13];
- ((uint_8t*)d)[14] = ((uint_8t*)s)[14] ^ ((uint_8t*)k)[14];
- ((uint_8t*)d)[15] = ((uint_8t*)s)[15] ^ ((uint_8t*)k)[15];
-#else
- block16_copy(d, s);
- xor_block(d, k);
-#endif
-}
-
-static void add_round_key( uint_8t d[N_BLOCK], const uint_8t k[N_BLOCK] )
-{
- xor_block(d, k);
-}
-
-static void shift_sub_rows( uint_8t st[N_BLOCK] )
-{ uint_8t tt;
-
- st[ 0] = s_box[st[ 0]]; st[ 4] = s_box[st[ 4]];
- st[ 8] = s_box[st[ 8]]; st[12] = s_box[st[12]];
-
- tt = st[1]; st[ 1] = s_box[st[ 5]]; st[ 5] = s_box[st[ 9]];
- st[ 9] = s_box[st[13]]; st[13] = s_box[ tt ];
-
- tt = st[2]; st[ 2] = s_box[st[10]]; st[10] = s_box[ tt ];
- tt = st[6]; st[ 6] = s_box[st[14]]; st[14] = s_box[ tt ];
-
- tt = st[15]; st[15] = s_box[st[11]]; st[11] = s_box[st[ 7]];
- st[ 7] = s_box[st[ 3]]; st[ 3] = s_box[ tt ];
-}
-
-static void inv_shift_sub_rows( uint_8t st[N_BLOCK] )
-{ uint_8t tt;
-
- st[ 0] = inv_s_box[st[ 0]]; st[ 4] = inv_s_box[st[ 4]];
- st[ 8] = inv_s_box[st[ 8]]; st[12] = inv_s_box[st[12]];
-
- tt = st[13]; st[13] = inv_s_box[st[9]]; st[ 9] = inv_s_box[st[5]];
- st[ 5] = inv_s_box[st[1]]; st[ 1] = inv_s_box[ tt ];
-
- tt = st[2]; st[ 2] = inv_s_box[st[10]]; st[10] = inv_s_box[ tt ];
- tt = st[6]; st[ 6] = inv_s_box[st[14]]; st[14] = inv_s_box[ tt ];
-
- tt = st[3]; st[ 3] = inv_s_box[st[ 7]]; st[ 7] = inv_s_box[st[11]];
- st[11] = inv_s_box[st[15]]; st[15] = inv_s_box[ tt ];
-}
-
-#if defined( VERSION_1 )
- static void mix_sub_columns( uint_8t dt[N_BLOCK] )
- { uint_8t st[N_BLOCK];
- block16_copy(st, dt);
-#else
- static void mix_sub_columns( uint_8t dt[N_BLOCK], uint_8t st[N_BLOCK] )
- {
-#endif
- dt[ 0] = gfm2_s_box[st[0]] ^ gfm3_s_box[st[5]] ^ s_box[st[10]] ^ s_box[st[15]];
- dt[ 1] = s_box[st[0]] ^ gfm2_s_box[st[5]] ^ gfm3_s_box[st[10]] ^ s_box[st[15]];
- dt[ 2] = s_box[st[0]] ^ s_box[st[5]] ^ gfm2_s_box[st[10]] ^ gfm3_s_box[st[15]];
- dt[ 3] = gfm3_s_box[st[0]] ^ s_box[st[5]] ^ s_box[st[10]] ^ gfm2_s_box[st[15]];
-
- dt[ 4] = gfm2_s_box[st[4]] ^ gfm3_s_box[st[9]] ^ s_box[st[14]] ^ s_box[st[3]];
- dt[ 5] = s_box[st[4]] ^ gfm2_s_box[st[9]] ^ gfm3_s_box[st[14]] ^ s_box[st[3]];
- dt[ 6] = s_box[st[4]] ^ s_box[st[9]] ^ gfm2_s_box[st[14]] ^ gfm3_s_box[st[3]];
- dt[ 7] = gfm3_s_box[st[4]] ^ s_box[st[9]] ^ s_box[st[14]] ^ gfm2_s_box[st[3]];
-
- dt[ 8] = gfm2_s_box[st[8]] ^ gfm3_s_box[st[13]] ^ s_box[st[2]] ^ s_box[st[7]];
- dt[ 9] = s_box[st[8]] ^ gfm2_s_box[st[13]] ^ gfm3_s_box[st[2]] ^ s_box[st[7]];
- dt[10] = s_box[st[8]] ^ s_box[st[13]] ^ gfm2_s_box[st[2]] ^ gfm3_s_box[st[7]];
- dt[11] = gfm3_s_box[st[8]] ^ s_box[st[13]] ^ s_box[st[2]] ^ gfm2_s_box[st[7]];
-
- dt[12] = gfm2_s_box[st[12]] ^ gfm3_s_box[st[1]] ^ s_box[st[6]] ^ s_box[st[11]];
- dt[13] = s_box[st[12]] ^ gfm2_s_box[st[1]] ^ gfm3_s_box[st[6]] ^ s_box[st[11]];
- dt[14] = s_box[st[12]] ^ s_box[st[1]] ^ gfm2_s_box[st[6]] ^ gfm3_s_box[st[11]];
- dt[15] = gfm3_s_box[st[12]] ^ s_box[st[1]] ^ s_box[st[6]] ^ gfm2_s_box[st[11]];
- }
-
-#if defined( VERSION_1 )
- static void inv_mix_sub_columns( uint_8t dt[N_BLOCK] )
- { uint_8t st[N_BLOCK];
- block16_copy(st, dt);
-#else
- static void inv_mix_sub_columns( uint_8t dt[N_BLOCK], uint_8t st[N_BLOCK] )
- {
-#endif
- dt[ 0] = inv_s_box[gfmul_e[st[ 0]] ^ gfmul_b[st[ 1]] ^ gfmul_d[st[ 2]] ^ gfmul_9[st[ 3]]];
- dt[ 5] = inv_s_box[gfmul_9[st[ 0]] ^ gfmul_e[st[ 1]] ^ gfmul_b[st[ 2]] ^ gfmul_d[st[ 3]]];
- dt[10] = inv_s_box[gfmul_d[st[ 0]] ^ gfmul_9[st[ 1]] ^ gfmul_e[st[ 2]] ^ gfmul_b[st[ 3]]];
- dt[15] = inv_s_box[gfmul_b[st[ 0]] ^ gfmul_d[st[ 1]] ^ gfmul_9[st[ 2]] ^ gfmul_e[st[ 3]]];
-
- dt[ 4] = inv_s_box[gfmul_e[st[ 4]] ^ gfmul_b[st[ 5]] ^ gfmul_d[st[ 6]] ^ gfmul_9[st[ 7]]];
- dt[ 9] = inv_s_box[gfmul_9[st[ 4]] ^ gfmul_e[st[ 5]] ^ gfmul_b[st[ 6]] ^ gfmul_d[st[ 7]]];
- dt[14] = inv_s_box[gfmul_d[st[ 4]] ^ gfmul_9[st[ 5]] ^ gfmul_e[st[ 6]] ^ gfmul_b[st[ 7]]];
- dt[ 3] = inv_s_box[gfmul_b[st[ 4]] ^ gfmul_d[st[ 5]] ^ gfmul_9[st[ 6]] ^ gfmul_e[st[ 7]]];
-
- dt[ 8] = inv_s_box[gfmul_e[st[ 8]] ^ gfmul_b[st[ 9]] ^ gfmul_d[st[10]] ^ gfmul_9[st[11]]];
- dt[13] = inv_s_box[gfmul_9[st[ 8]] ^ gfmul_e[st[ 9]] ^ gfmul_b[st[10]] ^ gfmul_d[st[11]]];
- dt[ 2] = inv_s_box[gfmul_d[st[ 8]] ^ gfmul_9[st[ 9]] ^ gfmul_e[st[10]] ^ gfmul_b[st[11]]];
- dt[ 7] = inv_s_box[gfmul_b[st[ 8]] ^ gfmul_d[st[ 9]] ^ gfmul_9[st[10]] ^ gfmul_e[st[11]]];
-
- dt[12] = inv_s_box[gfmul_e[st[12]] ^ gfmul_b[st[13]] ^ gfmul_d[st[14]] ^ gfmul_9[st[15]]];
- dt[ 1] = inv_s_box[gfmul_9[st[12]] ^ gfmul_e[st[13]] ^ gfmul_b[st[14]] ^ gfmul_d[st[15]]];
- dt[ 6] = inv_s_box[gfmul_d[st[12]] ^ gfmul_9[st[13]] ^ gfmul_e[st[14]] ^ gfmul_b[st[15]]];
- dt[11] = inv_s_box[gfmul_b[st[12]] ^ gfmul_d[st[13]] ^ gfmul_9[st[14]] ^ gfmul_e[st[15]]];
- }
-
-#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED )
-
-/* Set the cipher key for the pre-keyed version */
-
-return_type aes_set_key( const unsigned char key[], length_type keylen, aes_context ctx[1] )
-{
- uint_8t cc, rc, hi;
-
- switch( keylen )
- {
- case 16:
- case 128:
- keylen = 16;
- break;
- case 24:
- case 192:
- keylen = 24;
- break;
- case 32:
- case 256:
- keylen = 32;
- break;
- default:
- ctx->rnd = 0;
- return -1;
- }
- block_copy(ctx->ksch, key, keylen);
- hi = (keylen + 28) << 2;
- ctx->rnd = (hi >> 4) - 1;
- for( cc = keylen, rc = 1; cc < hi; cc += 4 )
- { uint_8t tt, t0, t1, t2, t3;
-
- t0 = ctx->ksch[cc - 4];
- t1 = ctx->ksch[cc - 3];
- t2 = ctx->ksch[cc - 2];
- t3 = ctx->ksch[cc - 1];
- if( cc % keylen == 0 )
- {
- tt = t0;
- t0 = s_box[t1] ^ rc;
- t1 = s_box[t2];
- t2 = s_box[t3];
- t3 = s_box[tt];
- rc = f2(rc);
- }
- else if( keylen > 24 && cc % keylen == 16 )
- {
- t0 = s_box[t0];
- t1 = s_box[t1];
- t2 = s_box[t2];
- t3 = s_box[t3];
- }
- tt = cc - keylen;
- ctx->ksch[cc + 0] = ctx->ksch[tt + 0] ^ t0;
- ctx->ksch[cc + 1] = ctx->ksch[tt + 1] ^ t1;
- ctx->ksch[cc + 2] = ctx->ksch[tt + 2] ^ t2;
- ctx->ksch[cc + 3] = ctx->ksch[tt + 3] ^ t3;
- }
- return 0;
-}
-
-#endif
-
-#if defined( AES_ENC_PREKEYED )
-
-/* Encrypt a single block of 16 bytes */
-
-return_type aes_encrypt( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], const aes_context ctx[1] )
-{
- if( ctx->rnd )
- {
- uint_8t s1[N_BLOCK], r;
- copy_and_key( s1, in, ctx->ksch );
-
- for( r = 1 ; r < ctx->rnd ; ++r )
-#if defined( VERSION_1 )
- {
- mix_sub_columns( s1 );
- add_round_key( s1, ctx->ksch + r * N_BLOCK);
- }
-#else
- { uint_8t s2[N_BLOCK];
- mix_sub_columns( s2, s1 );
- copy_and_key( s1, s2, ctx->ksch + r * N_BLOCK);
- }
-#endif
- shift_sub_rows( s1 );
- copy_and_key( out, s1, ctx->ksch + r * N_BLOCK );
- }
- else
- return -1;
- return 0;
-}
-
-#endif
-
-#if defined( AES_DEC_PREKEYED )
-
-/* Decrypt a single block of 16 bytes */
-
-return_type aes_decrypt( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], const aes_context ctx[1] )
-{
- if( ctx->rnd )
- {
- uint_8t s1[N_BLOCK], r;
- copy_and_key( s1, in, ctx->ksch + ctx->rnd * N_BLOCK );
- inv_shift_sub_rows( s1 );
-
- for( r = ctx->rnd ; --r ; )
-#if defined( VERSION_1 )
- {
- add_round_key( s1, ctx->ksch + r * N_BLOCK );
- inv_mix_sub_columns( s1 );
- }
-#else
- { uint_8t s2[N_BLOCK];
- copy_and_key( s2, s1, ctx->ksch + r * N_BLOCK );
- inv_mix_sub_columns( s1, s2 );
- }
-#endif
- copy_and_key( out, s1, ctx->ksch );
- }
- else
- return -1;
- return 0;
-}
-
-#endif
-
-#if defined( AES_ENC_128_OTFK )
-
-/* The 'on the fly' encryption key update for for 128 bit keys */
-
-static void update_encrypt_key_128( uint_8t k[N_BLOCK], uint_8t *rc )
-{ uint_8t cc;
-
- k[0] ^= s_box[k[13]] ^ *rc;
- k[1] ^= s_box[k[14]];
- k[2] ^= s_box[k[15]];
- k[3] ^= s_box[k[12]];
- *rc = f2( *rc );
-
- for(cc = 4; cc < 16; cc += 4 )
- {
- k[cc + 0] ^= k[cc - 4];
- k[cc + 1] ^= k[cc - 3];
- k[cc + 2] ^= k[cc - 2];
- k[cc + 3] ^= k[cc - 1];
- }
-}
-
-/* Encrypt a single block of 16 bytes with 'on the fly' 128 bit keying */
-
-void aes_encrypt_128( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK],
- const unsigned char key[N_BLOCK], unsigned char o_key[N_BLOCK] )
-{ uint_8t s1[N_BLOCK], r, rc = 1;
-
- if(o_key != key)
- block16_copy( o_key, key );
- copy_and_key( s1, in, o_key );
-
- for( r = 1 ; r < 10 ; ++r )
-#if defined( VERSION_1 )
- {
- mix_sub_columns( s1 );
- update_encrypt_key_128( o_key, &rc );
- add_round_key( s1, o_key );
- }
-#else
- { uint_8t s2[N_BLOCK];
- mix_sub_columns( s2, s1 );
- update_encrypt_key_128( o_key, &rc );
- copy_and_key( s1, s2, o_key );
- }
-#endif
-
- shift_sub_rows( s1 );
- update_encrypt_key_128( o_key, &rc );
- copy_and_key( out, s1, o_key );
-}
-
-#endif
-
-#if defined( AES_DEC_128_OTFK )
-
-/* The 'on the fly' decryption key update for for 128 bit keys */
-
-static void update_decrypt_key_128( uint_8t k[N_BLOCK], uint_8t *rc )
-{ uint_8t cc;
-
- for( cc = 12; cc > 0; cc -= 4 )
- {
- k[cc + 0] ^= k[cc - 4];
- k[cc + 1] ^= k[cc - 3];
- k[cc + 2] ^= k[cc - 2];
- k[cc + 3] ^= k[cc - 1];
- }
- *rc = d2(*rc);
- k[0] ^= s_box[k[13]] ^ *rc;
- k[1] ^= s_box[k[14]];
- k[2] ^= s_box[k[15]];
- k[3] ^= s_box[k[12]];
-}
-
-/* Decrypt a single block of 16 bytes with 'on the fly' 128 bit keying */
-
-void aes_decrypt_128( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK],
- const unsigned char key[N_BLOCK], unsigned char o_key[N_BLOCK] )
-{
- uint_8t s1[N_BLOCK], r, rc = 0x6c;
- if(o_key != key)
- block16_copy( o_key, key );
-
- copy_and_key( s1, in, o_key );
- inv_shift_sub_rows( s1 );
-
- for( r = 10 ; --r ; )
-#if defined( VERSION_1 )
- {
- update_decrypt_key_128( o_key, &rc );
- add_round_key( s1, o_key );
- inv_mix_sub_columns( s1 );
- }
-#else
- { uint_8t s2[N_BLOCK];
- update_decrypt_key_128( o_key, &rc );
- copy_and_key( s2, s1, o_key );
- inv_mix_sub_columns( s1, s2 );
- }
-#endif
- update_decrypt_key_128( o_key, &rc );
- copy_and_key( out, s1, o_key );
-}
-
-#endif
-
-#if defined( AES_ENC_256_OTFK )
-
-/* The 'on the fly' encryption key update for for 256 bit keys */
-
-static void update_encrypt_key_256( uint_8t k[2 * N_BLOCK], uint_8t *rc )
-{ uint_8t cc;
-
- k[0] ^= s_box[k[29]] ^ *rc;
- k[1] ^= s_box[k[30]];
- k[2] ^= s_box[k[31]];
- k[3] ^= s_box[k[28]];
- *rc = f2( *rc );
-
- for(cc = 4; cc < 16; cc += 4)
- {
- k[cc + 0] ^= k[cc - 4];
- k[cc + 1] ^= k[cc - 3];
- k[cc + 2] ^= k[cc - 2];
- k[cc + 3] ^= k[cc - 1];
- }
-
- k[16] ^= s_box[k[12]];
- k[17] ^= s_box[k[13]];
- k[18] ^= s_box[k[14]];
- k[19] ^= s_box[k[15]];
-
- for( cc = 20; cc < 32; cc += 4 )
- {
- k[cc + 0] ^= k[cc - 4];
- k[cc + 1] ^= k[cc - 3];
- k[cc + 2] ^= k[cc - 2];
- k[cc + 3] ^= k[cc - 1];
- }
-}
-
-/* Encrypt a single block of 16 bytes with 'on the fly' 256 bit keying */
-
-void aes_encrypt_256( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK],
- const unsigned char key[2 * N_BLOCK], unsigned char o_key[2 * N_BLOCK] )
-{
- uint_8t s1[N_BLOCK], r, rc = 1;
- if(o_key != key)
- {
- block16_copy( o_key, key );
- block16_copy( o_key + 16, key + 16 );
- }
- copy_and_key( s1, in, o_key );
-
- for( r = 1 ; r < 14 ; ++r )
-#if defined( VERSION_1 )
- {
- mix_sub_columns(s1);
- if( r & 1 )
- add_round_key( s1, o_key + 16 );
- else
- {
- update_encrypt_key_256( o_key, &rc );
- add_round_key( s1, o_key );
- }
- }
-#else
- { uint_8t s2[N_BLOCK];
- mix_sub_columns( s2, s1 );
- if( r & 1 )
- copy_and_key( s1, s2, o_key + 16 );
- else
- {
- update_encrypt_key_256( o_key, &rc );
- copy_and_key( s1, s2, o_key );
- }
- }
-#endif
-
- shift_sub_rows( s1 );
- update_encrypt_key_256( o_key, &rc );
- copy_and_key( out, s1, o_key );
-}
-
-#endif
-
-#if defined( AES_DEC_256_OTFK )
-
-/* The 'on the fly' encryption key update for for 256 bit keys */
-
-static void update_decrypt_key_256( uint_8t k[2 * N_BLOCK], uint_8t *rc )
-{ uint_8t cc;
-
- for(cc = 28; cc > 16; cc -= 4)
- {
- k[cc + 0] ^= k[cc - 4];
- k[cc + 1] ^= k[cc - 3];
- k[cc + 2] ^= k[cc - 2];
- k[cc + 3] ^= k[cc - 1];
- }
-
- k[16] ^= s_box[k[12]];
- k[17] ^= s_box[k[13]];
- k[18] ^= s_box[k[14]];
- k[19] ^= s_box[k[15]];
-
- for(cc = 12; cc > 0; cc -= 4)
- {
- k[cc + 0] ^= k[cc - 4];
- k[cc + 1] ^= k[cc - 3];
- k[cc + 2] ^= k[cc - 2];
- k[cc + 3] ^= k[cc - 1];
- }
-
- *rc = d2(*rc);
- k[0] ^= s_box[k[29]] ^ *rc;
- k[1] ^= s_box[k[30]];
- k[2] ^= s_box[k[31]];
- k[3] ^= s_box[k[28]];
-}
-
-/* Decrypt a single block of 16 bytes with 'on the fly'
- 256 bit keying
-*/
-void aes_decrypt_256( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK],
- const unsigned char key[2 * N_BLOCK], unsigned char o_key[2 * N_BLOCK] )
-{
- uint_8t s1[N_BLOCK], r, rc = 0x80;
-
- if(o_key != key)
- {
- block16_copy( o_key, key );
- block16_copy( o_key + 16, key + 16 );
- }
-
- copy_and_key( s1, in, o_key );
- inv_shift_sub_rows( s1 );
-
- for( r = 14 ; --r ; )
-#if defined( VERSION_1 )
- {
- if( ( r & 1 ) )
- {
- update_decrypt_key_256( o_key, &rc );
- add_round_key( s1, o_key + 16 );
- }
- else
- add_round_key( s1, o_key );
- inv_mix_sub_columns( s1 );
- }
-#else
- { uint_8t s2[N_BLOCK];
- if( ( r & 1 ) )
- {
- update_decrypt_key_256( o_key, &rc );
- copy_and_key( s2, s1, o_key + 16 );
- }
- else
- copy_and_key( s2, s1, o_key );
- inv_mix_sub_columns( s1, s2 );
- }
-#endif
- copy_and_key( out, s1, o_key );
-}
-
-#endif
+/*
+ ---------------------------------------------------------------------------
+ Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.
+
+ LICENSE TERMS
+
+ The free distribution and use of this software in both source and binary
+ form is allowed (with or without changes) provided that:
+
+ 1. distributions of this source code include the above copyright
+ notice, this list of conditions and the following disclaimer;
+
+ 2. distributions in binary form include the above copyright
+ notice, this list of conditions and the following disclaimer
+ in the documentation and/or other associated materials;
+
+ 3. the copyright holder's name is not used to endorse products
+ built using this software without specific written permission.
+
+ ALTERNATIVELY, provided that this notice is retained in full, this product
+ may be distributed under the terms of the GNU General Public License (GPL),
+ in which case the provisions of the GPL apply INSTEAD OF those given above.
+
+ DISCLAIMER
+
+ This software is provided 'as is' with no explicit or implied warranties
+ in respect of its properties, including, but not limited to, correctness
+ and/or fitness for purpose.
+ ---------------------------------------------------------------------------
+ Issue 09/09/2006
+
+ This is an AES implementation that uses only 8-bit byte operations on the
+ cipher state (there are options to use 32-bit types if available).
+
+ The combination of mix columns and byte substitution used here is based on
+ that developed by Karl Malbrain. His contribution is acknowledged.
+ */
+/* $Id: aes.c 8686 2008-05-02 01:42:14Z giles $ */
+
+/* define if you have a fast memcpy function on your system */
+#if 1
+# define HAVE_MEMCPY
+# include <string.h>
+# if defined( _MSC_VER )
+# include <intrin.h>
+# pragma intrinsic( memcpy )
+# endif
+#endif
+
+/* define if you have fast 32-bit types on your system */
+#if 1
+# define HAVE_UINT_32T
+#endif
+
+/* alternative versions (test for performance on your system) */
+#if 1
+# define VERSION_1
+#endif
+
+#include "aes.h"
+
+#define sb_data(w) {\
+ w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\
+ w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\
+ w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\
+ w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\
+ w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\
+ w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\
+ w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\
+ w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\
+ w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\
+ w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\
+ w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\
+ w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\
+ w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\
+ w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\
+ w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\
+ w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\
+ w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\
+ w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\
+ w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\
+ w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\
+ w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\
+ w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\
+ w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\
+ w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\
+ w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\
+ w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\
+ w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\
+ w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\
+ w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\
+ w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\
+ w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\
+ w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) }
+
+#define isb_data(w) {\
+ w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), w(0x38),\
+ w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), w(0xd7), w(0xfb),\
+ w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), w(0x2f), w(0xff), w(0x87),\
+ w(0x34), w(0x8e), w(0x43), w(0x44), w(0xc4), w(0xde), w(0xe9), w(0xcb),\
+ w(0x54), w(0x7b), w(0x94), w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d),\
+ w(0xee), w(0x4c), w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e),\
+ w(0x08), w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2),\
+ w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), w(0x25),\
+ w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), w(0x98), w(0x16),\
+ w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), w(0x65), w(0xb6), w(0x92),\
+ w(0x6c), w(0x70), w(0x48), w(0x50), w(0xfd), w(0xed), w(0xb9), w(0xda),\
+ w(0x5e), w(0x15), w(0x46), w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84),\
+ w(0x90), w(0xd8), w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a),\
+ w(0xf7), w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06),\
+ w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), w(0x02),\
+ w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), w(0x8a), w(0x6b),\
+ w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), w(0x67), w(0xdc), w(0xea),\
+ w(0x97), w(0xf2), w(0xcf), w(0xce), w(0xf0), w(0xb4), w(0xe6), w(0x73),\
+ w(0x96), w(0xac), w(0x74), w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85),\
+ w(0xe2), w(0xf9), w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e),\
+ w(0x47), w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89),\
+ w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), w(0x1b),\
+ w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), w(0x79), w(0x20),\
+ w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), w(0xcd), w(0x5a), w(0xf4),\
+ w(0x1f), w(0xdd), w(0xa8), w(0x33), w(0x88), w(0x07), w(0xc7), w(0x31),\
+ w(0xb1), w(0x12), w(0x10), w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f),\
+ w(0x60), w(0x51), w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d),\
+ w(0x2d), w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef),\
+ w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), w(0xb0),\
+ w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), w(0x99), w(0x61),\
+ w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), w(0x77), w(0xd6), w(0x26),\
+ w(0xe1), w(0x69), w(0x14), w(0x63), w(0x55), w(0x21), w(0x0c), w(0x7d) }
+
+#define mm_data(w) {\
+ w(0x00), w(0x01), w(0x02), w(0x03), w(0x04), w(0x05), w(0x06), w(0x07),\
+ w(0x08), w(0x09), w(0x0a), w(0x0b), w(0x0c), w(0x0d), w(0x0e), w(0x0f),\
+ w(0x10), w(0x11), w(0x12), w(0x13), w(0x14), w(0x15), w(0x16), w(0x17),\
+ w(0x18), w(0x19), w(0x1a), w(0x1b), w(0x1c), w(0x1d), w(0x1e), w(0x1f),\
+ w(0x20), w(0x21), w(0x22), w(0x23), w(0x24), w(0x25), w(0x26), w(0x27),\
+ w(0x28), w(0x29), w(0x2a), w(0x2b), w(0x2c), w(0x2d), w(0x2e), w(0x2f),\
+ w(0x30), w(0x31), w(0x32), w(0x33), w(0x34), w(0x35), w(0x36), w(0x37),\
+ w(0x38), w(0x39), w(0x3a), w(0x3b), w(0x3c), w(0x3d), w(0x3e), w(0x3f),\
+ w(0x40), w(0x41), w(0x42), w(0x43), w(0x44), w(0x45), w(0x46), w(0x47),\
+ w(0x48), w(0x49), w(0x4a), w(0x4b), w(0x4c), w(0x4d), w(0x4e), w(0x4f),\
+ w(0x50), w(0x51), w(0x52), w(0x53), w(0x54), w(0x55), w(0x56), w(0x57),\
+ w(0x58), w(0x59), w(0x5a), w(0x5b), w(0x5c), w(0x5d), w(0x5e), w(0x5f),\
+ w(0x60), w(0x61), w(0x62), w(0x63), w(0x64), w(0x65), w(0x66), w(0x67),\
+ w(0x68), w(0x69), w(0x6a), w(0x6b), w(0x6c), w(0x6d), w(0x6e), w(0x6f),\
+ w(0x70), w(0x71), w(0x72), w(0x73), w(0x74), w(0x75), w(0x76), w(0x77),\
+ w(0x78), w(0x79), w(0x7a), w(0x7b), w(0x7c), w(0x7d), w(0x7e), w(0x7f),\
+ w(0x80), w(0x81), w(0x82), w(0x83), w(0x84), w(0x85), w(0x86), w(0x87),\
+ w(0x88), w(0x89), w(0x8a), w(0x8b), w(0x8c), w(0x8d), w(0x8e), w(0x8f),\
+ w(0x90), w(0x91), w(0x92), w(0x93), w(0x94), w(0x95), w(0x96), w(0x97),\
+ w(0x98), w(0x99), w(0x9a), w(0x9b), w(0x9c), w(0x9d), w(0x9e), w(0x9f),\
+ w(0xa0), w(0xa1), w(0xa2), w(0xa3), w(0xa4), w(0xa5), w(0xa6), w(0xa7),\
+ w(0xa8), w(0xa9), w(0xaa), w(0xab), w(0xac), w(0xad), w(0xae), w(0xaf),\
+ w(0xb0), w(0xb1), w(0xb2), w(0xb3), w(0xb4), w(0xb5), w(0xb6), w(0xb7),\
+ w(0xb8), w(0xb9), w(0xba), w(0xbb), w(0xbc), w(0xbd), w(0xbe), w(0xbf),\
+ w(0xc0), w(0xc1), w(0xc2), w(0xc3), w(0xc4), w(0xc5), w(0xc6), w(0xc7),\
+ w(0xc8), w(0xc9), w(0xca), w(0xcb), w(0xcc), w(0xcd), w(0xce), w(0xcf),\
+ w(0xd0), w(0xd1), w(0xd2), w(0xd3), w(0xd4), w(0xd5), w(0xd6), w(0xd7),\
+ w(0xd8), w(0xd9), w(0xda), w(0xdb), w(0xdc), w(0xdd), w(0xde), w(0xdf),\
+ w(0xe0), w(0xe1), w(0xe2), w(0xe3), w(0xe4), w(0xe5), w(0xe6), w(0xe7),\
+ w(0xe8), w(0xe9), w(0xea), w(0xeb), w(0xec), w(0xed), w(0xee), w(0xef),\
+ w(0xf0), w(0xf1), w(0xf2), w(0xf3), w(0xf4), w(0xf5), w(0xf6), w(0xf7),\
+ w(0xf8), w(0xf9), w(0xfa), w(0xfb), w(0xfc), w(0xfd), w(0xfe), w(0xff) }
+
+#define WPOLY 0x011b
+#define DPOLY 0x008d
+#define f1(x) (x)
+#define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY))
+#define f4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY))
+#define f8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) \
+ ^ (((x>>5) & 4) * WPOLY))
+#define d2(x) (((x) >> 1) ^ ((x) & 1 ? DPOLY : 0))
+
+#define f3(x) (f2(x) ^ x)
+#define f9(x) (f8(x) ^ x)
+#define fb(x) (f8(x) ^ f2(x) ^ x)
+#define fd(x) (f8(x) ^ f4(x) ^ x)
+#define fe(x) (f8(x) ^ f4(x) ^ f2(x))
+
+static const uint_8t s_box[256] = sb_data(f1);
+static const uint_8t inv_s_box[256] = isb_data(f1);
+
+static const uint_8t gfm2_s_box[256] = sb_data(f2);
+static const uint_8t gfm3_s_box[256] = sb_data(f3);
+
+static const uint_8t gfmul_9[256] = mm_data(f9);
+static const uint_8t gfmul_b[256] = mm_data(fb);
+static const uint_8t gfmul_d[256] = mm_data(fd);
+static const uint_8t gfmul_e[256] = mm_data(fe);
+
+#if defined( HAVE_UINT_32T )
+ typedef unsigned long uint_32t;
+#endif
+
+#if defined( HAVE_MEMCPY )
+# define block_copy(d, s, l) memcpy(d, s, l)
+# define block16_copy(d, s) memcpy(d, s, N_BLOCK)
+#else
+# define block_copy(d, s, l) copy_block(d, s, l)
+# define block16_copy(d, s) copy_block16(d, s)
+#endif
+
+/* block size 'nn' must be a multiple of four */
+
+static void copy_block16( void *d, const void *s )
+{
+#if defined( HAVE_UINT_32T )
+ ((uint_32t*)d)[ 0] = ((uint_32t*)s)[ 0];
+ ((uint_32t*)d)[ 1] = ((uint_32t*)s)[ 1];
+ ((uint_32t*)d)[ 2] = ((uint_32t*)s)[ 2];
+ ((uint_32t*)d)[ 3] = ((uint_32t*)s)[ 3];
+#else
+ ((uint_8t*)d)[ 0] = ((uint_8t*)s)[ 0];
+ ((uint_8t*)d)[ 1] = ((uint_8t*)s)[ 1];
+ ((uint_8t*)d)[ 2] = ((uint_8t*)s)[ 2];
+ ((uint_8t*)d)[ 3] = ((uint_8t*)s)[ 3];
+ ((uint_8t*)d)[ 4] = ((uint_8t*)s)[ 4];
+ ((uint_8t*)d)[ 5] = ((uint_8t*)s)[ 5];
+ ((uint_8t*)d)[ 6] = ((uint_8t*)s)[ 6];
+ ((uint_8t*)d)[ 7] = ((uint_8t*)s)[ 7];
+ ((uint_8t*)d)[ 8] = ((uint_8t*)s)[ 8];
+ ((uint_8t*)d)[ 9] = ((uint_8t*)s)[ 9];
+ ((uint_8t*)d)[10] = ((uint_8t*)s)[10];
+ ((uint_8t*)d)[11] = ((uint_8t*)s)[11];
+ ((uint_8t*)d)[12] = ((uint_8t*)s)[12];
+ ((uint_8t*)d)[13] = ((uint_8t*)s)[13];
+ ((uint_8t*)d)[14] = ((uint_8t*)s)[14];
+ ((uint_8t*)d)[15] = ((uint_8t*)s)[15];
+#endif
+}
+
+static void copy_block( void * d, void *s, uint_8t nn )
+{
+ while( nn-- )
+ *((uint_8t*)d)++ = *((uint_8t*)s)++;
+}
+
+static void xor_block( void *d, const void *s )
+{
+#if defined( HAVE_UINT_32T )
+ ((uint_32t*)d)[ 0] ^= ((uint_32t*)s)[ 0];
+ ((uint_32t*)d)[ 1] ^= ((uint_32t*)s)[ 1];
+ ((uint_32t*)d)[ 2] ^= ((uint_32t*)s)[ 2];
+ ((uint_32t*)d)[ 3] ^= ((uint_32t*)s)[ 3];
+#else
+ ((uint_8t*)d)[ 0] ^= ((uint_8t*)s)[ 0];
+ ((uint_8t*)d)[ 1] ^= ((uint_8t*)s)[ 1];
+ ((uint_8t*)d)[ 2] ^= ((uint_8t*)s)[ 2];
+ ((uint_8t*)d)[ 3] ^= ((uint_8t*)s)[ 3];
+ ((uint_8t*)d)[ 4] ^= ((uint_8t*)s)[ 4];
+ ((uint_8t*)d)[ 5] ^= ((uint_8t*)s)[ 5];
+ ((uint_8t*)d)[ 6] ^= ((uint_8t*)s)[ 6];
+ ((uint_8t*)d)[ 7] ^= ((uint_8t*)s)[ 7];
+ ((uint_8t*)d)[ 8] ^= ((uint_8t*)s)[ 8];
+ ((uint_8t*)d)[ 9] ^= ((uint_8t*)s)[ 9];
+ ((uint_8t*)d)[10] ^= ((uint_8t*)s)[10];
+ ((uint_8t*)d)[11] ^= ((uint_8t*)s)[11];
+ ((uint_8t*)d)[12] ^= ((uint_8t*)s)[12];
+ ((uint_8t*)d)[13] ^= ((uint_8t*)s)[13];
+ ((uint_8t*)d)[14] ^= ((uint_8t*)s)[14];
+ ((uint_8t*)d)[15] ^= ((uint_8t*)s)[15];
+#endif
+}
+
+static void copy_and_key( void *d, const void *s, const void *k )
+{
+#if defined( HAVE_UINT_32T )
+ ((uint_32t*)d)[ 0] = ((uint_32t*)s)[ 0] ^ ((uint_32t*)k)[ 0];
+ ((uint_32t*)d)[ 1] = ((uint_32t*)s)[ 1] ^ ((uint_32t*)k)[ 1];
+ ((uint_32t*)d)[ 2] = ((uint_32t*)s)[ 2] ^ ((uint_32t*)k)[ 2];
+ ((uint_32t*)d)[ 3] = ((uint_32t*)s)[ 3] ^ ((uint_32t*)k)[ 3];
+#elif 1
+ ((uint_8t*)d)[ 0] = ((uint_8t*)s)[ 0] ^ ((uint_8t*)k)[ 0];
+ ((uint_8t*)d)[ 1] = ((uint_8t*)s)[ 1] ^ ((uint_8t*)k)[ 1];
+ ((uint_8t*)d)[ 2] = ((uint_8t*)s)[ 2] ^ ((uint_8t*)k)[ 2];
+ ((uint_8t*)d)[ 3] = ((uint_8t*)s)[ 3] ^ ((uint_8t*)k)[ 3];
+ ((uint_8t*)d)[ 4] = ((uint_8t*)s)[ 4] ^ ((uint_8t*)k)[ 4];
+ ((uint_8t*)d)[ 5] = ((uint_8t*)s)[ 5] ^ ((uint_8t*)k)[ 5];
+ ((uint_8t*)d)[ 6] = ((uint_8t*)s)[ 6] ^ ((uint_8t*)k)[ 6];
+ ((uint_8t*)d)[ 7] = ((uint_8t*)s)[ 7] ^ ((uint_8t*)k)[ 7];
+ ((uint_8t*)d)[ 8] = ((uint_8t*)s)[ 8] ^ ((uint_8t*)k)[ 8];
+ ((uint_8t*)d)[ 9] = ((uint_8t*)s)[ 9] ^ ((uint_8t*)k)[ 9];
+ ((uint_8t*)d)[10] = ((uint_8t*)s)[10] ^ ((uint_8t*)k)[10];
+ ((uint_8t*)d)[11] = ((uint_8t*)s)[11] ^ ((uint_8t*)k)[11];
+ ((uint_8t*)d)[12] = ((uint_8t*)s)[12] ^ ((uint_8t*)k)[12];
+ ((uint_8t*)d)[13] = ((uint_8t*)s)[13] ^ ((uint_8t*)k)[13];
+ ((uint_8t*)d)[14] = ((uint_8t*)s)[14] ^ ((uint_8t*)k)[14];
+ ((uint_8t*)d)[15] = ((uint_8t*)s)[15] ^ ((uint_8t*)k)[15];
+#else
+ block16_copy(d, s);
+ xor_block(d, k);
+#endif
+}
+
+static void add_round_key( uint_8t d[N_BLOCK], const uint_8t k[N_BLOCK] )
+{
+ xor_block(d, k);
+}
+
+static void shift_sub_rows( uint_8t st[N_BLOCK] )
+{ uint_8t tt;
+
+ st[ 0] = s_box[st[ 0]]; st[ 4] = s_box[st[ 4]];
+ st[ 8] = s_box[st[ 8]]; st[12] = s_box[st[12]];
+
+ tt = st[1]; st[ 1] = s_box[st[ 5]]; st[ 5] = s_box[st[ 9]];
+ st[ 9] = s_box[st[13]]; st[13] = s_box[ tt ];
+
+ tt = st[2]; st[ 2] = s_box[st[10]]; st[10] = s_box[ tt ];
+ tt = st[6]; st[ 6] = s_box[st[14]]; st[14] = s_box[ tt ];
+
+ tt = st[15]; st[15] = s_box[st[11]]; st[11] = s_box[st[ 7]];
+ st[ 7] = s_box[st[ 3]]; st[ 3] = s_box[ tt ];
+}
+
+static void inv_shift_sub_rows( uint_8t st[N_BLOCK] )
+{ uint_8t tt;
+
+ st[ 0] = inv_s_box[st[ 0]]; st[ 4] = inv_s_box[st[ 4]];
+ st[ 8] = inv_s_box[st[ 8]]; st[12] = inv_s_box[st[12]];
+
+ tt = st[13]; st[13] = inv_s_box[st[9]]; st[ 9] = inv_s_box[st[5]];
+ st[ 5] = inv_s_box[st[1]]; st[ 1] = inv_s_box[ tt ];
+
+ tt = st[2]; st[ 2] = inv_s_box[st[10]]; st[10] = inv_s_box[ tt ];
+ tt = st[6]; st[ 6] = inv_s_box[st[14]]; st[14] = inv_s_box[ tt ];
+
+ tt = st[3]; st[ 3] = inv_s_box[st[ 7]]; st[ 7] = inv_s_box[st[11]];
+ st[11] = inv_s_box[st[15]]; st[15] = inv_s_box[ tt ];
+}
+
+#if defined( VERSION_1 )
+ static void mix_sub_columns( uint_8t dt[N_BLOCK] )
+ { uint_8t st[N_BLOCK];
+ block16_copy(st, dt);
+#else
+ static void mix_sub_columns( uint_8t dt[N_BLOCK], uint_8t st[N_BLOCK] )
+ {
+#endif
+ dt[ 0] = gfm2_s_box[st[0]] ^ gfm3_s_box[st[5]] ^ s_box[st[10]] ^ s_box[st[15]];
+ dt[ 1] = s_box[st[0]] ^ gfm2_s_box[st[5]] ^ gfm3_s_box[st[10]] ^ s_box[st[15]];
+ dt[ 2] = s_box[st[0]] ^ s_box[st[5]] ^ gfm2_s_box[st[10]] ^ gfm3_s_box[st[15]];
+ dt[ 3] = gfm3_s_box[st[0]] ^ s_box[st[5]] ^ s_box[st[10]] ^ gfm2_s_box[st[15]];
+
+ dt[ 4] = gfm2_s_box[st[4]] ^ gfm3_s_box[st[9]] ^ s_box[st[14]] ^ s_box[st[3]];
+ dt[ 5] = s_box[st[4]] ^ gfm2_s_box[st[9]] ^ gfm3_s_box[st[14]] ^ s_box[st[3]];
+ dt[ 6] = s_box[st[4]] ^ s_box[st[9]] ^ gfm2_s_box[st[14]] ^ gfm3_s_box[st[3]];
+ dt[ 7] = gfm3_s_box[st[4]] ^ s_box[st[9]] ^ s_box[st[14]] ^ gfm2_s_box[st[3]];
+
+ dt[ 8] = gfm2_s_box[st[8]] ^ gfm3_s_box[st[13]] ^ s_box[st[2]] ^ s_box[st[7]];
+ dt[ 9] = s_box[st[8]] ^ gfm2_s_box[st[13]] ^ gfm3_s_box[st[2]] ^ s_box[st[7]];
+ dt[10] = s_box[st[8]] ^ s_box[st[13]] ^ gfm2_s_box[st[2]] ^ gfm3_s_box[st[7]];
+ dt[11] = gfm3_s_box[st[8]] ^ s_box[st[13]] ^ s_box[st[2]] ^ gfm2_s_box[st[7]];
+
+ dt[12] = gfm2_s_box[st[12]] ^ gfm3_s_box[st[1]] ^ s_box[st[6]] ^ s_box[st[11]];
+ dt[13] = s_box[st[12]] ^ gfm2_s_box[st[1]] ^ gfm3_s_box[st[6]] ^ s_box[st[11]];
+ dt[14] = s_box[st[12]] ^ s_box[st[1]] ^ gfm2_s_box[st[6]] ^ gfm3_s_box[st[11]];
+ dt[15] = gfm3_s_box[st[12]] ^ s_box[st[1]] ^ s_box[st[6]] ^ gfm2_s_box[st[11]];
+ }
+
+#if defined( VERSION_1 )
+ static void inv_mix_sub_columns( uint_8t dt[N_BLOCK] )
+ { uint_8t st[N_BLOCK];
+ block16_copy(st, dt);
+#else
+ static void inv_mix_sub_columns( uint_8t dt[N_BLOCK], uint_8t st[N_BLOCK] )
+ {
+#endif
+ dt[ 0] = inv_s_box[gfmul_e[st[ 0]] ^ gfmul_b[st[ 1]] ^ gfmul_d[st[ 2]] ^ gfmul_9[st[ 3]]];
+ dt[ 5] = inv_s_box[gfmul_9[st[ 0]] ^ gfmul_e[st[ 1]] ^ gfmul_b[st[ 2]] ^ gfmul_d[st[ 3]]];
+ dt[10] = inv_s_box[gfmul_d[st[ 0]] ^ gfmul_9[st[ 1]] ^ gfmul_e[st[ 2]] ^ gfmul_b[st[ 3]]];
+ dt[15] = inv_s_box[gfmul_b[st[ 0]] ^ gfmul_d[st[ 1]] ^ gfmul_9[st[ 2]] ^ gfmul_e[st[ 3]]];
+
+ dt[ 4] = inv_s_box[gfmul_e[st[ 4]] ^ gfmul_b[st[ 5]] ^ gfmul_d[st[ 6]] ^ gfmul_9[st[ 7]]];
+ dt[ 9] = inv_s_box[gfmul_9[st[ 4]] ^ gfmul_e[st[ 5]] ^ gfmul_b[st[ 6]] ^ gfmul_d[st[ 7]]];
+ dt[14] = inv_s_box[gfmul_d[st[ 4]] ^ gfmul_9[st[ 5]] ^ gfmul_e[st[ 6]] ^ gfmul_b[st[ 7]]];
+ dt[ 3] = inv_s_box[gfmul_b[st[ 4]] ^ gfmul_d[st[ 5]] ^ gfmul_9[st[ 6]] ^ gfmul_e[st[ 7]]];
+
+ dt[ 8] = inv_s_box[gfmul_e[st[ 8]] ^ gfmul_b[st[ 9]] ^ gfmul_d[st[10]] ^ gfmul_9[st[11]]];
+ dt[13] = inv_s_box[gfmul_9[st[ 8]] ^ gfmul_e[st[ 9]] ^ gfmul_b[st[10]] ^ gfmul_d[st[11]]];
+ dt[ 2] = inv_s_box[gfmul_d[st[ 8]] ^ gfmul_9[st[ 9]] ^ gfmul_e[st[10]] ^ gfmul_b[st[11]]];
+ dt[ 7] = inv_s_box[gfmul_b[st[ 8]] ^ gfmul_d[st[ 9]] ^ gfmul_9[st[10]] ^ gfmul_e[st[11]]];
+
+ dt[12] = inv_s_box[gfmul_e[st[12]] ^ gfmul_b[st[13]] ^ gfmul_d[st[14]] ^ gfmul_9[st[15]]];
+ dt[ 1] = inv_s_box[gfmul_9[st[12]] ^ gfmul_e[st[13]] ^ gfmul_b[st[14]] ^ gfmul_d[st[15]]];
+ dt[ 6] = inv_s_box[gfmul_d[st[12]] ^ gfmul_9[st[13]] ^ gfmul_e[st[14]] ^ gfmul_b[st[15]]];
+ dt[11] = inv_s_box[gfmul_b[st[12]] ^ gfmul_d[st[13]] ^ gfmul_9[st[14]] ^ gfmul_e[st[15]]];
+ }
+
+#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED )
+
+/* Set the cipher key for the pre-keyed version */
+
+return_type aes_set_key( const unsigned char key[], length_type keylen, aes_context ctx[1] )
+{
+ uint_8t cc, rc, hi;
+
+ switch( keylen )
+ {
+ case 16:
+ case 128:
+ keylen = 16;
+ break;
+ case 24:
+ case 192:
+ keylen = 24;
+ break;
+ case 32:
+ case 256:
+ keylen = 32;
+ break;
+ default:
+ ctx->rnd = 0;
+ return -1;
+ }
+ block_copy(ctx->ksch, key, keylen);
+ hi = (keylen + 28) << 2;
+ ctx->rnd = (hi >> 4) - 1;
+ for( cc = keylen, rc = 1; cc < hi; cc += 4 )
+ { uint_8t tt, t0, t1, t2, t3;
+
+ t0 = ctx->ksch[cc - 4];
+ t1 = ctx->ksch[cc - 3];
+ t2 = ctx->ksch[cc - 2];
+ t3 = ctx->ksch[cc - 1];
+ if( cc % keylen == 0 )
+ {
+ tt = t0;
+ t0 = s_box[t1] ^ rc;
+ t1 = s_box[t2];
+ t2 = s_box[t3];
+ t3 = s_box[tt];
+ rc = f2(rc);
+ }
+ else if( keylen > 24 && cc % keylen == 16 )
+ {
+ t0 = s_box[t0];
+ t1 = s_box[t1];
+ t2 = s_box[t2];
+ t3 = s_box[t3];
+ }
+ tt = cc - keylen;
+ ctx->ksch[cc + 0] = ctx->ksch[tt + 0] ^ t0;
+ ctx->ksch[cc + 1] = ctx->ksch[tt + 1] ^ t1;
+ ctx->ksch[cc + 2] = ctx->ksch[tt + 2] ^ t2;
+ ctx->ksch[cc + 3] = ctx->ksch[tt + 3] ^ t3;
+ }
+ return 0;
+}
+
+#endif
+
+#if defined( AES_ENC_PREKEYED )
+
+/* Encrypt a single block of 16 bytes */
+
+return_type aes_encrypt( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], const aes_context ctx[1] )
+{
+ if( ctx->rnd )
+ {
+ uint_8t s1[N_BLOCK], r;
+ copy_and_key( s1, in, ctx->ksch );
+
+ for( r = 1 ; r < ctx->rnd ; ++r )
+#if defined( VERSION_1 )
+ {
+ mix_sub_columns( s1 );
+ add_round_key( s1, ctx->ksch + r * N_BLOCK);
+ }
+#else
+ { uint_8t s2[N_BLOCK];
+ mix_sub_columns( s2, s1 );
+ copy_and_key( s1, s2, ctx->ksch + r * N_BLOCK);
+ }
+#endif
+ shift_sub_rows( s1 );
+ copy_and_key( out, s1, ctx->ksch + r * N_BLOCK );
+ }
+ else
+ return -1;
+ return 0;
+}
+
+#endif
+
+#if defined( AES_DEC_PREKEYED )
+
+/* Decrypt a single block of 16 bytes */
+
+return_type aes_decrypt( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK], const aes_context ctx[1] )
+{
+ if( ctx->rnd )
+ {
+ uint_8t s1[N_BLOCK], r;
+ copy_and_key( s1, in, ctx->ksch + ctx->rnd * N_BLOCK );
+ inv_shift_sub_rows( s1 );
+
+ for( r = ctx->rnd ; --r ; )
+#if defined( VERSION_1 )
+ {
+ add_round_key( s1, ctx->ksch + r * N_BLOCK );
+ inv_mix_sub_columns( s1 );
+ }
+#else
+ { uint_8t s2[N_BLOCK];
+ copy_and_key( s2, s1, ctx->ksch + r * N_BLOCK );
+ inv_mix_sub_columns( s1, s2 );
+ }
+#endif
+ copy_and_key( out, s1, ctx->ksch );
+ }
+ else
+ return -1;
+ return 0;
+}
+
+#endif
+
+#if defined( AES_ENC_128_OTFK )
+
+/* The 'on the fly' encryption key update for for 128 bit keys */
+
+static void update_encrypt_key_128( uint_8t k[N_BLOCK], uint_8t *rc )
+{ uint_8t cc;
+
+ k[0] ^= s_box[k[13]] ^ *rc;
+ k[1] ^= s_box[k[14]];
+ k[2] ^= s_box[k[15]];
+ k[3] ^= s_box[k[12]];
+ *rc = f2( *rc );
+
+ for(cc = 4; cc < 16; cc += 4 )
+ {
+ k[cc + 0] ^= k[cc - 4];
+ k[cc + 1] ^= k[cc - 3];
+ k[cc + 2] ^= k[cc - 2];
+ k[cc + 3] ^= k[cc - 1];
+ }
+}
+
+/* Encrypt a single block of 16 bytes with 'on the fly' 128 bit keying */
+
+void aes_encrypt_128( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK],
+ const unsigned char key[N_BLOCK], unsigned char o_key[N_BLOCK] )
+{ uint_8t s1[N_BLOCK], r, rc = 1;
+
+ if(o_key != key)
+ block16_copy( o_key, key );
+ copy_and_key( s1, in, o_key );
+
+ for( r = 1 ; r < 10 ; ++r )
+#if defined( VERSION_1 )
+ {
+ mix_sub_columns( s1 );
+ update_encrypt_key_128( o_key, &rc );
+ add_round_key( s1, o_key );
+ }
+#else
+ { uint_8t s2[N_BLOCK];
+ mix_sub_columns( s2, s1 );
+ update_encrypt_key_128( o_key, &rc );
+ copy_and_key( s1, s2, o_key );
+ }
+#endif
+
+ shift_sub_rows( s1 );
+ update_encrypt_key_128( o_key, &rc );
+ copy_and_key( out, s1, o_key );
+}
+
+#endif
+
+#if defined( AES_DEC_128_OTFK )
+
+/* The 'on the fly' decryption key update for for 128 bit keys */
+
+static void update_decrypt_key_128( uint_8t k[N_BLOCK], uint_8t *rc )
+{ uint_8t cc;
+
+ for( cc = 12; cc > 0; cc -= 4 )
+ {
+ k[cc + 0] ^= k[cc - 4];
+ k[cc + 1] ^= k[cc - 3];
+ k[cc + 2] ^= k[cc - 2];
+ k[cc + 3] ^= k[cc - 1];
+ }
+ *rc = d2(*rc);
+ k[0] ^= s_box[k[13]] ^ *rc;
+ k[1] ^= s_box[k[14]];
+ k[2] ^= s_box[k[15]];
+ k[3] ^= s_box[k[12]];
+}
+
+/* Decrypt a single block of 16 bytes with 'on the fly' 128 bit keying */
+
+void aes_decrypt_128( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK],
+ const unsigned char key[N_BLOCK], unsigned char o_key[N_BLOCK] )
+{
+ uint_8t s1[N_BLOCK], r, rc = 0x6c;
+ if(o_key != key)
+ block16_copy( o_key, key );
+
+ copy_and_key( s1, in, o_key );
+ inv_shift_sub_rows( s1 );
+
+ for( r = 10 ; --r ; )
+#if defined( VERSION_1 )
+ {
+ update_decrypt_key_128( o_key, &rc );
+ add_round_key( s1, o_key );
+ inv_mix_sub_columns( s1 );
+ }
+#else
+ { uint_8t s2[N_BLOCK];
+ update_decrypt_key_128( o_key, &rc );
+ copy_and_key( s2, s1, o_key );
+ inv_mix_sub_columns( s1, s2 );
+ }
+#endif
+ update_decrypt_key_128( o_key, &rc );
+ copy_and_key( out, s1, o_key );
+}
+
+#endif
+
+#if defined( AES_ENC_256_OTFK )
+
+/* The 'on the fly' encryption key update for for 256 bit keys */
+
+static void update_encrypt_key_256( uint_8t k[2 * N_BLOCK], uint_8t *rc )
+{ uint_8t cc;
+
+ k[0] ^= s_box[k[29]] ^ *rc;
+ k[1] ^= s_box[k[30]];
+ k[2] ^= s_box[k[31]];
+ k[3] ^= s_box[k[28]];
+ *rc = f2( *rc );
+
+ for(cc = 4; cc < 16; cc += 4)
+ {
+ k[cc + 0] ^= k[cc - 4];
+ k[cc + 1] ^= k[cc - 3];
+ k[cc + 2] ^= k[cc - 2];
+ k[cc + 3] ^= k[cc - 1];
+ }
+
+ k[16] ^= s_box[k[12]];
+ k[17] ^= s_box[k[13]];
+ k[18] ^= s_box[k[14]];
+ k[19] ^= s_box[k[15]];
+
+ for( cc = 20; cc < 32; cc += 4 )
+ {
+ k[cc + 0] ^= k[cc - 4];
+ k[cc + 1] ^= k[cc - 3];
+ k[cc + 2] ^= k[cc - 2];
+ k[cc + 3] ^= k[cc - 1];
+ }
+}
+
+/* Encrypt a single block of 16 bytes with 'on the fly' 256 bit keying */
+
+void aes_encrypt_256( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK],
+ const unsigned char key[2 * N_BLOCK], unsigned char o_key[2 * N_BLOCK] )
+{
+ uint_8t s1[N_BLOCK], r, rc = 1;
+ if(o_key != key)
+ {
+ block16_copy( o_key, key );
+ block16_copy( o_key + 16, key + 16 );
+ }
+ copy_and_key( s1, in, o_key );
+
+ for( r = 1 ; r < 14 ; ++r )
+#if defined( VERSION_1 )
+ {
+ mix_sub_columns(s1);
+ if( r & 1 )
+ add_round_key( s1, o_key + 16 );
+ else
+ {
+ update_encrypt_key_256( o_key, &rc );
+ add_round_key( s1, o_key );
+ }
+ }
+#else
+ { uint_8t s2[N_BLOCK];
+ mix_sub_columns( s2, s1 );
+ if( r & 1 )
+ copy_and_key( s1, s2, o_key + 16 );
+ else
+ {
+ update_encrypt_key_256( o_key, &rc );
+ copy_and_key( s1, s2, o_key );
+ }
+ }
+#endif
+
+ shift_sub_rows( s1 );
+ update_encrypt_key_256( o_key, &rc );
+ copy_and_key( out, s1, o_key );
+}
+
+#endif
+
+#if defined( AES_DEC_256_OTFK )
+
+/* The 'on the fly' encryption key update for for 256 bit keys */
+
+static void update_decrypt_key_256( uint_8t k[2 * N_BLOCK], uint_8t *rc )
+{ uint_8t cc;
+
+ for(cc = 28; cc > 16; cc -= 4)
+ {
+ k[cc + 0] ^= k[cc - 4];
+ k[cc + 1] ^= k[cc - 3];
+ k[cc + 2] ^= k[cc - 2];
+ k[cc + 3] ^= k[cc - 1];
+ }
+
+ k[16] ^= s_box[k[12]];
+ k[17] ^= s_box[k[13]];
+ k[18] ^= s_box[k[14]];
+ k[19] ^= s_box[k[15]];
+
+ for(cc = 12; cc > 0; cc -= 4)
+ {
+ k[cc + 0] ^= k[cc - 4];
+ k[cc + 1] ^= k[cc - 3];
+ k[cc + 2] ^= k[cc - 2];
+ k[cc + 3] ^= k[cc - 1];
+ }
+
+ *rc = d2(*rc);
+ k[0] ^= s_box[k[29]] ^ *rc;
+ k[1] ^= s_box[k[30]];
+ k[2] ^= s_box[k[31]];
+ k[3] ^= s_box[k[28]];
+}
+
+/* Decrypt a single block of 16 bytes with 'on the fly'
+ 256 bit keying
+*/
+void aes_decrypt_256( const unsigned char in[N_BLOCK], unsigned char out[N_BLOCK],
+ const unsigned char key[2 * N_BLOCK], unsigned char o_key[2 * N_BLOCK] )
+{
+ uint_8t s1[N_BLOCK], r, rc = 0x80;
+
+ if(o_key != key)
+ {
+ block16_copy( o_key, key );
+ block16_copy( o_key + 16, key + 16 );
+ }
+
+ copy_and_key( s1, in, o_key );
+ inv_shift_sub_rows( s1 );
+
+ for( r = 14 ; --r ; )
+#if defined( VERSION_1 )
+ {
+ if( ( r & 1 ) )
+ {
+ update_decrypt_key_256( o_key, &rc );
+ add_round_key( s1, o_key + 16 );
+ }
+ else
+ add_round_key( s1, o_key );
+ inv_mix_sub_columns( s1 );
+ }
+#else
+ { uint_8t s2[N_BLOCK];
+ if( ( r & 1 ) )
+ {
+ update_decrypt_key_256( o_key, &rc );
+ copy_and_key( s2, s1, o_key + 16 );
+ }
+ else
+ copy_and_key( s2, s1, o_key );
+ inv_mix_sub_columns( s1, s2 );
+ }
+#endif
+ copy_and_key( out, s1, o_key );
+}
+
+#endif
Modified: branches/mtrender/src/aes.h
===================================================================
--- branches/mtrender/src/aes.h 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/aes.h 2008-05-04 17:50:39 UTC (rev 8698)
@@ -1,160 +1,161 @@
-/*
- ---------------------------------------------------------------------------
- Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.
-
- LICENSE TERMS
-
- The free distribution and use of this software in both source and binary
- form is allowed (with or without changes) provided that:
-
- 1. distributions of this source code include the above copyright
- notice, this list of conditions and the following disclaimer;
-
- 2. distributions in binary form include the above copyright
- notice, this list of conditions and the following disclaimer
- in the documentation and/or other associated materials;
-
- 3. the copyright holder's name is not used to endorse products
- built using this software without specific written permission.
-
- ALTERNATIVELY, provided that this notice is retained in full, this product
- may be distributed under the terms of the GNU General Public License (GPL),
- in which case the provisions of the GPL apply INSTEAD OF those given above.
-
- DISCLAIMER
-
- This software is provided 'as is' with no explicit or implied warranties
- in respect of its properties, including, but not limited to, correctness
- and/or fitness for purpose.
- ---------------------------------------------------------------------------
- Issue 09/09/2006
-
- This is an AES implementation that uses only 8-bit byte operations on the
- cipher state.
- */
-
-#ifndef AES_H
-#define AES_H
-
-/* This provides speed optimisation opportunities if 32-bit word
- operations are available
-*/
-#if 0
-# define HAVE_UINT_32T
-#endif
-
-#if 1
-# define AES_ENC_PREKEYED /* AES encryption with a precomputed key schedule */
-#endif
-#if 1
-# define AES_DEC_PREKEYED /* AES decryption with a precomputed key schedule */
-#endif
-#if 1
-# define AES_ENC_128_OTFK /* AES encryption with 'on the fly' 128 bit keying */
-#endif
-#if 1
-# define AES_DEC_128_OTFK /* AES decryption with 'on the fly' 128 bit keying */
-#endif
-#if 1
-# define AES_ENC_256_OTFK /* AES encryption with 'on the fly' 256 bit keying */
-#endif
-#if 1
-# define AES_DEC_256_OTFK /* AES decryption with 'on the fly' 256 bit keying */
-#endif
-
-#define N_ROW 4
-#define N_COL 4
-#define N_BLOCK (N_ROW * N_COL)
-#define N_MAX_ROUNDS 14
-
-typedef unsigned char uint_8t;
-
-typedef uint_8t return_type;
-typedef uint_8t length_type;
-typedef uint_8t uint_type;
-
-typedef unsigned char uint_8t;
-
-typedef struct
-{ uint_8t ksch[(N_MAX_ROUNDS + 1) * N_BLOCK];
- uint_8t rnd;
-} aes_context;
-
-/* The following calls are for a precomputed key schedule
-
- NOTE: If the length_type used for the key length is an
- unsigned 8-bit character, a key length of 256 bits must
- be entered as a length in bytes (valid inputs are hence
- 128, 192, 16, 24 and 32).
-*/
-
-#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED )
-
-return_type aes_set_key( const unsigned char key[],
- length_type keylen,
- aes_context ctx[1] );
-#endif
-
-#if defined( AES_ENC_PREKEYED )
-
-return_type aes_encrypt( const unsigned char in[N_BLOCK],
- unsigned char out[N_BLOCK],
- const aes_context ctx[1] );
-#endif
-
-#if defined( AES_DEC_PREKEYED )
-
-return_type aes_decrypt( const unsigned char in[N_BLOCK],
- unsigned char out[N_BLOCK],
- const aes_context ctx[1] );
-#endif
-
-/* The following calls are for 'on the fly' keying. In this case the
- encryption and decryption keys are different.
-
- The encryption subroutines take a key in an array of bytes in
- key[L] where L is 16, 24 or 32 bytes for key lengths of 128,
- 192, and 256 bits respectively. They then encrypts the input
- data, in[] with this key and put the reult in the output array
- out[]. In addition, the second key array, o_key[L], is used
- to output the key that is needed by the decryption subroutine
- to reverse the encryption operation. The two key arrays can
- be the same array but in this case the original key will be
- overwritten.
-
- In the same way, the decryption subroutines output keys that
- can be used to reverse their effect when used for encryption.
-
- Only 128 and 256 bit keys are supported in these 'on the fly'
- modes.
-*/
-
-#if defined( AES_ENC_128_OTFK )
-void aes_encrypt_128( const unsigned char in[N_BLOCK],
- unsigned char out[N_BLOCK],
- const unsigned char key[N_BLOCK],
- uint_8t o_key[N_BLOCK] );
-#endif
-
-#if defined( AES_DEC_128_OTFK )
-void aes_decrypt_128( const unsigned char in[N_BLOCK],
- unsigned char out[N_BLOCK],
- const unsigned char key[N_BLOCK],
- unsigned char o_key[N_BLOCK] );
-#endif
-
-#if defined( AES_ENC_256_OTFK )
-void aes_encrypt_256( const unsigned char in[N_BLOCK],
- unsigned char out[N_BLOCK],
- const unsigned char key[2 * N_BLOCK],
- unsigned char o_key[2 * N_BLOCK] );
-#endif
-
-#if defined( AES_DEC_256_OTFK )
-void aes_decrypt_256( const unsigned char in[N_BLOCK],
- unsigned char out[N_BLOCK],
- const unsigned char key[2 * N_BLOCK],
- unsigned char o_key[2 * N_BLOCK] );
-#endif
-
-#endif
+/*
+ ---------------------------------------------------------------------------
+ Copyright (c) 1998-2006, Brian Gladman, Worcester, UK. All rights reserved.
+
+ LICENSE TERMS
+
+ The free distribution and use of this software in both source and binary
+ form is allowed (with or without changes) provided that:
+
+ 1. distributions of this source code include the above copyright
+ notice, this list of conditions and the following disclaimer;
+
+ 2. distributions in binary form include the above copyright
+ notice, this list of conditions and the following disclaimer
+ in the documentation and/or other associated materials;
+
+ 3. the copyright holder's name is not used to endorse products
+ built using this software without specific written permission.
+
+ ALTERNATIVELY, provided that this notice is retained in full, this product
+ may be distributed under the terms of the GNU General Public License (GPL),
+ in which case the provisions of the GPL apply INSTEAD OF those given above.
+
+ DISCLAIMER
+
+ This software is provided 'as is' with no explicit or implied warranties
+ in respect of its properties, including, but not limited to, correctness
+ and/or fitness for purpose.
+ ---------------------------------------------------------------------------
+ Issue 09/09/2006
+
+ This is an AES implementation that uses only 8-bit byte operations on the
+ cipher state.
+ */
+/* $Id: aes.h 8686 2008-05-02 01:42:14Z giles $ */
+
+#ifndef AES_H
+#define AES_H
+
+/* This provides speed optimisation opportunities if 32-bit word
+ operations are available
+*/
+#if 0
+# define HAVE_UINT_32T
+#endif
+
+#if 1
+# define AES_ENC_PREKEYED /* AES encryption with a precomputed key schedule */
+#endif
+#if 1
+# define AES_DEC_PREKEYED /* AES decryption with a precomputed key schedule */
+#endif
+#if 1
+# define AES_ENC_128_OTFK /* AES encryption with 'on the fly' 128 bit keying */
+#endif
+#if 1
+# define AES_DEC_128_OTFK /* AES decryption with 'on the fly' 128 bit keying */
+#endif
+#if 1
+# define AES_ENC_256_OTFK /* AES encryption with 'on the fly' 256 bit keying */
+#endif
+#if 1
+# define AES_DEC_256_OTFK /* AES decryption with 'on the fly' 256 bit keying */
+#endif
+
+#define N_ROW 4
+#define N_COL 4
+#define N_BLOCK (N_ROW * N_COL)
+#define N_MAX_ROUNDS 14
+
+typedef unsigned char uint_8t;
+
+typedef uint_8t return_type;
+typedef uint_8t length_type;
+typedef uint_8t uint_type;
+
+typedef unsigned char uint_8t;
+
+typedef struct
+{ uint_8t ksch[(N_MAX_ROUNDS + 1) * N_BLOCK];
+ uint_8t rnd;
+} aes_context;
+
+/* The following calls are for a precomputed key schedule
+
+ NOTE: If the length_type used for the key length is an
+ unsigned 8-bit character, a key length of 256 bits must
+ be entered as a length in bytes (valid inputs are hence
+ 128, 192, 16, 24 and 32).
+*/
+
+#if defined( AES_ENC_PREKEYED ) || defined( AES_DEC_PREKEYED )
+
+return_type aes_set_key( const unsigned char key[],
+ length_type keylen,
+ aes_context ctx[1] );
+#endif
+
+#if defined( AES_ENC_PREKEYED )
+
+return_type aes_encrypt( const unsigned char in[N_BLOCK],
+ unsigned char out[N_BLOCK],
+ const aes_context ctx[1] );
+#endif
+
+#if defined( AES_DEC_PREKEYED )
+
+return_type aes_decrypt( const unsigned char in[N_BLOCK],
+ unsigned char out[N_BLOCK],
+ const aes_context ctx[1] );
+#endif
+
+/* The following calls are for 'on the fly' keying. In this case the
+ encryption and decryption keys are different.
+
+ The encryption subroutines take a key in an array of bytes in
+ key[L] where L is 16, 24 or 32 bytes for key lengths of 128,
+ 192, and 256 bits respectively. They then encrypts the input
+ data, in[] with this key and put the reult in the output array
+ out[]. In addition, the second key array, o_key[L], is used
+ to output the key that is needed by the decryption subroutine
+ to reverse the encryption operation. The two key arrays can
+ be the same array but in this case the original key will be
+ overwritten.
+
+ In the same way, the decryption subroutines output keys that
+ can be used to reverse their effect when used for encryption.
+
+ Only 128 and 256 bit keys are supported in these 'on the fly'
+ modes.
+*/
+
+#if defined( AES_ENC_128_OTFK )
+void aes_encrypt_128( const unsigned char in[N_BLOCK],
+ unsigned char out[N_BLOCK],
+ const unsigned char key[N_BLOCK],
+ uint_8t o_key[N_BLOCK] );
+#endif
+
+#if defined( AES_DEC_128_OTFK )
+void aes_decrypt_128( const unsigned char in[N_BLOCK],
+ unsigned char out[N_BLOCK],
+ const unsigned char key[N_BLOCK],
+ unsigned char o_key[N_BLOCK] );
+#endif
+
+#if defined( AES_ENC_256_OTFK )
+void aes_encrypt_256( const unsigned char in[N_BLOCK],
+ unsigned char out[N_BLOCK],
+ const unsigned char key[2 * N_BLOCK],
+ unsigned char o_key[2 * N_BLOCK] );
+#endif
+
+#if defined( AES_DEC_256_OTFK )
+void aes_decrypt_256( const unsigned char in[N_BLOCK],
+ unsigned char out[N_BLOCK],
+ const unsigned char key[2 * N_BLOCK],
+ unsigned char o_key[2 * N_BLOCK] );
+#endif
+
+#endif
Modified: branches/mtrender/src/configure.ac
===================================================================
--- branches/mtrender/src/configure.ac 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/configure.ac 2008-05-04 17:50:39 UTC (rev 8698)
@@ -247,16 +247,8 @@
dnl --------------------------------------------------
AC_CHECK_LIB(m, cos)
+dnl AC_CHECK_LIB(pthread, pthread_create)
-SYNC="nosync"
-PTHREAD_LIBS=""
-AC_CHECK_LIB(pthread, pthread_create, [
- SYNC=posync;
- PTHREAD_LIBS="-lpthread"
-])
-AC_SUBST(SYNC)
-AC_SUBST(PTHREAD_LIBS)
-
dnl Tests for iconv (Needed for OpenPrinting Vector, "opvp" output device)
AC_ARG_WITH(libiconv,
[AC_HELP_STRING([--with-libiconv=@<:@no/gnu/native@:>@],
@@ -708,6 +700,7 @@
PS = Output to PostScript/PDF
TIFF = Output to TIFF
WTS = WTS Halftoning devices
+ ETS = ETS Halftoning devices
You can mix both variants, e.g.
--with-drivers=HP,stcolor would build HP drivers and
the Epson stcolor driver.
@@ -741,6 +734,7 @@
JAPAN_DEVS="lips4 lips4v ljet4pjl lj4dithp dj505j picty180 lips2p bjc880j pr201 pr150 pr1000 pr1000_4 jj100 bj10v bj10vh mj700v2c mj500c mj6000c mj8000c fmpr fmlbp ml600 lbp310 lbp320 md50Mono md50Eco md1xMono escpage lp2000 npdl rpdl"
MISC_PDEVS="uniprint ap3250 atx23 atx24 atx38 coslw2p coslwxl cp50 declj250 fs600 imagen lj250 m8510 necp6 oce9050 r4081 sj48 tek4696 t4693d2 t4693d4 t4693d8 dl2100 la50 la70 la75 la75plus ln03 xes md2k md5k gdi samsunggdi"
OPVP_DEVS="opvp oprp"
+ETS_HALFTONING_DEVS="rinkj"
dnl Known file formats
BMP_DEVS="bmpmono bmpgray bmpsep1 bmpsep8 bmp16 bmp256 bmp16m bmp32b"
@@ -772,7 +766,7 @@
fi
;;
PRINTERS)
- P_DEVS="$P_DEVS $CANON_DEVS $EPSON_DEVS $HP_DEVS $LEXMARK_DEVS $BROTHER_DEVS $APPLE_DEVS $IBM_DEVS $OKI_DEVS $JAPAN_DEVS $MISC_PDEVS $OPVP_DEVS"
+ P_DEVS="$P_DEVS $CANON_DEVS $EPSON_DEVS $HP_DEVS $LEXMARK_DEVS $BROTHER_DEVS $APPLE_DEVS $IBM_DEVS $OKI_DEVS $JAPAN_DEVS $MISC_PDEVS $ETS_HALFTONING_DEVS $OPVP_DEVS"
;;
FILES)
F_DEVS="$F_DEVS $BMP_DEVS $FAX_DEVS $JPEG_DEVS $PNG_DEVS $TIFF_DEVS $PCX_DEVS $PBM_DEVS $PS_DEVS $WTS_HALFTONING_DEVS $MISC_FDEVS"
@@ -853,6 +847,10 @@
# WTS Halftoning devices
F_DEVS="$F_DEVS $WTS_HALFTONING_DEVS"
;;
+ ETS)
+ # ETS Halftoning devices
+ F_DEVS="$F_DEVS $ETS_HALFTONING_DEVS"
+ ;;
opvp)
# Open Vector Printing driver...
if test x$ac_cv_lib_dl_dlopen != xno -a x$found_iconv != xno; then
Modified: branches/mtrender/src/echogs.c
===================================================================
--- branches/mtrender/src/echogs.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/echogs.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -91,14 +91,14 @@
FILE *in = 0;
const char *extn = "";
char fmode[4];
-#define FNSIZE 100
+#define FNSIZE 1000
char *fnparam;
char fname[FNSIZE];
int newline = 1;
int interact = 0;
int (*eputc)(int, FILE *) = fputc;
int (*eputs)(const char *, FILE *) = fputs;
-#define LINESIZE 1000
+#define LINESIZE 1000+FNSIZE
char line[LINESIZE];
char sw = 0, sp = 0, hexx = 0;
char **argp = argv + 1;
Modified: branches/mtrender/src/gdevddrw.c
===================================================================
--- branches/mtrender/src/gdevddrw.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevddrw.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -126,7 +126,7 @@
if ((tl->df = xd + h) >= 0 /* xd >= -h */)
tl->di = -1, tl->x -= ys;
else {
- tl->di = di = (int)-((h - 1 - xd) / h);
+ tl->di = di = (int)((xd + 1) / h - 1);
tl->df = xd - di * h;
tl->x += ys * di;
}
Modified: branches/mtrender/src/gdevdjet.c
===================================================================
--- branches/mtrender/src/gdevdjet.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevdjet.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -579,7 +579,7 @@
if (code>=0)
{
code=param_read_bool(plist,"Tumble",&Tumble);
- if (code != 0) Tumble = false; // default: no tumble
+ if (code != 0) Tumble = false; /* default: no tumble */
}
if (code >= 0)
Modified: branches/mtrender/src/gdevfax.c
===================================================================
--- branches/mtrender/src/gdevfax.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevfax.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -197,7 +197,11 @@
uint left = r.limit - r.ptr;
memcpy(in, r.ptr + 1, left);
- gdev_prn_copy_scan_lines(pdev, lnum++, in + left, in_size);
+ code = gdev_prn_copy_scan_lines(pdev, lnum++, in + left, in_size);
+ if (code < 0) {
+ gs_note_error(code);
+ goto done;
+ }
/* Note: we use col_size here, not in_size. */
if (col_size > in_size) {
memset(in + left + in_size, 0, col_size - in_size);
Modified: branches/mtrender/src/gdevp14.c
===================================================================
--- branches/mtrender/src/gdevp14.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevp14.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -56,11 +56,11 @@
* usually simple. For other devices or if the user is doing custom color
* processing then the user may want to control this choice.
*/
-#define AUTO_CUSTOM_BLENDING 0
+#define AUTO_USE_CUSTOM_BLENDING 0
#define ALWAYS_USE_CUSTOM_BLENDING 1
#define DO_NOT_USE_CUSTOM_BLENDING 2
-#define CUSTOM_BLENDING_MODE AUTO_CUSTOM_BLENDING
+#define CUSTOM_BLENDING_MODE AUTO_USE_CUSTOM_BLENDING
/* #define DUMP_TO_PNG */
@@ -1877,7 +1877,6 @@
pdf14_disable_device(gx_device * dev)
{
gx_device_forward * pdev = (gx_device_forward *)dev;
- pdf14_device *cdev = (pdf14_device *)dev;
if_debug0('v', "[v]pdf14_disable_device\n");
dev->color_info = pdev->target->color_info;
Modified: branches/mtrender/src/gdevpdfb.c
===================================================================
--- branches/mtrender/src/gdevpdfb.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevpdfb.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -569,7 +569,10 @@
sprintf(buf, "/R%ld Do\n", image_id);
pprintd1(s, "%d>>stream\n", strlen(buf));
- pprints1(s, "%sendstream\n", buf);
+ if (pdev->PDFA)
+ pprints1(s, "%s\nendstream\n", buf);
+ else
+ pprints1(s, "%sendstream\n", buf);
pdf_end_resource(pdev);
} else {
length_id = pdf_obj_ref(pdev);
Modified: branches/mtrender/src/gdevpdfo.c
===================================================================
--- branches/mtrender/src/gdevpdfo.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevpdfo.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -524,6 +524,8 @@
}
DISCARD(cos_array_reorder(pca, first));
stream_puts(s, "]");
+ if (pdev->PDFA)
+ stream_puts(s, "\n");
return 0;
}
@@ -790,6 +792,8 @@
stream_puts(s, "<<");
cos_elements_write(s, ((const cos_dict_t *)pco)->elements, pdev, false, object_id);
stream_puts(s, ">>");
+ if (pdev->PDFA)
+ stream_puts(s, "\n");
return 0;
}
Modified: branches/mtrender/src/gdevpdfu.c
===================================================================
--- branches/mtrender/src/gdevpdfu.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevpdfu.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -689,6 +689,8 @@
pdf_end_encrypt(pdev);
s = pdev->strm;
length = pdf_stell(pdev) - pdev->contents_pos;
+ if (pdev->PDFA)
+ stream_puts(s, "\n");
stream_puts(s, "endstream\n");
pdf_end_obj(pdev);
pdf_open_obj(pdev, pdev->contents_length_id);
Modified: branches/mtrender/src/gdevpdtb.c
===================================================================
--- branches/mtrender/src/gdevpdtb.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevpdtb.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -43,6 +43,8 @@
/* ---------------- Private ---------------- */
private_st_pdf_base_font();
+gs_private_st_basic(st_pdf_base_font, pdf_base_font_t, "pdf_base_font_t",\
+ pdf_base_font_ptrs, pdf_base_font_data);
#define SUBSET_PREFIX_SIZE 7 /* XXXXXX+ */
@@ -557,6 +559,7 @@
#define TRUETYPE_OPTIONS (WRITE_TRUETYPE_NAME | WRITE_TRUETYPE_HVMTX)
/* Acrobat Reader 3 doesn't handle cmap format 6 correctly. */
const int options = TRUETYPE_OPTIONS |
+ (pdev->PDFA ? WRITE_TRUETYPE_UNICODE_CMAP : 0) |
(pdev->CompatibilityLevel <= 1.2 ?
WRITE_TRUETYPE_NO_TRIMMED_TABLE : 0) |
/* Generate a cmap only for incrementally downloaded fonts
Modified: branches/mtrender/src/gdevpdtf.h
===================================================================
--- branches/mtrender/src/gdevpdtf.h 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevpdtf.h 2008-05-04 17:50:39 UTC (rev 8698)
@@ -185,8 +185,6 @@
GC_OBJ_ELT(pdf_base_font_t, FontFile),\
GC_STRING_ELT(pdf_base_font_t, font_name)\
};\
-gs_private_st_basic(st_pdf_base_font, pdf_base_font_t, "pdf_base_font_t",\
- pdf_base_font_ptrs, pdf_base_font_data);
typedef struct {
Modified: branches/mtrender/src/gdevpdti.c
===================================================================
--- branches/mtrender/src/gdevpdti.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevpdti.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -347,6 +347,8 @@
sseek(s, start_pos - 15);
pprintd1(s, "%d", length);
sseek(s, end_pos);
+ if (pdev->PDFA)
+ stream_puts(s, "\n");
stream_puts(s, "endstream\n");
pdf_end_separate(pdev);
return 0;
Modified: branches/mtrender/src/gdevpdtv.c
===================================================================
--- branches/mtrender/src/gdevpdtv.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevpdtv.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -10,9 +10,21 @@
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
*/
-
/* $Id$ */
+/*
+ * This file contains substantial parts of toolbin/encs2c.ps,
+ * which generated the remainder of the file mechanically from
+ * gs_std_e.ps gs_il1_e.ps gs_sym_e.ps gs_dbt_e.ps
+ * gs_wan_e.ps gs_mro_e.ps gs_mex_e.ps gs_mgl_e.ps
+ * gs_lgo_e.ps gs_lgx_e.ps gs_css_e.ps
+ *
+ * This source file is maintained manually under source code control,
+ * however its content should be regenerated by using encs2c.ps
+ * if changes are required.
+ */
+#include "gdevpdtv.h"
+
/*
* Glyph attributes for every glyph <= GS_C_PDF_MAX_GOOD_GLYPH
* packed 4 per byte least significant bits first.
Modified: branches/mtrender/src/gdevpdtv.h
===================================================================
--- branches/mtrender/src/gdevpdtv.h 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevpdtv.h 2008-05-04 17:50:39 UTC (rev 8698)
@@ -10,8 +10,18 @@
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
*/
-
/* $Id$ */
+/*
+ * This file contains substantial parts of toolbin/encs2c.ps,
+ * which generated the remainder of the file mechanically from
+ * gs_std_e.ps gs_il1_e.ps gs_sym_e.ps gs_dbt_e.ps
+ * gs_wan_e.ps gs_mro_e.ps gs_mex_e.ps gs_mgl_e.ps
+ * gs_lgo_e.ps gs_lgx_e.ps gs_css_e.ps
+ *
+ * This source file is maintained manually under source code control,
+ * however its content should be regenerated by using encs2c.ps
+ * if changes are required.
+ */
#ifndef gdevpdtv_INCLUDED
#define gdevpdtv_INCLUDED
Modified: branches/mtrender/src/gdevps.c
===================================================================
--- branches/mtrender/src/gdevps.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevps.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -1622,7 +1622,7 @@
return_error(gs_error_rangecheck);
psw_put_bits(pdev->image_stream,
planes[pi].data,
- planes[pi].data_x*info->plane_depths[pi] + pie->bits_per_row*j,
+ planes[pi].data_x*info->plane_depths[pi] + planes[pi].raster*j*8,
planes[pi].raster,
pie->bits_per_row,
1 );
Modified: branches/mtrender/src/gdevpsf.h
===================================================================
--- branches/mtrender/src/gdevpsf.h 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevpsf.h 2008-05-04 17:50:39 UTC (rev 8698)
@@ -241,6 +241,10 @@
#define WRITE_TRUETYPE_POST 4 /* generate post if missing */
#define WRITE_TRUETYPE_NO_TRIMMED_TABLE 8 /* not OK to use cmap format 6 */
#define WRITE_TRUETYPE_HVMTX 16 /* generate [hv]mtx from glyph_info */
+#define WRITE_TRUETYPE_UNICODE_CMAP 32 /* For PDF/A or other non-symbolic TT font,
+ * write a 3,1 (Windows Unicode) cmap instead of
+ * a 3,0 one.
+ */
int psf_write_truetype_font(stream *s, gs_font_type42 *pfont, int options,
gs_glyph *subset_glyphs, uint subset_size,
const gs_const_string *alt_font_name);
Modified: branches/mtrender/src/gdevpsft.c
===================================================================
--- branches/mtrender/src/gdevpsft.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevpsft.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -238,6 +238,27 @@
0, 0, /* first character code */
0, 0 /* # of entries *VARIABLE* */
};
+static const byte cmap_unicode_initial_6[] = {
+ 0, 0, /* table version # = 0 */
+ 0, 2, /* # of encoding tables = 2 */
+
+ /* First table, Macintosh */
+ 0, 1, /* platform ID = Macintosh */
+ 0, 0, /* platform encoding ID = ??? */
+ 0, 0, 0, 4+8+8, /* offset to table start */
+ /* Second table, Windows */
+ 0, 3, /* platform ID = Microsoft */
+ 0, 1, /* platform encoding ID = Unicode */
+ 0, 0, 0, 4+8+8+10, /* offset to table start */
+ /* *VARIABLE*, add 2 x # of entries */
+
+ /* Start of Macintosh format 6 table */
+ 0, 6, /* format = 6, trimmed table mapping */
+ 0, 10, /* length *VARIABLE*, add 2 x # of entries */
+ 0, 0, /* version number */
+ 0, 0, /* first character code */
+ 0, 0 /* # of entries *VARIABLE* */
+};
static const byte cmap_initial_4[] = {
0, 0, /* table version # = 0 */
0, 1, /* # of encoding tables = 2 */
@@ -301,6 +322,21 @@
stream_write(s, cmap_data, sizeof(cmap_data));
stream_write(s, entries + first_entry * 2, num_entries * 2);
}
+static void write_unicode_cmap_6(stream *s, byte *entries, uint first_code,
+ uint first_entry, uint num_entries)
+{
+ byte cmap_data[sizeof(cmap_unicode_initial_6)];
+
+ memcpy(cmap_data, cmap_unicode_initial_6, sizeof(cmap_unicode_initial_6));
+ put_u16(cmap_data + 18,
+ U16(cmap_data + 18) + num_entries * 2); /* offset */
+ put_u16(cmap_data + 22,
+ U16(cmap_data + 22) + num_entries * 2); /* length */
+ put_u16(cmap_data + 26, first_entry);
+ put_u16(cmap_data + 28, num_entries);
+ stream_write(s, cmap_data, sizeof(cmap_data));
+ stream_write(s, entries + first_entry * 2, num_entries * 2);
+}
static void
write_cmap(stream *s, gs_font *font, uint first_code, int num_glyphs,
gs_glyph max_glyph, int options, uint cmap_length)
@@ -336,6 +372,19 @@
/* Write the table header and Macintosh sub-table (if any). */
+ if (options & WRITE_TRUETYPE_UNICODE_CMAP) {
+ write_unicode_cmap_6(s, entries, first_code, first_entry, num_entries);
+
+ /* Write the Windows sub-table. */
+ memcpy(cmap_sub, cmap_sub_initial, sizeof(cmap_sub_initial));
+ put_u16(cmap_sub + 2, U16(cmap_sub + 2) + num_entries * 2); /* length */
+ put_u16(cmap_sub + 14, end_entry - 1); /* endCount[0] */
+ put_u16(cmap_sub + 20, first_entry); /* startCount[0] */
+ stream_write(s, cmap_sub, sizeof(cmap_sub));
+ stream_write(s, entries + first_entry * 2, num_entries * 2);
+ put_pad(s, cmap_length);
+ return;
+ }
#if TT_FORCE_CMAP_6 > 0
/* Always use format 6. */
write_cmap_6(s, entries, first_code, first_entry, num_entries);
Modified: branches/mtrender/src/gdevrinkj.c
===================================================================
--- branches/mtrender/src/gdevrinkj.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevrinkj.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2006 Artifex Software, Inc.
+/* Copyright (C) 2001-2008 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -214,6 +214,7 @@
/* DeviceN device specific parameters */
RINKJ_DEVICE_CMYK, /* Color model */
8, /* Bits per color - must match ncomp, depth, etc. above */
+ 4, /* Number of output color planes, overwritten below. */
(&DeviceCMYKComponents), /* Names of color model colorants */
4, /* Number colorants for CMYK */
{0}, /* SeparationNames */
@@ -757,7 +758,8 @@
* number if the name is found. It returns a negative value if not found.
*/
static int
-rinkj_get_color_comp_index(const gx_device * dev, const char * pname, int name_size, int src_index)
+rinkj_get_color_comp_index(gx_device * dev, const char * pname, int name_size,
+ int src_index)
{
/* TO_DO_DEVICEN This routine needs to include the effects of the SeparationOrder array */
const fixed_colorant_names_list * list = ((const rinkj_device *)dev)->std_colorant_names;
Modified: branches/mtrender/src/gdevvec.c
===================================================================
--- branches/mtrender/src/gdevvec.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gdevvec.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -1055,8 +1055,8 @@
{
int code;
- if ((code = gdev_vector_prepare_fill(vdev, pis, params, pdevc)) < 0 ||
- (code = gdev_vector_update_clip_path(vdev, pcpath)) < 0 ||
+ if ((code = gdev_vector_update_clip_path(vdev, pcpath)) < 0 ||
+ (code = gdev_vector_prepare_fill(vdev, pis, params, pdevc)) < 0 ||
(vdev->bbox_device &&
(code = (*dev_proc(vdev->bbox_device, fill_path))
((gx_device *) vdev->bbox_device, pis, ppath, params,
@@ -1082,9 +1082,9 @@
int set_ctm;
gs_matrix mat;
- if ((set_ctm = gdev_vector_stroke_scaling(vdev, pis, &scale, &mat)) != 0 ||
+ if ((code = gdev_vector_update_clip_path(vdev, pcpath)) < 0 ||
+ (set_ctm = gdev_vector_stroke_scaling(vdev, pis, &scale, &mat)) != 0 ||
(code = gdev_vector_prepare_stroke(vdev, pis, params, pdcolor, scale)) < 0 ||
- (code = gdev_vector_update_clip_path(vdev, pcpath)) < 0 ||
(vdev->bbox_device &&
(code = (*dev_proc(vdev->bbox_device, stroke_path))
((gx_device *) vdev->bbox_device, pis, ppath, params,
Modified: branches/mtrender/src/gs.mak
===================================================================
--- branches/mtrender/src/gs.mak 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gs.mak 2008-05-04 17:50:39 UTC (rev 8698)
@@ -275,10 +275,10 @@
$(RMN_) $(GSGEN)_temp_* $(GSGEN)_temp_*.* $(GSOBJ)*.map $(GSOBJ)*.sym
$(RMN_) $(GENARCH_XE) $(GENCONF_XE) $(GENDEV_XE) $(GENHT_XE) $(GENINIT_XE)
$(RMN_) $(ECHOGS_XE)
- $(RMN_) $(GSGEN)gs_init.c $(BEGINFILES)
+ $(RMN_) $(GSGEN)gs_init.ps $(BEGINFILES)
$(RMN_) $(MKROMFS_XE)
$(RMN_) $(PSGEN)$(GS_INIT)
- $(RMN_) $(GSGEN)gsromfs.c
+ $(RMN_) $(GSGEN)gsromfs1.c
# Remove only configuration-dependent information.
#****** FOLLOWING IS WRONG, NEEDS TO BE PER-SUBSYSTEM ******
Modified: branches/mtrender/src/gscdevn.c
===================================================================
--- branches/mtrender/src/gscdevn.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gscdevn.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -34,6 +34,7 @@
#include "gxdevcli.h"
#include "gsovrc.h"
#include "stream.h"
+#include "gsnamecl.h" /* Custom color call back define */
/* ---------------- Color space ---------------- */
Modified: branches/mtrender/src/gscedata.c
===================================================================
--- branches/mtrender/src/gscedata.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gscedata.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -10,8 +10,18 @@
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
*/
-
/* $Id$ */
+/*
+ * This file contains substantial parts of toolbin/encs2c.ps,
+ * which generated the remainder of the file mechanically from
+ * gs_std_e.ps gs_il1_e.ps gs_sym_e.ps gs_dbt_e.ps
+ * gs_wan_e.ps gs_mro_e.ps gs_mex_e.ps gs_mgl_e.ps
+ * gs_lgo_e.ps gs_lgx_e.ps gs_css_e.ps
+ *
+ * This source file is maintained manually under source code control,
+ * however its content should be regenerated by using encs2c.ps
+ * if changes are required.
+ */
#include "stdpre.h"
#include "gstypes.h"
Modified: branches/mtrender/src/gscedata.h
===================================================================
--- branches/mtrender/src/gscedata.h 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gscedata.h 2008-05-04 17:50:39 UTC (rev 8698)
@@ -10,8 +10,18 @@
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
*/
-
/* $Id$ */
+/*
+ * This file contains substantial parts of toolbin/encs2c.ps,
+ * which generated the remainder of the file mechanically from
+ * gs_std_e.ps gs_il1_e.ps gs_sym_e.ps gs_dbt_e.ps
+ * gs_wan_e.ps gs_mro_e.ps gs_mex_e.ps gs_mgl_e.ps
+ * gs_lgo_e.ps gs_lgx_e.ps gs_css_e.ps
+ *
+ * This source file is maintained manually under source code control,
+ * however its content should be regenerated by using encs2c.ps
+ * if changes are required.
+ */
#ifndef gscedata_INCLUDED
# define gscedata_INCLUDED
Modified: branches/mtrender/src/gscspace.c
===================================================================
--- branches/mtrender/src/gscspace.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gscspace.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -28,6 +28,7 @@
#include "gxdevcli.h"
#include "gzstate.h"
#include "stream.h"
+#include "gsnamecl.h" /* Custom color call back define */
static cs_proc_install_cspace(gx_install_DeviceGray);
static cs_proc_install_cspace(gx_install_DeviceRGB);
@@ -308,7 +309,9 @@
/*
* Determine if the current color model is a "DeviceCMYK" color model, and
* if so what are its process color components. This information is required
- * only if overprint is true and overprint mode is set to 1.
+ * when PLRM defines special rules for CMYK devices. This includes:
+ * 1. DeviceGray to CMYK color conversion
+ * 2. when overprint is true and overprint mode is set to 1.
*
* A color model is considered a "DeviceCMYK" color model if it supports the
* cyan, magenta, yellow, and black color components, and maps the DeviceCMYK
@@ -320,7 +323,7 @@
* If the color model is a "DeviceCMYK" color model, return the set of
* process color components; otherwise return 0.
*/
-static gx_color_index
+gx_color_index
check_cmyk_color_model_comps(gx_device * dev)
{
gx_device_color_info * pcinfo = &dev->color_info;
@@ -384,6 +387,7 @@
| ((gx_color_index)1 << black_c);
pcinfo->opmode = GX_CINFO_OPMODE;
pcinfo->process_comps = process_comps;
+ pcinfo->black_component = black_c;
return process_comps;
}
Modified: branches/mtrender/src/gscspace.h
===================================================================
--- branches/mtrender/src/gscspace.h 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gscspace.h 2008-05-04 17:50:39 UTC (rev 8698)
@@ -118,8 +118,8 @@
/* We define the names only for debugging printout. */
#define GS_COLOR_SPACE_TYPE_NAMES\
"DeviceGray", "DeviceRGB", "DeviceCMYK", "DevicePixel", "DeviceN",\
- "ICCBased", "CIEBasedDEFG", "CIEBasedDEF", "CIEBasedABC", "CIEBasedA",\
- "Separation", "Indexed", "Pattern"
+ "CIEBasedDEFG", "CIEBasedDEF", "CIEBasedABC", "CIEBasedA",\
+ "Separation", "Indexed", "Pattern", "ICCBased"
/* Define an abstract type for color space types (method structures). */
typedef struct gs_color_space_type_s gs_color_space_type;
@@ -254,11 +254,12 @@
gs_cie_def * def;
gs_cie_abc * abc;
gs_cie_a * a;
- gs_icc_params icc;
gs_separation_params separation;
gs_device_n_params device_n;
gs_indexed_params indexed;
gs_pattern_params pattern;
+ gs_icc_params icc;
+
} params;
};
Modified: branches/mtrender/src/gsdps1.c
===================================================================
--- branches/mtrender/src/gsdps1.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gsdps1.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -244,10 +244,10 @@
} else {
int x, y, w, h;
- draw_rect.p.x -= pgs->fill_adjust.x;
- draw_rect.p.y -= pgs->fill_adjust.x;
+ draw_rect.p.x -= max(pgs->fill_adjust.x - fixed_epsilon, 0);
+ draw_rect.p.y -= max(pgs->fill_adjust.y - fixed_epsilon, 0);
draw_rect.q.x += pgs->fill_adjust.x;
- draw_rect.q.y += pgs->fill_adjust.x;
+ draw_rect.q.y += pgs->fill_adjust.y;
rect_intersect(draw_rect, clip_rect);
x = fixed2int_pixround(draw_rect.p.x);
y = fixed2int_pixround(draw_rect.p.y);
Modified: branches/mtrender/src/gsicc.c
===================================================================
--- branches/mtrender/src/gsicc.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gsicc.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -24,7 +24,6 @@
#include "gxarith.h"
#include "gxcie.h"
#include "gzstate.h"
-#include "stream.h"
#include "icc.h" /* must precede icc.h */
#include "gsicc.h"
@@ -253,21 +252,26 @@
gx_restrict_CIEICC(&lcc, pcs);
for (i = 0; i < ncomps; i++)
inv[i] = lcc.paint.values[i];
+
+ /* Since the original limits were wrong for this case, We need to adjust things a bit different */
/* For input Lab color space massage the values into Lab range */
- if (picc_info->plu->e_inSpace == icSigLabData) {
+ /* if (picc_info->plu->e_inSpace == icSigLabData) {
+
inv[0] *= 100;
inv[1] = inv[1]*255 - 128;
inv[2] = inv[2]*255 - 128;
- }
+ } */
+
/*
* Perform the lookup operation. A return value of 1 indicates that
* clipping occurred somewhere in the operation, but the result is
* legitimate. Other non-zero return values indicate an error, which
* should not occur in practice.
*/
+
if (picc_info->plu->lookup(picc_info->plu, outv, inv) > 1)
return_error(gs_error_unregistered);
Modified: branches/mtrender/src/gsimage.c
===================================================================
--- branches/mtrender/src/gsimage.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gsimage.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -194,6 +194,7 @@
gx_clip_path *pcpath;
int code = gx_effective_clip_path(pgs, &pcpath);
gx_device *dev2 = dev;
+ gx_device_color dc_temp, *pdevc = pgs->dev_color;
if (code < 0)
return code;
@@ -219,9 +220,13 @@
if (code < 0)
return code;
}
+ if (dev2 != dev) {
+ set_nonclient_dev_color(&dc_temp, 1);
+ pdevc = &dc_temp;
+ }
}
code = gx_device_begin_typed_image(dev2, (const gs_imager_state *)pgs,
- NULL, pic, NULL, pgs->dev_color, pcpath, pgs->memory, ppie);
+ NULL, pic, NULL, pdevc, pcpath, pgs->memory, ppie);
if (code < 0)
return code;
code = is_image_visible(pic, pgs, pcpath);
Modified: branches/mtrender/src/gsnamecl.c
===================================================================
--- branches/mtrender/src/gsnamecl.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gsnamecl.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -1,215 +1,216 @@
-/* Copyright (C) 2001-2006 Artifex Software, Inc.
- All Rights Reserved.
-
- This software is provided AS-IS with no warranty, either express or
- implied.
-
- This software is distributed under license and may not be copied, modified
- or distributed except as expressly authorized under the terms of that
- license. Refer to licensing information at http://www.artifex.com/
- or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
- San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
-*/
-/* $Id$ */
-/* Callback mechanism for handling color spaces containing named colors. */
-
-/*
- * This module has been created to provide a callback mechanism for special
- * processing of DeviceN and Separation color spaces. One possible application
- * of this callback mechanism is to provide a means for special handling of
- * PANTONE or SWOP colors.
- *
- * This implementation consists of four routines. There are a pair of
- * routines for both Separation and DeviceN color spaces. Each pair consists
- * of a routine that is called when the color space is installed and a
- * second routine that is called to transform colors in that color space
- * into device colorant values. The routines named_color_install_Separation
- * and named_color_install_DeviceN are called when a Separation or DeviceN
- * color space is installed. These routines determine if the given color space
- * meets some criteria decided by the client. These routines return true if the
- * colors in the color space should be processed via the second routine.
- */
-
-#include "stdpre.h"
-#include "math_.h"
-#include "memory_.h"
-#include "gx.h"
-#include "gserrors.h"
-#include "gscdefs.h"
-#include "gscspace.h"
-#include "gxdevice.h"
-#include "gzstate.h"
-#include "gsutil.h"
-
-#if ENABLE_CUSTOM_COLOR_CALLBACK /* Defined in src/gsnamecl.h */
-
-/*
- * Check if we want to use the callback color processing logic for the given
- * Separation color space.
- */
-bool
-custom_color_callback_install_Separation(gs_color_space * pcs, gs_state * pgs)
-{
- client_custom_color_params_t * pcb =
- (client_custom_color_params_t *) pgs->custom_color_callback;
-
- return (pcb == NULL) ? false
- : pcb->client_procs->install_Separation(pcb, pcs, pgs);
-}
-
-/*
- * Check if we want to use the callback color processing logic for the given
- * DeviceN color space.
- */
-bool
-custom_color_callback_install_DeviceN(gs_color_space * pcs, gs_state * pgs)
-{
- client_custom_color_params_t * pcb =
- (client_custom_color_params_t *) pgs->custom_color_callback;
-
- return (pcb == NULL) ? false
- : pcb->client_procs->install_DeviceN(pcb, pcs, pgs);
- }
-
-/*
- * Convert a Separation color using the 'custom color' callback into
- * device color.
-*/
-int
-gx_remap_concrete_custom_color_Separation(const frac * pconc,
- const gs_color_space * pcs, gx_device_color * pdc,
- const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
-{
- client_custom_color_params_t * pcb =
- (client_custom_color_params_t *) pis->custom_color_callback;
-
- if (pcb == NULL) {
- return_error(gs_error_rangecheck);
- }
- else
- return pcb->client_procs->remap_Separation(pcb, pconc,
- pcs, pdc, pis, dev, select);
-}
-
-/*
- * Convert a DeviceN color using the 'custom color' callback into device
- * color.
- */
-int
-gx_remap_concrete_custom_color_DeviceN(const frac * pconc,
- const gs_color_space * pcs, gx_device_color * pdc,
- const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
-{
- client_custom_color_params_t * pcb =
- (client_custom_color_params_t *) pis->custom_color_callback;
-
- if (pcb == NULL) {
- return_error(gs_error_rangecheck);
- }
- else
- return pcb->client_procs->remap_DeviceN(pcb, pconc,
- pcs, pdc, pis, dev, select);
-}
-
-/*
- * Get the 'custom color' client callback parameter block pointer. This value
- * is passed as a string type device paramter. A string is being used since
- * PostScript does not support pointers as a type. Note: An integer type
- * is not being used since PS intergers are nominally 32 bits. Thus there
- * would be a problem using integers to pass pointer values on 64 bit systems.
- */
-int
-custom_color_callback_get_params(gs_state * pgs, gs_param_list * plist)
-{
- /* Convert our pointer to a PostScript hex string */
- char buf[64] = "16#";
- int buf_pos = 3;
- gs_param_string custom_color_param;
- int idx;
- int val;
- size_t iptr;
-
- idx = ((int)sizeof(size_t)) * 8 - 4;
- iptr = (size_t)(pgs->custom_color_callback);
- while (idx >= 0) {
- val = (int)(iptr >> idx) & 0xf;
- if (val <= 9)
- buf[buf_pos++] = '0' + val;
- else
- buf[buf_pos++] = 'a' - 10 + val;
- idx -= 4;
- }
- param_string_from_transient_string(custom_color_param, buf);
-
- return param_write_string(plist, CustomColorCallbackParamName,
- &custom_color_param);
-}
-
-/*
- * Put the 'custom color' client callback parameter block pointer. This value
- * is passed as a string type device paramter. A string is being used since
- * PostScript does not support pointers as a type. Note: An integer type
- * is not being used since PS integers are nominally 32 bits. Thus there
- * would be a problem using integers to pass pointer values on 64 bit systems.
- */
-int
-custom_color_callback_put_params(gs_state * pgs, gs_param_list * plist)
-{
- int code;
- size_t iptr = (size_t)(pgs->custom_color_callback);
- gs_param_string dh = { 0 };
-
- switch (code = param_read_string(plist, CustomColorCallbackParamName, &dh)) {
- case 0:
- {
- /*
- * Convert from a string to a pointer.
- * It is assumed that size_t has the same size as a pointer.
- * Allow formats (1234), (10#1234) or (16#04d2).
- */
- uint i;
- int base = 10;
- int val;
- code = 0;
- for (i = 0; i < dh.size; i++) {
- val = dh.data[i];
- if ((val >= '0') && (val <= '9'))
- val = val - '0';
- else if ((val >= 'A') && (val <= 'F'))
- val = val - 'A' + 10;
- else if ((val >= 'a') && (val <= 'f'))
- val = val - 'a' + 10;
- else if (val == '#' && ((iptr == 10) || (iptr == 16))) {
- base = (int) iptr;
- iptr = 0;
- continue;
- }
- else {
- code = gs_error_rangecheck;
- break;
- }
- iptr = iptr * base + val;
- }
- }
- break;
- default:
- case 1:
- dh.data = 0;
- break;
- }
- if (code < 0) {
- param_signal_error(plist, "CustomColorCallback", code);
- }
- else if (pgs->custom_color_callback != (void *)iptr) {
- pgs->custom_color_callback = (void *)iptr;
- /*
- * Custom color processing can depend upon the type of object
- * being imaged so we enable object type tagging.
- */
- gs_enable_object_tagging();
- }
-
- return 0;
-}
-
-#endif /* ENABLE_CUSTOM_COLOR_CALLBACK */
+/* Copyright (C) 2001-2006 Artifex Software, Inc.
+ All Rights Reserved.
+
+ This software is provided AS-IS with no warranty, either express or
+ implied.
+
+ This software is distributed under license and may not be copied, modified
+ or distributed except as expressly authorized under the terms of that
+ license. Refer to licensing information at http://www.artifex.com/
+ or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
+ San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
+*/
+/* $Id$ */
+/* Callback mechanism for handling color spaces containing named colors. */
+
+/*
+ * This module has been created to provide a callback mechanism for special
+ * processing of DeviceN and Separation color spaces. One possible application
+ * of this callback mechanism is to provide a means for special handling of
+ * PANTONE or SWOP colors.
+ *
+ * This implementation consists of four routines. There are a pair of
+ * routines for both Separation and DeviceN color spaces. Each pair consists
+ * of a routine that is called when the color space is installed and a
+ * second routine that is called to transform colors in that color space
+ * into device colorant values. The routines named_color_install_Separation
+ * and named_color_install_DeviceN are called when a Separation or DeviceN
+ * color space is installed. These routines determine if the given color space
+ * meets some criteria decided by the client. These routines return true if the
+ * colors in the color space should be processed via the second routine.
+ */
+
+#include "stdpre.h"
+#include "math_.h"
+#include "memory_.h"
+#include "gx.h"
+#include "gserrors.h"
+#include "gscdefs.h"
+#include "gscspace.h"
+#include "gxdevice.h"
+#include "gzstate.h"
+#include "gsutil.h"
+#include "gsnamecl.h" /* Custom color call back define */
+
+#if ENABLE_CUSTOM_COLOR_CALLBACK /* Defined in src/gsnamecl.h */
+
+/*
+ * Check if we want to use the callback color processing logic for the given
+ * Separation color space.
+ */
+bool
+custom_color_callback_install_Separation(gs_color_space * pcs, gs_state * pgs)
+{
+ client_custom_color_params_t * pcb =
+ (client_custom_color_params_t *) pgs->custom_color_callback;
+
+ return (pcb == NULL) ? false
+ : pcb->client_procs->install_Separation(pcb, pcs, pgs);
+}
+
+/*
+ * Check if we want to use the callback color processing logic for the given
+ * DeviceN color space.
+ */
+bool
+custom_color_callback_install_DeviceN(gs_color_space * pcs, gs_state * pgs)
+{
+ client_custom_color_params_t * pcb =
+ (client_custom_color_params_t *) pgs->custom_color_callback;
+
+ return (pcb == NULL) ? false
+ : pcb->client_procs->install_DeviceN(pcb, pcs, pgs);
+ }
+
+/*
+ * Convert a Separation color using the 'custom color' callback into
+ * device color.
+*/
+int
+gx_remap_concrete_custom_color_Separation(const frac * pconc,
+ const gs_color_space * pcs, gx_device_color * pdc,
+ const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
+{
+ client_custom_color_params_t * pcb =
+ (client_custom_color_params_t *) pis->custom_color_callback;
+
+ if (pcb == NULL) {
+ return_error(gs_error_rangecheck);
+ }
+ else
+ return pcb->client_procs->remap_Separation(pcb, pconc,
+ pcs, pdc, pis, dev, select);
+}
+
+/*
+ * Convert a DeviceN color using the 'custom color' callback into device
+ * color.
+ */
+int
+gx_remap_concrete_custom_color_DeviceN(const frac * pconc,
+ const gs_color_space * pcs, gx_device_color * pdc,
+ const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
+{
+ client_custom_color_params_t * pcb =
+ (client_custom_color_params_t *) pis->custom_color_callback;
+
+ if (pcb == NULL) {
+ return_error(gs_error_rangecheck);
+ }
+ else
+ return pcb->client_procs->remap_DeviceN(pcb, pconc,
+ pcs, pdc, pis, dev, select);
+}
+
+/*
+ * Get the 'custom color' client callback parameter block pointer. This value
+ * is passed as a string type device paramter. A string is being used since
+ * PostScript does not support pointers as a type. Note: An integer type
+ * is not being used since PS intergers are nominally 32 bits. Thus there
+ * would be a problem using integers to pass pointer values on 64 bit systems.
+ */
+int
+custom_color_callback_get_params(gs_state * pgs, gs_param_list * plist)
+{
+ /* Convert our pointer to a PostScript hex string */
+ char buf[64] = "16#";
+ int buf_pos = 3;
+ gs_param_string custom_color_param;
+ int idx;
+ int val;
+ size_t iptr;
+
+ idx = ((int)sizeof(size_t)) * 8 - 4;
+ iptr = (size_t)(pgs->custom_color_callback);
+ while (idx >= 0) {
+ val = (int)(iptr >> idx) & 0xf;
+ if (val <= 9)
+ buf[buf_pos++] = '0' + val;
+ else
+ buf[buf_pos++] = 'a' - 10 + val;
+ idx -= 4;
+ }
+ param_string_from_transient_string(custom_color_param, buf);
+
+ return param_write_string(plist, CustomColorCallbackParamName,
+ &custom_color_param);
+}
+
+/*
+ * Put the 'custom color' client callback parameter block pointer. This value
+ * is passed as a string type device paramter. A string is being used since
+ * PostScript does not support pointers as a type. Note: An integer type
+ * is not being used since PS integers are nominally 32 bits. Thus there
+ * would be a problem using integers to pass pointer values on 64 bit systems.
+ */
+int
+custom_color_callback_put_params(gs_state * pgs, gs_param_list * plist)
+{
+ int code;
+ size_t iptr = (size_t)(pgs->custom_color_callback);
+ gs_param_string dh = { 0 };
+
+ switch (code = param_read_string(plist, CustomColorCallbackParamName, &dh)) {
+ case 0:
+ {
+ /*
+ * Convert from a string to a pointer.
+ * It is assumed that size_t has the same size as a pointer.
+ * Allow formats (1234), (10#1234) or (16#04d2).
+ */
+ uint i;
+ int base = 10;
+ int val;
+ code = 0;
+ for (i = 0; i < dh.size; i++) {
+ val = dh.data[i];
+ if ((val >= '0') && (val <= '9'))
+ val = val - '0';
+ else if ((val >= 'A') && (val <= 'F'))
+ val = val - 'A' + 10;
+ else if ((val >= 'a') && (val <= 'f'))
+ val = val - 'a' + 10;
+ else if (val == '#' && ((iptr == 10) || (iptr == 16))) {
+ base = (int) iptr;
+ iptr = 0;
+ continue;
+ }
+ else {
+ code = gs_error_rangecheck;
+ break;
+ }
+ iptr = iptr * base + val;
+ }
+ }
+ break;
+ default:
+ case 1:
+ dh.data = 0;
+ break;
+ }
+ if (code < 0) {
+ param_signal_error(plist, "CustomColorCallback", code);
+ }
+ else if (pgs->custom_color_callback != (void *)iptr) {
+ pgs->custom_color_callback = (void *)iptr;
+ /*
+ * Custom color processing can depend upon the type of object
+ * being imaged so we enable object type tagging.
+ */
+ gs_enable_object_tagging();
+ }
+
+ return 0;
+}
+
+#endif /* ENABLE_CUSTOM_COLOR_CALLBACK */
Modified: branches/mtrender/src/gsnamecl.h
===================================================================
--- branches/mtrender/src/gsnamecl.h 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gsnamecl.h 2008-05-04 17:50:39 UTC (rev 8698)
@@ -25,9 +25,10 @@
* Enable custom client callback color processing. Note: There is a sample
* implementation in src/gsncdummy.c.
*/
+#ifndef ENABLE_CUSTOM_COLOR_CALLBACK
#define ENABLE_CUSTOM_COLOR_CALLBACK 0 /* 0 --> disabled, 1 --> enabled */
+#endif
-
#if ENABLE_CUSTOM_COLOR_CALLBACK
/* Ptr to custom color callback struct */
#define CUSTOM_COLOR_PTR void * custom_color_callback;
Modified: branches/mtrender/src/gsncdummy.c
===================================================================
--- branches/mtrender/src/gsncdummy.c 2008-05-04 17:46:33 UTC (rev 8697)
+++ branches/mtrender/src/gsncdummy.c 2008-05-04 17:50:39 UTC (rev 8698)
@@ -20,8 +20,11 @@
* all lines and fills to shades of blue. if the flag is 0 then our example
* only handles PANTONE colors (see comment below).
*/
-#define OBJECT_TYPE_EXAMPLE 1 /* 0 --> disabled, 1 --> enabled */
+/* Added these two defines so that I could compare to ghost script rendering color */
+
+#define OBJECT_TYPE_EXAMPLE 0 /* 0 --> disabled, 1 --> enabled */
+#define PANTONE_ONLY 0
/*
* This module has been created to demonstrate how to support the use of
* PANTONE colors to the Ghostscript graphics library. PANTONE colors
@@ -70,8 +73,10 @@
#include "gzstate.h"
#include "malloc_.h"
#include "gsutil.h"
+#include "gxcie.h"
#include "gsncdummy.h"
+
#if ENABLE_CUSTOM_COLOR_CALLBACK /* Defined in src/gsnamecl.h */
/*
@@ -151,40 +156,6 @@
}
/*
- * Dummy convert routine for simple color spaces (gray, RGB, CMYK, DeviceN,
- * and Separation) which are not handled by the client.
- */
-static int
-client_remap_simple_no_op(client_custom_color_params_t * pparams,
- const frac * pconc, const gs_color_space * pcs, gx_device_color * pdc,
- const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
-{
- /*
- * Returning an error value will cause GS to use its normal processes
- * for handling the color space.
- */
- return_error(gs_error_rangecheck);
-}
-
-/*
- * Dummy convert routine for complex color spaces (CIEBasedA, CIEBasedABC,
- * CIEBasedDEF, CIEBasedDEF, CIEBasedDEFG, ICCBased) which are not handled
- * by the client.
- */
-static int
-client_remap_complex_no_op(client_custom_color_params_t * pparams,
- const gs_client_color * pc, const gs_color_space * pcs,
- gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
- gs_color_select_t select)
-{
- /*
- * Returning an error value will cause GS to use its normal processes
- * for handling the color space.
- */
- return_error(gs_error_rangecheck);
-}
-
-/*
* Since this is an example for a client, we are using the system
* malloc and free routines instead of the normal GS memory management
* routines.
@@ -525,7 +496,9 @@
pdc, pis, dev, select, gs_color_space_num_components(pcs));
}
-#if OBJECT_TYPE_EXAMPLE
+
+#if !PANTONE_ONLY
+
/*
* Install a DeviceGray color space.
*/
@@ -577,13 +550,24 @@
const frac * pconc, const gs_color_space * pcs, gx_device_color * pdc,
const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
{
- /*
- * For demo and debug purposes, make our colors a function of the
- * intensity of the given colors and the object type.
- */
- frac intensity = pconc[0];
- convert_intensity_into_device_color(intensity, pdc, pis, dev, select);
+ #if OBJECT_TYPE_EXAMPLE
+
+ /* For demo and debug purposes, make our colors a function of the
+ * intensity of the given colors and the object type. */
+
+ frac intensity = pconc[0];
+ convert_intensity_into_device_color(intensity, pdc, pis, dev, select);
+
+ #else
+
+ /* If desired, replace with your own color transformation */
+
+ gx_remap_concrete_gray(pconc[0], pdc, pis, dev, select);
+
+ #endif
+
+
return 0;
}
@@ -607,13 +591,23 @@
const frac * pconc, const gs_color_space * pcs, gx_device_color * pdc,
const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
{
- /*
- * For demo and debug purposes, make our colors a function of the
- * intensity of the given colors and the object type.
- */
- frac intensity = (frac)(pconc[0] * 0.30 + pconc[1] * 0.59 + pconc[2] * 0.11);
- convert_intensity_into_device_color(intensity, pdc, pis, dev, select);
+ #if OBJECT_TYPE_EXAMPLE
+
+ /* For demo and debug purposes, make our colors a function of the
+ * intensity of the given colors and the object type. */
+
+ frac intensity = (frac)(pconc[0] * 0.30 + pconc[1] * 0.59 + pconc[2] * 0.11);
+ convert_intensity_into_device_color(intensity, pdc, pis, dev, select);
+
+ #else
+
+ /* If desired, replace with your own color transformation */
+
+ gx_remap_concrete_rgb(pconc[0], pconc[1], pconc[2], pdc, pis, dev, select);
+
+ #endif
+
return 0;
}
@@ -636,16 +630,27 @@
const frac * pconc, const gs_color_space * pcs, gx_device_color * pdc,
const gs_imager_state * pis, gx_device * dev, gs_color_select_t select)
{
- /*
- * For demo and debug purposes, make our colors a function of the
- * intensity of the given colors and the object type.
- */
- frac intensity = frac_1 - (frac)(pconc[0] * 0.30 + pconc[1] * 0.59
- + pconc[2] * 0.11 + pconc[3]);
- if (intensity < frac_0)
- intensity = frac_0;
- convert_intensity_into_device_color(intensity, pdc, pis, dev, select);
+ #if OBJECT_TYPE_EXAMPLE
+
+ /*
+ * For demo and debug purposes, make our colors a function of the
+ * intensity of the given colors and the object type. */
+
+ frac intensity = frac_1 - (frac)(pconc[0] * 0.30 + pconc[1] * 0.59
+ + pconc[2] * 0.11 + pconc[3]);
+
+ if (intensity < frac_0)
+ intensity = frac_0;
+ convert_intensity_into_device_color(intensity, pdc, pis, dev, select);
+
+ #else
+
+ /* If desired, replace with your own color transformation */
+ gx_remap_concrete_cmyk(pconc[0], pconc[1], pconc[2], pconc[3],pdc, pis, dev, select);
+
+ #endif
+
return 0;
}
@@ -659,6 +664,7 @@
: (frac) (frac_1 * \
(color - range.rmin) / (range.rmax - range.rmin))
+static bool
client_install_CIEtoA(client_custom_color_params_t * pparams,
gs_color_space * pcs, gs_state * pgs)
{
@@ -704,6 +710,7 @@
return true;
}
+static bool
client_install_CIEtoXYZ(client_custom_color_params_t * pparams,
gs_color_space * pcs, gs_state * pgs)
{
@@ -764,23 +771,47 @@
return true;
}
+
+static bool
client_install_ICCtoXYZ(client_custom_color_params_t * pparams,
gs_color_space * pcs, gs_state * pgs)
{
int code;
const gs_icc_params * picc_params = (const gs_icc_params *)&pcs->params.icc;
gs_cie_icc * picc_info = picc_params->picc_info;
+ demo_color_space_data_t * pdata;
- /* update the stub information used by the joint caches */
+ if (pcs->pclient_color_space_data != NULL)
+ return true;
+
+ pdata = allocate_client_data_block(1, pcs->rc.memory->stable_memory);
+ pcs->pclient_color_space_data = (client_color_space_data_t *) pdata;
+
+ /* Need to initialize the client data. The imager_state is what is needed in pdata->CIEtoXZY_ps */
+
+ /* update the stub information used by the joint caches */
gx_cie_load_common_cache(&picc_info->common, pgs);
gx_cie_common_complete(&picc_info->common);
+
if ((code=gs_cie_cs_complete(pgs, true)) < 0) {
- client_adjust_cspace_count(pcs, -1); /* free it up */
+ client_adjust_cspace_count(pcs, -1); /* free it up */
return false;
}
+
+ /* Now allocate the conversion imager state in stable_memory */
+ /* so that the garbage collector won't free it */
+ code = gx_cie_to_xyz_alloc(&pdata->CIEtoXYZ_pis, pcs,
+ pcs->rc.memory->stable_memory);
+
+ if (code < 0) {
+ client_adjust_cspace_count(pcs, -1); /* free it up */
+ return false;
+ }
+
return true;
}
+
/*
* Convert a CIEBasedA color into device color.
*/
@@ -794,7 +825,6 @@
(demo_color_space_data_t *)(pcs->pclient_color_space_data);
frac gray = convert2frac(pc->paint.values[0], pcs->params.a->RangeA);
-
/*** Demonstrate method to convert to XYZ ***/
if (pdata->CIEtoXYZ_pis) {
frac xyz[3];
@@ -941,16 +971,18 @@
int i, num_values = pcs->params.icc.picc_info->num_components;
/*** Demonstrate method to convert to XYZ ***/
- if (pdata->CIEtoXYZ_pis) {
- frac xyz[3];
+ if (pdata->CIEtoXYZ_pis) {
- cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
- /* We don't really do anything with these values, but this */
- /* is where a real client could convert to a device color */
- if_debug6('|', "[c]client_remap ICCBased [%g, %g, %g] -> XYZ [%g, %g, %g]\n",
- pc->paint.values[0], pc->paint.values[1], pc->paint.values[2],
- frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
+ frac xyz[3];
+
+ cs_concretize_color(pc, pcs, xyz, pdata->CIEtoXYZ_pis);
+ /* We don't really do anything with these values, but this */
+ /* is where a real client could convert to a device color */
+ if_debug6('|', "[c]client_remap ICCBased [%g, %g, %g] -> XYZ [%g, %g, %g]\n",
+ pc->paint.values[0], pc->paint.values[1], pc->paint.values[2],
+ frac2float(xyz[0]), frac2float(xyz[1]), frac2float(xyz[2]));
}
+
/*
* For demo and debug purposes, make our colors a function of the
* intensity of the given color value and the object type. The color
@@ -980,9 +1012,40 @@
#undef convert2frac
-#endif /* OBJECT_TYPE_EXAMPLE */
+#endif /* NOT PANTONE_ONLY */
-#if OBJECT_TYPE_EXAMPLE
+#if PANTONE_ONLY
+
+ /*
+ * For PANTONE colors, we only need to handle Separation and DeviceN
+ * color spaces. These are the only color spaces that can have PANTONE
+ * colors.
+ */
+ client_custom_color_procs_t demo_procs = {
+ client_install_no_op, /* DeviceGray */
+ NULL,
+ client_install_no_op, /* DeviceRGB */
+ NULL,
+ client_install_no_op, /* DeviceCMYK */
+ NULL,
+ client_pantone_install_Separation, /* Separation */
+ client_pantone_remap_Separation,
+ client_pantone_install_DeviceN, /* DeviceN */
+ client_pantone_remap_DeviceN,
+ client_install_no_op, /* CIEBasedA */
+ NULL,
+ client_install_no_op, /* CIEBasedABC */
+ NULL,
+ client_install_no_op, /* CIEBasedDEF */
+ NULL,
+ client_install_no_op, /* CIEBasedDEFG */
+ NULL,
+ client_install_no_op, /* ICCBased */
+ NULL
+ };
+
+#else /* Not PANTONE_ONLY special */
+
/*
* Client call back procedures for our demo which illustrates color
* processing based upon object type.
@@ -1009,34 +1072,7 @@
client_install_ICCtoXYZ, /* ICCBased */
client_remap_ICCBased
};
-#else /*