Fixed cms-test.pl for no-ec2m
[openssl.git] / test / cms-test.pl
1 # test/cms-test.pl
2 # Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 # project.
4 #
5 # ====================================================================
6 # Copyright (c) 2008 The OpenSSL Project.  All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # 1. Redistributions of source code must retain the above copyright
13 #    notice, this list of conditions and the following disclaimer.
14 #
15 # 2. Redistributions in binary form must reproduce the above copyright
16 #    notice, this list of conditions and the following disclaimer in
17 #    the documentation and/or other materials provided with the
18 #    distribution.
19 #
20 # 3. All advertising materials mentioning features or use of this
21 #    software must display the following acknowledgment:
22 #    "This product includes software developed by the OpenSSL Project
23 #    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 #
25 # 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 #    endorse or promote products derived from this software without
27 #    prior written permission. For written permission, please contact
28 #    licensing@OpenSSL.org.
29 #
30 # 5. Products derived from this software may not be called "OpenSSL"
31 #    nor may "OpenSSL" appear in their names without prior written
32 #    permission of the OpenSSL Project.
33 #
34 # 6. Redistributions of any form whatsoever must retain the following
35 #    acknowledgment:
36 #    "This product includes software developed by the OpenSSL Project
37 #    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 #
39 # THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 # OF THE POSSIBILITY OF SUCH DAMAGE.
51 # ====================================================================
52
53 # CMS, PKCS7 consistency test script. Run extensive tests on
54 # OpenSSL PKCS#7 and CMS implementations.
55
56 my $ossl_path;
57 my $redir = " 2> cms.err > cms.out";
58 # Make VMS work
59 if ( $^O eq "VMS" && -f "OSSLX:openssl.exe" ) {
60     $ossl_path = "pipe mcr OSSLX:openssl";
61     $null_path = "NL:";
62 }
63 # Make MSYS work
64 elsif ( $^O eq "MSWin32" && -f "../apps/openssl.exe" ) {
65     $ossl_path = "cmd /c ..\\apps\\openssl";
66     $null_path = "/dev/null";
67 }
68 elsif ( -f "../apps/openssl$ENV{EXE_EXT}" ) {
69     $ossl_path = "../util/shlib_wrap.sh ../apps/openssl";
70     $null_path = "/dev/null";
71 }
72 elsif ( -f "..\\out32dll\\openssl.exe" ) {
73     $ossl_path = "..\\out32dll\\openssl.exe";
74     $null_path = "/dev/null";
75 }
76 elsif ( -f "..\\out32\\openssl.exe" ) {
77     $ossl_path = "..\\out32\\openssl.exe";
78     $null_path = "/dev/null";
79 }
80 else {
81     die "Can't find OpenSSL executable";
82 }
83
84 my $pk7cmd   = "$ossl_path smime ";
85 my $cmscmd   = "$ossl_path cms ";
86 my $smdir    = "smime-certs";
87 my $halt_err = 1;
88
89 my $badcmd = 0;
90 my $no_ec;
91 my $no_ec2m;
92 my $ossl8 = `$ossl_path version -v` =~ /0\.9\.8/;
93
94 system ("$ossl_path no-ec > $null_path");
95 if ($? == 0)
96         {
97         $no_ec = 1;
98         }
99 elsif ($^O eq "VMS" ? $? == 512 : $? == 256)
100         {
101         $no_ec = 0;
102         }
103 else
104         {
105         die "Error checking for EC support\n";
106         }
107     
108 system ("$ossl_path no-ec2m >/dev/null");
109 if ($? == 0)
110         {
111         $no_ec2m = 1;
112         }
113 elsif ($? == 256)
114         {
115         $no_ec2m = 0;
116         }
117 else
118         {
119         die "Error checking for EC2M support\n";
120         }
121     
122 my @smime_pkcs7_tests = (
123
124     [
125         "signed content DER format, RSA key",
126         "-sign -in smcont.txt -outform \"DER\" -nodetach"
127           . " -certfile $smdir/smroot.pem"
128           . " -signer $smdir/smrsa1.pem -out test.cms",
129         "-verify -in test.cms -inform \"DER\" "
130           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
131     ],
132
133     [
134         "signed detached content DER format, RSA key",
135         "-sign -in smcont.txt -outform \"DER\""
136           . " -signer $smdir/smrsa1.pem -out test.cms",
137         "-verify -in test.cms -inform \"DER\" "
138           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
139     ],
140
141     [
142         "signed content test streaming BER format, RSA",
143         "-sign -in smcont.txt -outform \"DER\" -nodetach"
144           . " -stream -signer $smdir/smrsa1.pem -out test.cms",
145         "-verify -in test.cms -inform \"DER\" "
146           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
147     ],
148
149     [
150         "signed content DER format, DSA key",
151         "-sign -in smcont.txt -outform \"DER\" -nodetach"
152           . " -signer $smdir/smdsa1.pem -out test.cms",
153         "-verify -in test.cms -inform \"DER\" "
154           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
155     ],
156
157     [
158         "signed detached content DER format, DSA key",
159         "-sign -in smcont.txt -outform \"DER\""
160           . " -signer $smdir/smdsa1.pem -out test.cms",
161         "-verify -in test.cms -inform \"DER\" "
162           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
163     ],
164
165     [
166         "signed detached content DER format, add RSA signer",
167         "-resign -inform \"DER\" -in test.cms -outform \"DER\""
168           . " -signer $smdir/smrsa1.pem -out test2.cms",
169         "-verify -in test2.cms -inform \"DER\" "
170           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
171     ],
172
173     [
174         "signed content test streaming BER format, DSA key",
175         "-sign -in smcont.txt -outform \"DER\" -nodetach"
176           . " -stream -signer $smdir/smdsa1.pem -out test.cms",
177         "-verify -in test.cms -inform \"DER\" "
178           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
179     ],
180
181     [
182         "signed content test streaming BER format, 2 DSA and 2 RSA keys",
183         "-sign -in smcont.txt -outform \"DER\" -nodetach"
184           . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
185           . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
186           . " -stream -out test.cms",
187         "-verify -in test.cms -inform \"DER\" "
188           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
189     ],
190
191     [
192 "signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes",
193         "-sign -in smcont.txt -outform \"DER\" -noattr -nodetach"
194           . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
195           . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
196           . " -stream -out test.cms",
197         "-verify -in test.cms -inform \"DER\" "
198           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
199     ],
200
201     [
202         "signed content test streaming S/MIME format, 2 DSA and 2 RSA keys",
203         "-sign -in smcont.txt -nodetach"
204           . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
205           . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
206           . " -stream -out test.cms",
207         "-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
208     ],
209
210     [
211 "signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys",
212         "-sign -in smcont.txt"
213           . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
214           . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
215           . " -stream -out test.cms",
216         "-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
217     ],
218
219     [
220         "enveloped content test streaming S/MIME format, 3 recipients",
221         "-encrypt -in smcont.txt"
222           . " -stream -out test.cms"
223           . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
224         "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
225     ],
226
227     [
228 "enveloped content test streaming S/MIME format, 3 recipients, 3rd used",
229         "-encrypt -in smcont.txt"
230           . " -stream -out test.cms"
231           . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
232         "-decrypt -recip $smdir/smrsa3.pem -in test.cms -out smtst.txt"
233     ],
234
235     [
236 "enveloped content test streaming S/MIME format, 3 recipients, key only used",
237         "-encrypt -in smcont.txt"
238           . " -stream -out test.cms"
239           . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
240         "-decrypt -inkey $smdir/smrsa3.pem -in test.cms -out smtst.txt"
241     ],
242
243     [
244 "enveloped content test streaming S/MIME format, AES-256 cipher, 3 recipients",
245         "-encrypt -in smcont.txt"
246           . " -aes256 -stream -out test.cms"
247           . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
248         "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
249     ],
250
251 );
252
253 my @smime_cms_tests = (
254
255     [
256         "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid",
257         "-sign -in smcont.txt -outform \"DER\" -nodetach -keyid"
258           . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
259           . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
260           . " -stream -out test.cms",
261         "-verify -in test.cms -inform \"DER\" "
262           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
263     ],
264
265     [
266         "signed content test streaming PEM format, 2 DSA and 2 RSA keys",
267         "-sign -in smcont.txt -outform PEM -nodetach"
268           . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
269           . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
270           . " -stream -out test.cms",
271         "-verify -in test.cms -inform PEM "
272           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
273     ],
274
275     [
276         "signed content MIME format, RSA key, signed receipt request",
277         "-sign -in smcont.txt -signer $smdir/smrsa1.pem -nodetach"
278           . " -receipt_request_to test\@openssl.org -receipt_request_all"
279           . " -out test.cms",
280         "-verify -in test.cms "
281           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
282     ],
283
284     [
285         "signed receipt MIME format, RSA key",
286         "-sign_receipt -in test.cms"
287           . " -signer $smdir/smrsa2.pem"
288           . " -out test2.cms",
289         "-verify_receipt test2.cms -in test.cms"
290           . " \"-CAfile\" $smdir/smroot.pem"
291     ],
292
293     [
294         "enveloped content test streaming S/MIME format, 3 recipients, keyid",
295         "-encrypt -in smcont.txt"
296           . " -stream -out test.cms -keyid"
297           . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
298         "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
299     ],
300
301     [
302         "enveloped content test streaming PEM format, KEK",
303         "-encrypt -in smcont.txt -outform PEM -aes128"
304           . " -stream -out test.cms "
305           . " -secretkey 000102030405060708090A0B0C0D0E0F "
306           . " -secretkeyid C0FEE0",
307         "-decrypt -in test.cms -out smtst.txt -inform PEM"
308           . " -secretkey 000102030405060708090A0B0C0D0E0F "
309           . " -secretkeyid C0FEE0"
310     ],
311
312     [
313         "enveloped content test streaming PEM format, KEK, key only",
314         "-encrypt -in smcont.txt -outform PEM -aes128"
315           . " -stream -out test.cms "
316           . " -secretkey 000102030405060708090A0B0C0D0E0F "
317           . " -secretkeyid C0FEE0",
318         "-decrypt -in test.cms -out smtst.txt -inform PEM"
319           . " -secretkey 000102030405060708090A0B0C0D0E0F "
320     ],
321
322     [
323         "data content test streaming PEM format",
324         "-data_create -in smcont.txt -outform PEM -nodetach"
325           . " -stream -out test.cms",
326         "-data_out -in test.cms -inform PEM -out smtst.txt"
327     ],
328
329     [
330         "encrypted content test streaming PEM format, 128 bit RC2 key",
331         "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
332           . " -rc2 -secretkey 000102030405060708090A0B0C0D0E0F"
333           . " -stream -out test.cms",
334         "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
335           . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
336     ],
337
338     [
339         "encrypted content test streaming PEM format, 40 bit RC2 key",
340         "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
341           . " -rc2 -secretkey 0001020304"
342           . " -stream -out test.cms",
343         "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
344           . " -secretkey 0001020304 -out smtst.txt"
345     ],
346
347     [
348         "encrypted content test streaming PEM format, triple DES key",
349         "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
350           . " -des3 -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
351           . " -stream -out test.cms",
352         "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
353           . " -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
354           . " -out smtst.txt"
355     ],
356
357     [
358         "encrypted content test streaming PEM format, 128 bit AES key",
359         "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
360           . " -aes128 -secretkey 000102030405060708090A0B0C0D0E0F"
361           . " -stream -out test.cms",
362         "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
363           . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
364     ],
365
366 );
367
368 my @smime_cms_comp_tests = (
369
370     [
371         "compressed content test streaming PEM format",
372         "-compress -in smcont.txt -outform PEM -nodetach"
373           . " -stream -out test.cms",
374         "-uncompress -in test.cms -inform PEM -out smtst.txt"
375     ]
376
377 );
378
379 my @smime_cms_param_tests = (
380     [
381         "signed content test streaming PEM format, RSA keys, PSS signature",
382         "-sign -in smcont.txt -outform PEM -nodetach"
383           . " -signer $smdir/smrsa1.pem -keyopt rsa_padding_mode:pss"
384           . " -out test.cms",
385         "-verify -in test.cms -inform PEM "
386           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
387     ],
388
389     [
390         "signed content test streaming PEM format, RSA keys, PSS signature, no attributes",
391         "-sign -in smcont.txt -outform PEM -nodetach -noattr"
392           . " -signer $smdir/smrsa1.pem -keyopt rsa_padding_mode:pss"
393           . " -out test.cms",
394         "-verify -in test.cms -inform PEM "
395           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
396     ],
397
398     [
399         "signed content test streaming PEM format, RSA keys, PSS signature, SHA384 MGF1",
400         "-sign -in smcont.txt -outform PEM -nodetach"
401           . " -signer $smdir/smrsa1.pem -keyopt rsa_padding_mode:pss"
402           . " -keyopt rsa_mgf1_md:sha384 -out test.cms",
403         "-verify -in test.cms -inform PEM "
404           . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
405     ],
406
407     [
408 "enveloped content test streaming S/MIME format, OAEP default parameters",
409         "-encrypt -in smcont.txt"
410           . " -stream -out test.cms"
411           . " -recip $smdir/smrsa1.pem -keyopt rsa_padding_mode:oaep",
412         "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
413     ],
414
415     [
416 "enveloped content test streaming S/MIME format, OAEP SHA256",
417         "-encrypt -in smcont.txt"
418           . " -stream -out test.cms"
419           . " -recip $smdir/smrsa1.pem -keyopt rsa_padding_mode:oaep"
420           . " -keyopt rsa_oaep_md:sha256",
421         "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
422     ],
423
424     [
425 "enveloped content test streaming S/MIME format, ECDH",
426         "-encrypt -in smcont.txt"
427           . " -stream -out test.cms"
428           . " -recip $smdir/smec1.pem",
429         "-decrypt -recip $smdir/smec1.pem -in test.cms -out smtst.txt"
430     ],
431
432     [
433 "enveloped content test streaming S/MIME format, ECDH, AES128, SHA256 KDF",
434         "-encrypt -in smcont.txt"
435           . " -stream -out test.cms"
436           . " -recip $smdir/smec1.pem -aes128 -keyopt ecdh_kdf_md:sha256",
437         "-decrypt -recip $smdir/smec1.pem -in test.cms -out smtst.txt"
438     ],
439
440     [
441 "enveloped content test streaming S/MIME format, ECDH, K-283, cofactor DH",
442         "-encrypt -in smcont.txt"
443           . " -stream -out test.cms"
444           . " -recip $smdir/smec2.pem -aes128"
445           . " -keyopt ecdh_kdf_md:sha256 -keyopt ecdh_cofactor_mode:1",
446         "-decrypt -recip $smdir/smec2.pem -in test.cms -out smtst.txt"
447     ],
448
449     [
450 "enveloped content test streaming S/MIME format, X9.42 DH",
451         "-encrypt -in smcont.txt"
452           . " -stream -out test.cms"
453           . " -recip $smdir/smdh.pem -aes128",
454         "-decrypt -recip $smdir/smdh.pem -in test.cms -out smtst.txt"
455     ]
456 );
457
458 print "CMS => PKCS#7 compatibility tests\n";
459
460 run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $pk7cmd );
461
462 print "CMS <= PKCS#7 compatibility tests\n";
463
464 run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $pk7cmd, $cmscmd );
465
466 print "CMS <=> CMS consistency tests\n";
467
468 run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $cmscmd );
469 run_smime_tests( \$badcmd, \@smime_cms_tests,   $cmscmd, $cmscmd );
470
471 print "CMS <=> CMS consistency tests, modified key parameters\n";
472 run_smime_tests( \$badcmd, \@smime_cms_param_tests,   $cmscmd, $cmscmd );
473
474 if ( `$ossl_path version -f` =~ /ZLIB/ ) {
475     run_smime_tests( \$badcmd, \@smime_cms_comp_tests, $cmscmd, $cmscmd );
476 }
477 else {
478     print "Zlib not supported: compression tests skipped\n";
479 }
480
481 print "Running modified tests for OpenSSL 0.9.8 cms backport\n" if($ossl8);
482
483 if ($badcmd) {
484     print "$badcmd TESTS FAILED!!\n";
485 }
486 else {
487     print "ALL TESTS SUCCESSFUL.\n";
488 }
489
490 unlink "test.cms";
491 unlink "test2.cms";
492 unlink "smtst.txt";
493 unlink "cms.out";
494 unlink "cms.err";
495
496 sub run_smime_tests {
497     my ( $rv, $aref, $scmd, $vcmd ) = @_;
498
499     foreach $smtst (@$aref) {
500         my ( $tnam, $rscmd, $rvcmd ) = @$smtst;
501         if ($ossl8)
502                 {
503                 # Skip smime resign: 0.9.8 smime doesn't support -resign        
504                 next if ($scmd =~ /smime/ && $rscmd =~ /-resign/);
505                 # Disable streaming: option not supported in 0.9.8
506                 $tnam =~ s/streaming//; 
507                 $rscmd =~ s/-stream//;  
508                 $rvcmd =~ s/-stream//;
509                 }
510         if ($no_ec && $tnam =~ /ECDH/)
511                 {
512                 print "$tnam: skipped, EC disabled\n";
513                 next;
514                 }
515         if ($no_ec2m && $tnam =~ /K-283/)
516                 {
517                 print "$tnam: skipped, EC2M disabled\n";
518                 next;
519                 }
520         system("$scmd$rscmd$redir");
521         if ($?) {
522             print "$tnam: generation error\n";
523             $$rv++;
524             exit 1 if $halt_err;
525             next;
526         }
527         system("$vcmd$rvcmd$redir");
528         if ($?) {
529             print "$tnam: verify error\n";
530             $$rv++;
531             exit 1 if $halt_err;
532             next;
533         }
534         if (!cmp_files("smtst.txt", "smcont.txt")) {
535             print "$tnam: content verify error\n";
536             $$rv++;
537             exit 1 if $halt_err;
538             next;
539         }
540         print "$tnam: OK\n";
541     }
542 }
543
544 sub cmp_files {
545     use FileHandle;
546     my ( $f1, $f2 ) = @_;
547     my $fp1 = FileHandle->new();
548     my $fp2 = FileHandle->new();
549
550     my ( $rd1, $rd2 );
551
552     if ( !open( $fp1, "<$f1" ) ) {
553         print STDERR "Can't Open file $f1\n";
554         return 0;
555     }
556
557     if ( !open( $fp2, "<$f2" ) ) {
558         print STDERR "Can't Open file $f2\n";
559         return 0;
560     }
561
562     binmode $fp1;
563     binmode $fp2;
564
565     my $ret = 0;
566
567     for ( ; ; ) {
568         $n1 = sysread $fp1, $rd1, 4096;
569         $n2 = sysread $fp2, $rd2, 4096;
570         last if ( $n1 != $n2 );
571         last if ( $rd1 ne $rd2 );
572
573         if ( $n1 == 0 ) {
574             $ret = 1;
575             last;
576         }
577
578     }
579
580     close $fp1;
581     close $fp2;
582
583     return $ret;
584
585 }
586