~ubuntu-branches/ubuntu/oneiric/ghostscript/oneiric

« back to all changes in this revision

Viewing changes to base/saes.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2011-07-15 16:49:55 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20110715164955-uga6qibao6kez05c
Tags: 9.04~dfsg~20110715-0ubuntu1
* New upstream release
   - GIT snapshot from Jult, 12 2011.
* debian/patches/020110406~a54df2d.patch,
  debian/patches/020110408~0791cc8.patch,
  debian/patches/020110408~507cbee.patch,
  debian/patches/020110411~4509a49.patch,
  debian/patches/020110412~78bb9a6.patch,
  debian/patches/020110418~a05ab8a.patch,
  debian/patches/020110420~20b6c78.patch,
  debian/patches/020110420~4ddefa2.patch: Removed upstream patches.
* debian/rules: Generate ABI version number (variable "abi") correctly,
  cutting off repackaging and pre-release parts.
* debian/rules: Added ./lcms2/ directory to DEB_UPSTREAM_REPACKAGE_EXCLUDES.
* debian/copyright: Added lcms2/* to the list of excluded files.
* debian/symbols.common: Updated for new upstream source. Applied patch
  which dpkg-gensymbols generated for debian/libgs9.symbols to this file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
/* stream implementation */
25
25
 
26
26
private_st_aes_state(); /* creates a gc object for our state,
27
 
                           defined in saes.h */
 
27
                           defined in saes.h */
28
28
 
29
29
/* Store a key in our crypt context */
30
30
int
31
31
s_aes_set_key(stream_aes_state * state, const unsigned char *key,
32
 
                  int keylength)
 
32
                  int keylength)
33
33
{
34
34
    int code = 0;
35
35
 
36
36
    if ( (keylength < 1) || (keylength > SAES_MAX_KEYLENGTH) )
37
 
        return_error(gs_error_rangecheck);
 
37
        return_error(gs_error_rangecheck);
38
38
    if (key == NULL)
39
 
        return_error(gs_error_invalidaccess);
 
39
        return_error(gs_error_invalidaccess);
40
40
 
41
41
    /* we can't set the key here because the interpreter's
42
42
       filter implementation wants to duplicate our state
90
90
 */
91
91
static int
92
92
s_aes_process(stream_state * ss, stream_cursor_read * pr,
93
 
                  stream_cursor_write * pw, bool last)
 
93
                  stream_cursor_write * pw, bool last)
94
94
{
95
95
    stream_aes_state *const state = (stream_aes_state *) ss;
96
96
    const unsigned char *limit;
101
101
 
102
102
    /* figure out if we're going to run out of space */
103
103
    if (in_size > out_size) {
104
 
        limit = pr->ptr + out_size;
105
 
        status = 1; /* need more output space */
 
104
        limit = pr->ptr + out_size;
 
105
        status = 1; /* need more output space */
106
106
    } else {
107
 
        limit = pr->limit;
108
 
        status = last ? EOFC : 0; /* need more input */
 
107
        limit = pr->limit;
 
108
        status = last ? EOFC : 0; /* need more input */
109
109
    }
110
110
 
111
111
    /* set up state and context */
114
114
         contains internal pointers, so we need to store it separately
115
115
         in immovable memory like any opaque structure. */
116
116
      state->ctx = (aes_context *)gs_alloc_bytes_immovable(state->memory,
117
 
                sizeof(aes_context), "aes context structure");
 
117
                sizeof(aes_context), "aes context structure");
118
118
      if (state->ctx == NULL) {
119
 
        gs_throw(gs_error_VMerror, "could not allocate aes context");
120
 
        return ERRC;
 
119
        gs_throw(gs_error_VMerror, "could not allocate aes context");
 
120
        return ERRC;
121
121
      }
122
122
      if (state->keylength < 1 || state->keylength > SAES_MAX_KEYLENGTH) {
123
 
        gs_throw1(gs_error_rangecheck, "invalid aes key length (%d bytes)",
124
 
                state->keylength);
125
 
        return ERRC;
 
123
        gs_throw1(gs_error_rangecheck, "invalid aes key length (%d bytes)",
 
124
                state->keylength);
 
125
        return ERRC;
126
126
      }
127
127
      aes_setkey_dec(state->ctx, state->key, state->keylength * 8);
128
128
    }
129
129
    if (!state->initialized) {
130
 
        /* read the initialization vector from the first 16 bytes */
131
 
        if (in_size < 16) return 0; /* get more data */
132
 
        memcpy(state->iv, pr->ptr + 1, 16);
133
 
        state->initialized = 1;
134
 
        pr->ptr += 16;
 
130
        /* read the initialization vector from the first 16 bytes */
 
131
        if (in_size < 16) return 0; /* get more data */
 
132
        memcpy(state->iv, pr->ptr + 1, 16);
 
133
        state->initialized = 1;
 
134
        pr->ptr += 16;
135
135
    }
136
136
 
137
137
    /* decrypt available blocks */
138
138
    while (pr->ptr + 16 <= limit) {
139
139
      aes_crypt_cbc(state->ctx, AES_DECRYPT, 16, state->iv,
140
 
                                pr->ptr + 1, temp);
 
140
                                pr->ptr + 1, temp);
141
141
      pr->ptr += 16;
142
142
      if (last && pr->ptr == pr->limit) {
143
143
        /* we're on the last block; unpad if necessary */