MD5 checksum in COBOL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Date: Mon, 11 Sep 2017 13:48:24 +0000
> From: Kevin Lyda <kevin@xxxxxxxxxxxxxx>

> Hi there. New to COBOL, please excuse overly stupid questions.

Hello Kevin, you're welcome. Thank you for your mail as this highlights
some issues where we can improve the compiler.

> I came across an example version of an MD5 checksum generator written
> entirely in COBOL[1]. However I note that it's written in Micro Focus
> format - which I take it is one dialect of COBOL. So, using the 2.2 release
> of GNU COBOL I ran the following:
> 
> tr -d '\r' < cobmd5.cbl > cobmd5-2.cbl
> sed -i 's/^\*/*>/g' cobmd5-2.cbl
> cobc -std=mf -free -x -o cobmd5 cobmd5-2.cbl
> 
> The tr and sed commands are to change the source from DOS line-endings to
> Unix ones and to change the bare "*" comments to "*>" comments (I'm
> guessing an unsupported MF COBOL extension?).

Note: These commands should normally not be needed.

First: Line ending --> no issue (if you encounter one, please post)

Second: * in column 1 as comment --> works if you explicit add -fmfcomment
Note: it should also work if `-std=mf` is used (as it should imply this
setting, which it currently doesn't). This is tracked with FR #230.

But this won't help here as the source should not compile with MF
according to their docs (if anyone on this list has a MF compiler:
please recheck, the source should only work if you add an additional
      $set mfcomment [does it?]).

The reason: In this case the source has the MF compiler directive $SET
sourceformat"free". And their docs [2] state that this implies the
setting of NOMFCOMMENT [3]. If no further options are set this is what
GnuCOBOL does (but resetting the option by compiler directive would
currently not work).

Therefore you need to change all * after line 8 to *>, even if you add
-fmfcomment - your sed is reasonable (I actually did the same).

> And I get the following:
>
> cobmd5-2.cbl: 158: warning: REDEFINES clause should follow entry-name
> cobmd5-2.cbl: 165: warning: REDEFINES clause should follow entry-name
> cobmd5-2.cbl: 178: warning: REDEFINES clause should follow entry-name
> cobmd5-2.cbl: 190: warning: REDEFINES clause should follow entry-name
> cobmd5-2.cbl: 298: warning: REDEFINES clause should follow entry-name

The "REDEFINES clause should follow entry-name" is only a warning (but
it actually should raise no warning, this one is tracked with FR #211.

> cobmd5-2.cbl: 144: error: only level 88 items may have multiple values

This one is a missing extension (MF does not mark this as extension [4]
but as it isn't part of ISO2002 or IBM or ACU I'm quite sure this isn't
allowed in ANSI85 either).
It wasn't tracked alread, I've just created FR #234 for this.
Thank you for reporting!

The current code

    03  ROL-PowersOf2                   pic x(4) comp-5 sync
                                        occurs 31
                                        value 2 4 8 16 32 64 128 256
                                              512 1024 2048 4096 8192
                                              16384 32768 65536 131072
                                              262144 524288 1048576
                                              2097152 4194304 8388608
                                              16777216 33554432 67108864
                                              134217728 268435456
                                              536870912 1073741824
                                              2147483648.

will not work until this is implemented, you need to change it to

    03  ROL-PowersOf2-vals.
        05 filler                       pic x(4) comp-5 sync value 2.
        05 filler                       pic x(4) comp-5 sync value 4.
        05 filler                       pic x(4) comp-5 sync value 8.
        05 filler                       pic x(4) comp-5 sync value 16.
        05 filler                       pic x(4) comp-5 sync value 32.
        05 filler                       pic x(4) comp-5 sync value 64.
        05 filler                       pic x(4) comp-5 sync value 128.
        05 filler                       pic x(4) comp-5 sync value 256.
        05 filler                       pic x(4) comp-5 sync value 512.
        05 filler                       pic x(4) comp-5 sync value 1024.
        05 filler                       pic x(4) comp-5 sync value 2048.
        05 filler                       pic x(4) comp-5 sync value 4096.
        05 filler                       pic x(4) comp-5 sync value 8192.
        05 filler                       pic x(4) comp-5 sync
                                             value 16384.
        05 filler                       pic x(4) comp-5 sync
                                             value 32768.
        05 filler                       pic x(4) comp-5 sync
                                             value 65536.
        05 filler                       pic x(4) comp-5 sync
                                              value 131072.
        05 filler                       pic x(4) comp-5 sync
                                              value 262144.
        05 filler                       pic x(4) comp-5 sync
                                              value 524288.
        05 filler                       pic x(4) comp-5 sync
                                              value 1048576.
        05 filler                       pic x(4) comp-5 sync
                                              value 2097152.
        05 filler                       pic x(4) comp-5 sync
                                              value 4194304.
        05 filler                       pic x(4) comp-5 sync
                                              value 8388608.
        05 filler                       pic x(4) comp-5 sync
                                              value 16777216.
        05 filler                       pic x(4) comp-5 sync
                                              value 33554432.
        05 filler                       pic x(4) comp-5 sync
                                              value 67108864.
        05 filler                       pic x(4) comp-5 sync
                                              value 134217728.
        05 filler                       pic x(4) comp-5 sync
                                              value 268435456.
        05 filler                       pic x(4) comp-5 sync
                                              value 536870912.
        05 filler                       pic x(4) comp-5 sync
                                              value 1073741824.
        05 filler                       pic x(4) comp-5 sync
                                              value 2147483648.
    03  filler redefines ROL-PowersOf2-vals.
        05  ROL-PowersOf2               pic x(4) comp-5 sync
                                        occurs 31.

> cobmd5-2.cbl: in section 'MD5-F':
> cobmd5-2.cbl: 413: error: 'b-and' is a reserved word, but isn't supported
> cobmd5-2.cbl: 413: error: syntax error, unexpected Identifier, expecting )
> or - or +
> cobmd5-2.cbl: 413: error: 'b-or' is a reserved word, but isn't supported
> cobmd5-2.cbl: 413: error: 'b-not' is a reserved word, but isn't supported
> cobmd5-2.cbl: 413: error: 'b-and' is a reserved word, but isn't supported
> cobmd5-2.cbl: in section 'MD5-G':
> cobmd5-2.cbl: 418: error: 'b-and' is a reserved word, but isn't supported
> cobmd5-2.cbl: 418: error: syntax error, unexpected Identifier, expecting )
> or - or +
> cobmd5-2.cbl: 418: error: 'b-or' is a reserved word, but isn't supported
> cobmd5-2.cbl: 418: error: 'b-and' is a reserved word, but isn't supported
> cobmd5-2.cbl: 418: error: 'b-not' is a reserved word, but isn't supported
> cobmd5-2.cbl: in section 'MD5-H':
> cobmd5-2.cbl: 423: error: 'b-xor' is a reserved word, but isn't supported
> cobmd5-2.cbl: 423: error: syntax error, unexpected Identifier, expecting )
> or - or +
> cobmd5-2.cbl: 423: error: 'b-xor' is a reserved word, but isn't supported
> cobmd5-2.cbl: in section 'MD5-I':
> cobmd5-2.cbl: 428: error: 'b-xor' is a reserved word, but isn't supported
> cobmd5-2.cbl: 428: error: syntax error, unexpected Identifier
> cobmd5-2.cbl: 428: error: 'b-or' is a reserved word, but isn't supported
> cobmd5-2.cbl: 428: error: 'b-not' is a reserved word, but isn't supported
> 
> Some of these seem like syntax MF COBOL supports that GNU COBOL doesn't -
> the redefines and the syntax errors. The others seem like
> functions/operators MF COBOL supports that GNU COBOL doesn't.

All others were handled already but the last one stays open:
boolean operations on *numerical* items/literals.
I've added FR #235 for this one. Note: ISO2002 added bitwise operators,
too - but only on boolean data items/literals.

As a workaround you could use the system libraries `CBL_AND`, `CBL_OR`,
... instead. See MF docs [5]

> Are there any good guides on porting MF COBOL to GNU COBOL? Suggestions for
> things I should read?

In general this should be not too big issue and you'll learn a little
bit COBOL on the way ;-)

Concerning the sample the readme says nearly all:

> Note, however, that this is unsupported sample code.  
> 
> Note also that this program is written using MF COBOL extensions and 
> is not portable COBOL.

You likely won't have much bitwise operations in production code.

Note: I've posted a running but not working changed program to the
discussion boards [6], just in case you want to check approaches from
others or have a look at the changed version.

If you see issues in sources where the notes above don't help I suggest
to to check the discussion boards for answers (and post a new question
for everything you haven't found an answer) - the discussion boards are
more frequently used and have the benefit of easier search of old posts.

> 
> [1]:
> https://community.microfocus.com/microfocus/cobol/net_express__server_express/w/knowledge_base/2761/demo-how-to-create-an-md5-hash

[2]:
http://documentation.microfocus.com:8080/help/topic/com.microfocus.eclipse.infocenter.enterprisedeveloper.vs2012/HRCDRHCDIR63.html
[3]:
http://documentation.microfocus.com:8080/help/topic/com.microfocus.eclipse.infocenter.enterprisedeveloper.vs2012/HRCDRHCDIR4F.html?cp=3_2_4_3_1_3_10
[4]:http://documentation.microfocus.com:8080/help/topic/com.microfocus.eclipse.infocenter.enterprisedeveloper.vs2012/HRLHLHPDF40R.html?cp=3_2_4_1_3_3_8_1_16
[5]:http://documentation.microfocus.com:8080/help/topic/com.microfocus.eclipse.infocenter.enterprisedeveloper.vs2017/HRCLRHCALL0E.html
[6]:https://sourceforge.net/p/open-cobol/discussion/cobol/thread/e629731a/




[Index of Archives]     [Gcc Help]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Info]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux