Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 156947 | Differences between
and this patch

Collapse All | Expand All

(-)encr-data.c.orig (-30 / +63 lines)
Lines 44-50 typedef struct { Link Here
44
    char defer[20];
44
    char defer[20];
45
    int  defer_filled;
45
    int  defer_filled;
46
    int  eof_seen;
46
    int  eof_seen;
47
} decode_filter_ctx_t;
47
    int  refcount;
48
} *decode_filter_ctx_t;
49
50
51
/* Helper to release the decode context.  */
52
static void
53
release_dfx_context (decode_filter_ctx_t dfx)
54
{
55
  if (!dfx)
56
    return;
57
58
  assert (dfx->refcount);
59
  if ( !--dfx->refcount )
60
    {
61
      cipher_close (dfx->cipher_hd);
62
      dfx->cipher_hd = NULL;
63
      md_close (dfx->mdc_hash);
64
      dfx->mdc_hash = NULL;
65
      xfree (dfx);
66
    }
67
}
48
68
49
69
50
/****************
70
/****************
Lines 60-66 decrypt_data( void *procctx, PKT_encrypt Link Here
60
    unsigned blocksize;
80
    unsigned blocksize;
61
    unsigned nprefix;
81
    unsigned nprefix;
62
82
63
    memset( &dfx, 0, sizeof dfx );
83
84
    dfx = xcalloc (1, sizeof *dfx);
85
    dfx->refcount = 1;
86
64
    if( opt.verbose && !dek->algo_info_printed ) {
87
    if( opt.verbose && !dek->algo_info_printed ) {
65
	const char *s = cipher_algo_to_string( dek->algo );
88
	const char *s = cipher_algo_to_string( dek->algo );
66
	if( s )
89
	if( s )
Lines 79-93 decrypt_data( void *procctx, PKT_encrypt Link Here
79
	BUG();
102
	BUG();
80
103
81
    if( ed->mdc_method ) {
104
    if( ed->mdc_method ) {
82
	dfx.mdc_hash = md_open( ed->mdc_method, 0 );
105
	dfx->mdc_hash = md_open ( ed->mdc_method, 0 );
83
	if ( DBG_HASHING )
106
	if ( DBG_HASHING )
84
	    md_start_debug(dfx.mdc_hash, "checkmdc");
107
	    md_start_debug (dfx->mdc_hash, "checkmdc");
85
    }
108
    }
86
    dfx.cipher_hd = cipher_open( dek->algo,
109
    dfx->cipher_hd = cipher_open ( dek->algo,
87
				 ed->mdc_method? CIPHER_MODE_CFB
110
                                   ed->mdc_method? CIPHER_MODE_CFB
88
					       : CIPHER_MODE_AUTO_CFB, 1 );
111
                                                 : CIPHER_MODE_AUTO_CFB, 1 );
89
    /* log_hexdump( "thekey", dek->key, dek->keylen );*/
112
    /* log_hexdump( "thekey", dek->key, dek->keylen );*/
90
    rc = cipher_setkey( dfx.cipher_hd, dek->key, dek->keylen );
113
    rc = cipher_setkey ( dfx->cipher_hd, dek->key, dek->keylen );
91
    if( rc == G10ERR_WEAK_KEY )
114
    if( rc == G10ERR_WEAK_KEY )
92
      {
115
      {
93
	log_info(_("WARNING: message was encrypted with"
116
	log_info(_("WARNING: message was encrypted with"
Lines 105-111 decrypt_data( void *procctx, PKT_encrypt Link Here
105
        goto leave;
128
        goto leave;
106
    }
129
    }
107
130
108
    cipher_setiv( dfx.cipher_hd, NULL, 0 );
131
    cipher_setiv ( dfx->cipher_hd, NULL, 0 );
109
132
110
    if( ed->len ) {
133
    if( ed->len ) {
111
	for(i=0; i < (nprefix+2) && ed->len; i++, ed->len-- ) {
134
	for(i=0; i < (nprefix+2) && ed->len; i++, ed->len-- ) {
Lines 122-129 decrypt_data( void *procctx, PKT_encrypt Link Here
122
	    else
145
	    else
123
		temp[i] = c;
146
		temp[i] = c;
124
    }
147
    }
125
    cipher_decrypt( dfx.cipher_hd, temp, temp, nprefix+2);
148
    cipher_decrypt ( dfx->cipher_hd, temp, temp, nprefix+2);
126
    cipher_sync( dfx.cipher_hd );
149
    cipher_sync ( dfx->cipher_hd );
127
    p = temp;
150
    p = temp;
128
/* log_hexdump( "prefix", temp, nprefix+2 ); */
151
/* log_hexdump( "prefix", temp, nprefix+2 ); */
129
    if(dek->symmetric
152
    if(dek->symmetric
Lines 133-166 decrypt_data( void *procctx, PKT_encrypt Link Here
133
	goto leave;
156
	goto leave;
134
      }
157
      }
135
158
136
    if( dfx.mdc_hash )
159
    if ( dfx->mdc_hash )
137
	md_write( dfx.mdc_hash, temp, nprefix+2 );
160
	md_write ( dfx->mdc_hash, temp, nprefix+2 );
138
161
139
    if( ed->mdc_method )
162
    dfx->refcount++;
140
	iobuf_push_filter( ed->buf, mdc_decode_filter, &dfx );
163
    if ( ed->mdc_method )
164
	iobuf_push_filter( ed->buf, mdc_decode_filter, dfx );
141
    else
165
    else
142
	iobuf_push_filter( ed->buf, decode_filter, &dfx );
166
	iobuf_push_filter( ed->buf, decode_filter, dfx );
143
167
144
    proc_packets( procctx, ed->buf );
168
    proc_packets( procctx, ed->buf );
145
    ed->buf = NULL;
169
    ed->buf = NULL;
146
    if( ed->mdc_method && dfx.eof_seen == 2 )
170
    if( ed->mdc_method && dfx->eof_seen == 2 )
147
	rc = G10ERR_INVALID_PACKET;
171
	rc = G10ERR_INVALID_PACKET;
148
    else if( ed->mdc_method ) { /* check the mdc */
172
    else if( ed->mdc_method ) { /* check the mdc */
149
	int datalen = md_digest_length( ed->mdc_method );
173
	int datalen = md_digest_length( ed->mdc_method );
150
174
151
	cipher_decrypt( dfx.cipher_hd, dfx.defer, dfx.defer, 20);
175
	cipher_decrypt ( dfx->cipher_hd, dfx->defer, dfx->defer, 20);
152
	md_final( dfx.mdc_hash );
176
	md_final ( dfx->mdc_hash );
153
	if( datalen != 20
177
	if( datalen != 20
154
	    || memcmp(md_read( dfx.mdc_hash, 0 ), dfx.defer, datalen) )
178
	    || memcmp(md_read( dfx->mdc_hash, 0 ), dfx->defer, datalen) )
155
	    rc = G10ERR_BAD_SIGN;
179
	    rc = G10ERR_BAD_SIGN;
156
	/*log_hexdump("MDC calculated:", md_read( dfx.mdc_hash, 0), datalen);*/
180
	/*log_hexdump("MDC calculated:",md_read( dfx->mdc_hash, 0), datalen);*/
157
	/*log_hexdump("MDC message   :", dfx.defer, 20);*/
181
	/*log_hexdump("MDC message   :", dfx->defer, 20);*/
158
    }
182
    }
159
    
183
    
160
184
161
  leave:
185
  leave:
162
    cipher_close(dfx.cipher_hd);
186
    release_dfx_context (dfx);
163
    md_close( dfx.mdc_hash );
164
    return rc;
187
    return rc;
165
}
188
}
166
189
Lines 171-177 static int Link Here
171
mdc_decode_filter( void *opaque, int control, IOBUF a,
194
mdc_decode_filter( void *opaque, int control, IOBUF a,
172
					      byte *buf, size_t *ret_len)
195
					      byte *buf, size_t *ret_len)
173
{
196
{
174
    decode_filter_ctx_t *dfx = opaque;
197
    decode_filter_ctx_t dfx = opaque;
175
    size_t n, size = *ret_len;
198
    size_t n, size = *ret_len;
176
    int rc = 0;
199
    int rc = 0;
177
    int c;
200
    int c;
Lines 226-233 mdc_decode_filter( void *opaque, int con Link Here
226
	}
249
	}
227
250
228
	if( n ) {
251
	if( n ) {
229
	    cipher_decrypt( dfx->cipher_hd, buf, buf, n);
252
            if (dfx->cipher_hd)
230
	    md_write( dfx->mdc_hash, buf, n );
253
                cipher_decrypt( dfx->cipher_hd, buf, buf, n);
254
            if (dfx->mdc_hash)
255
                md_write( dfx->mdc_hash, buf, n );
231
	}
256
	}
232
	else {
257
	else {
233
	    assert( dfx->eof_seen );
258
	    assert( dfx->eof_seen );
Lines 235-240 mdc_decode_filter( void *opaque, int con Link Here
235
	}
260
	}
236
	*ret_len = n;
261
	*ret_len = n;
237
    }
262
    }
263
    else if ( control == IOBUFCTRL_FREE ) {
264
        release_dfx_context (dfx);
265
    }
238
    else if( control == IOBUFCTRL_DESC ) {
266
    else if( control == IOBUFCTRL_DESC ) {
239
	*(char**)buf = "mdc_decode_filter";
267
	*(char**)buf = "mdc_decode_filter";
240
    }
268
    }
Lines 244-250 mdc_decode_filter( void *opaque, int con Link Here
244
static int
272
static int
245
decode_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len)
273
decode_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len)
246
{
274
{
247
    decode_filter_ctx_t *fc = opaque;
275
    decode_filter_ctx_t fc = opaque;
248
    size_t n, size = *ret_len;
276
    size_t n, size = *ret_len;
249
    int rc = 0;
277
    int rc = 0;
250
278
Lines 252-263 decode_filter( void *opaque, int control Link Here
252
	assert(a);
280
	assert(a);
253
	n = iobuf_read( a, buf, size );
281
	n = iobuf_read( a, buf, size );
254
	if( n == -1 ) n = 0;
282
	if( n == -1 ) n = 0;
255
	if( n )
283
	if( n ) {
256
	    cipher_decrypt( fc->cipher_hd, buf, buf, n);
284
            if (fc->cipher_hd)
285
                cipher_decrypt( fc->cipher_hd, buf, buf, n);
286
        }
257
	else
287
	else
258
	    rc = -1; /* eof */
288
	    rc = -1; /* eof */
259
	*ret_len = n;
289
	*ret_len = n;
260
    }
290
    }
291
    else if ( control == IOBUFCTRL_FREE ) {
292
        release_dfx_context (fc);
293
    }
261
    else if( control == IOBUFCTRL_DESC ) {
294
    else if( control == IOBUFCTRL_DESC ) {
262
	*(char**)buf = "decode_filter";
295
	*(char**)buf = "decode_filter";
263
    }
296
    }

Return to bug 156947