~ubuntu-branches/ubuntu/maverick/openssl/maverick

« back to all changes in this revision

Viewing changes to crypto/evp/evp_test.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Martin
  • Date: 2004-12-16 18:41:29 UTC
  • mto: (11.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20041216184129-z7xjkul57mh1jiha
Tags: upstream-0.9.7e
ImportĀ upstreamĀ versionĀ 0.9.7e

Show diffs side-by-side

added added

removed removed

Lines of Context:
136
136
                  const unsigned char *iv,int in,
137
137
                  const unsigned char *plaintext,int pn,
138
138
                  const unsigned char *ciphertext,int cn,
139
 
                  int encdec)
 
139
                  int encdec,int multiplier)
140
140
    {
141
141
    EVP_CIPHER_CTX ctx;
142
142
    unsigned char out[4096];
162
162
        if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv))
163
163
            {
164
164
            fprintf(stderr,"EncryptInit failed\n");
 
165
            ERR_print_errors_fp(stderr);
165
166
            test1_exit(10);
166
167
            }
167
168
        EVP_CIPHER_CTX_set_padding(&ctx,0);
168
169
 
169
 
        if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn))
 
170
        if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn*multiplier))
170
171
            {
171
172
            fprintf(stderr,"Encrypt failed\n");
 
173
            ERR_print_errors_fp(stderr);
172
174
            test1_exit(6);
173
175
            }
174
176
        if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2))
175
177
            {
176
178
            fprintf(stderr,"EncryptFinal failed\n");
 
179
            ERR_print_errors_fp(stderr);
177
180
            test1_exit(7);
178
181
            }
179
182
 
180
 
        if(outl+outl2 != cn)
 
183
        if(outl+outl2 != cn*multiplier)
181
184
            {
182
185
            fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n",
183
186
                    outl+outl2,cn);
198
201
        if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv))
199
202
            {
200
203
            fprintf(stderr,"DecryptInit failed\n");
 
204
            ERR_print_errors_fp(stderr);
201
205
            test1_exit(11);
202
206
            }
203
207
        EVP_CIPHER_CTX_set_padding(&ctx,0);
204
208
 
205
 
        if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn))
 
209
        if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn*multiplier))
206
210
            {
207
211
            fprintf(stderr,"Decrypt failed\n");
 
212
            ERR_print_errors_fp(stderr);
208
213
            test1_exit(6);
209
214
            }
210
215
        if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2))
211
216
            {
212
217
            fprintf(stderr,"DecryptFinal failed\n");
 
218
            ERR_print_errors_fp(stderr);
213
219
            test1_exit(7);
214
220
            }
215
221
 
216
 
        if(outl+outl2 != cn)
 
222
        if(outl+outl2 != cn*multiplier)
217
223
            {
218
224
            fprintf(stderr,"Plaintext length mismatch got %d expected %d\n",
219
225
                    outl+outl2,cn);
238
244
                       const unsigned char *iv,int in,
239
245
                       const unsigned char *plaintext,int pn,
240
246
                       const unsigned char *ciphertext,int cn,
241
 
                       int encdec)
 
247
                       int encdec,int multiplier)
242
248
    {
243
249
    const EVP_CIPHER *c;
244
250
 
246
252
    if(!c)
247
253
        return 0;
248
254
 
249
 
    test1(c,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec);
 
255
    test1(c,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec,multiplier);
250
256
 
251
257
    return 1;
252
258
    }
272
278
    if(!EVP_DigestInit_ex(&ctx,d, NULL))
273
279
        {
274
280
        fprintf(stderr,"DigestInit failed\n");
 
281
        ERR_print_errors_fp(stderr);
275
282
        EXIT(100);
276
283
        }
277
284
    if(!EVP_DigestUpdate(&ctx,plaintext,pn))
278
285
        {
279
286
        fprintf(stderr,"DigestUpdate failed\n");
 
287
        ERR_print_errors_fp(stderr);
280
288
        EXIT(101);
281
289
        }
282
290
    if(!EVP_DigestFinal_ex(&ctx,md,&mdn))
283
291
        {
284
292
        fprintf(stderr,"DigestFinal failed\n");
 
293
        ERR_print_errors_fp(stderr);
285
294
        EXIT(101);
286
295
        }
287
296
    EVP_MD_CTX_cleanup(&ctx);
359
368
        unsigned char *iv,*key,*plaintext,*ciphertext;
360
369
        int encdec;
361
370
        int kn,in,pn,cn;
 
371
        int multiplier=1;
362
372
 
363
373
        if(!fgets((char *)line,sizeof line,f))
364
374
            break;
383
393
        pn=convert(plaintext);
384
394
        cn=convert(ciphertext);
385
395
 
386
 
        if(!test_cipher(cipher,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec)
 
396
        if(strchr(cipher,'*'))
 
397
            {
 
398
            p=cipher;
 
399
            sstrsep(&p,"*");
 
400
            multiplier=atoi(sstrsep(&p,"*"));
 
401
            }
 
402
 
 
403
        if(!test_cipher(cipher,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec,
 
404
                        multiplier)
387
405
           && !test_digest(cipher,plaintext,pn,ciphertext,cn))
388
406
            {
389
407
            fprintf(stderr,"Can't find %s\n",cipher);