Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Asynchronous execution - example

&pagelevel(4)&pagelevel

CRYPT uses the following macros in the sample program section below:

  1. The CPKC11T macro contains data descriptions and equates that are used by the following macros.

  2. The CGENRAL macro implements asynchronous processing for the task with CRYPT.

  3. The event identification CRYPTTST is defined. The address of the short ID is OUTEIID.

  4. The CRY2ABC routine is defined as a contingency process:
    CONTAAD specifies the start address.
    OUTCOID specifies the address of the short ID.

  5. The program requests a signal from the event identification CRYPTTST using a SOLSIG call and specifies the contingency process CRY2ABC. If the signal has not yet arrived after 600 seconds the event control should start the contingency process CRY2ABC. The program continues to run after this SOLSIG call.

  6. The CSESION macro opens a session between an application and a token in a certain slot using the *OPENSESSION action.

  7. The CGENKEY macro generates a secret DES key.

  8. The *ENCRYPTINIT action of the CCRYINI macro then initiates an encryption operation with the DES key created.

  9. The *ENCRYPT action of the CCRY macro performs the encryption operation

  10. Routine CRY2ABC which acts as a contingency process.

  11. The program once again requests a signal with a SOLSIG call.

  12. A check is carried out to determine whether an CRYPT event has occurred.

  13. Follow-up processing takes place depending on the event that has occurred.

You can find information about eventing and the contingency process in the “Executive Macros” user guide [3].
FHDR  MF=D
TITLE 'CPKC11T layout'  --------------------------------------------(1.)
CPKC11T MF=D
TITLE 'CSESION'
CSESION MF=D,VERSION=002
TITLE 'CCRY'
CCRY  MF=D,VERSION=002
TITLE 'CGENKEY'
CGENKEY MF=D,VERSION=002
TITLE 'CRY2ABS - example'
*
AREA     DSECT
OUTEIID  DS    F
OUTCOID  DS    F
AREA#    EQU   *-AREA
*
CRY2AB   CSECT
CRY2AB   AMODE ANY
CRY2AB   RMODE ANY
*
         ENTRY CRY2ABV
CRY2ABV  DS    0D
         DS    XL(AREA#) 
*
SPACE
CRY2ABS  @ENTR TYP=M,ENV=SPLSPEC,FUNCT='example of crypt ass program', -
               LOCAL=ZEXALOC
CRY2ABS  AMODE ANY
CRY2ABS  RMODE ANY
*
         L     R9,=V(CRY2ABV)
         @DATA BASE=R9,CLASS=B,DSECT=AREA
*
         LA    R3,CGENRALC
         MVC   CGENRALC,CGENRALL
         @DATA BASE=R3,CLASS=B,DSECT=CRYJHEADER
         MVI   CRYJACTION,CRYJINITIALIZE
         MVI   CRYJEXEC,CRYJASYNCHRON
CGENRALE CGENRAL MF=E,PARAM=(R3),CALLER=USER  -----------------------(2.)
*
         @IF   ZE
         CLC   CRYJRET,=F'0'
         @THEN , INIT ok
*
         @ELSE , error
* error handling 
         B     EXIT
         @BEND , INIT ok/error
*
         LA    R2,OUTEIID
         ENAEI EINAME=CRYPTTST,EIIDRET=(R2),PARMOD=31  --------------(3.)
         ST    R15,ENAEIRC
         @IF   EQ
* ok?
         CLI   ENAEIMC,X'00'
         @THEN , event item created
*
         @ELSE , event item not created
* error handling 
         B     EXIT
         @BEND , event item (not) created
*
         LA    R2,OUTCOID
         ENACO CONAME=CRYPTST,COADAD=CONTAAD,COIDRET=(R2),PARMOD=31  (4.)
         ST    R15,ENACORC
         @IF   EQ
* ok?
         CLI   ENACOMC,X'00'
         @THEN , contingency created
*
         @ELSE , contingency not created
* error handling 
         B     EXIT
         @BEND , contingency (not) created
*
         LA    R4,OUTCOID
         LA    R2,OUTEIID
         SOLSIG EIID=(R2),COID=(R4),LIFETIM=600,PARMOD=31  ----------(5.)
*
         @IF   NZ
*   SOLSIG ok?
         LTR   R15,R15
         @THEN , error
* error handling 
         B     EXIT
         @BEND , error
*
* REQM for openSession PA
         REQM  1,PARMOD=31
         @IF   NZ
         LTR   R15,R15
         @THEN , error
* error handling 
         B     EXIT
         @BEND , error
*
         LR    R6,R1
         @DATA BASE=R6,CLASS=B,DSECT=CRYO_MDL 
*
* set up CSESION call
         MVC   CRYOHEADER(CRYO#),CSESIONL
         MVI   CRYOACTION,CRYOOPENSESSION
         MVC   CRYOBOID,OUTEIID
         LA    R1,OPSTKEY1
         ST    R1,CRYORPOSTAD
         ST    R6,OPSTKEY2
         MVC   CRYORPOSTL,=F'2'
         CSESION MF=E,PARAM=(R6),CALLER=USER  -----------------------(6.)
*
         @IF   EQ
         CLC   CRYORET,=F'0'
         @THEN , open session accepted
*
*  wait for the completion of openSession
*
         @ELSE , open session not accepted
* error handling 
         B     EXIT
         @BEND , open session (not) accepted
*
*
* REQM for genKey PA
         REQM  1,PARMOD=31
         @IF   NZ
         LTR   R15,R15
         @THEN , error
* error handling 
         B     EXIT
         @BEND , error
*
         LR    R7,R1
         @DATA BASE=R7,CLASS=B,DSECT=CRYDHEADER
*
         MVC   CRYDHEADER(CRYD#),CGENKEYL
         MVC   CRYDSESSION,CRYOSESSION
         MVC   CRYDMECHANISM,=A(MDESKGEN)
         MVC   CRYDBOID,OUTEIID
         LA    R1,DPSTKEY1
         ST    R1,CRYDRPOSTAD
         ST    R7,DPSTKEY2
         MVC   CRYDRPOSTL,=F'2'
         CGENKEY MF=E,PARAM=(R7),CALLER=USER  -----------------------(7.)
         @IF   EQ
         CLC   CRYDRET,=F'0'
         @THEN , generate key accepted
*
*  wait for the completion of generate key
*
         @ELSE , generate key not accepted
* error handling 
         B     EXIT
         @BEND , generate key (not) accepted
*
*
* set up encrypt CCRYINI call
         MVC   CCRYINIC,CCRYINIL
         LA    R8,CCRYINIC
         @DATA BASE=R8,CLASS=B,DSECT=CRYAHEADER
         MVI   CRYAACTION,CRYAENCRYPTINIT
         MVC   CRYASESSION,CRYOSESSION
         MVC   CRYAKEY,CRYDKEY
         MVC   CRYAMECHANISM,=A(MDESECB)
*
         CCRYINI MF=E,PARAM=(R8),CALLER=USER  -----------------------(8.)
*
         @IF   EQ
         CLC   CRYARET,=F'0'
         @THEN , encrypt init ok
*
         @ELSE , encrypt init not ok
* error handling 
         B     EXIT
         @BEND , encrypt init (not) ok
*
* REQM for encrypt PA
         REQM  1,PARMOD=31
         @IF   NZ
         LTR   R15,R15
         @THEN , error
* error handling 
         B     EXIT
         @BEND , error
*
         LR    R8,R1
         @DATA BASE=R8,CLASS=B,DSECT=CRYB_MDL
*
         MVC   CRYBHEADER(CRYB#),CCRYL
         MVC   CRYBSESSION,CRYOSESSION
         MVI   CRYBACTION,CRYBENCRYPT
         MVC   CRYBDATAIN,=A(ZINPUT)
         MVC   CRYBDATAINLEN,=A(L'ZINPUT)
         LA    R15,ZENCOUT
         ST    R15,CRYBDATAOUT
         MVC   CRYBDATAOUTLEN,=A(L'ZENCOUT)
         MVC   CRYBBOID,OUTEIID
         LA    R1,BPSTKEY1
         ST    R1,CRYBRPOSTAD
         ST    R8,BPSTKEY2
         MVC   CRYBRPOSTL,=F'2'
         CCRY  MF=E,PARAM=(R8),CALLER=USER  -------------------------(9.)
*
         @IF   EQ
         CLC   CRYBRET,=F'0'
         @THEN , encrypt accepted
*
*  wait for the completion of encrypt
*
         @ELSE , encrypt not accepted
* error handling 
         B     EXIT
         @BEND , encrypt (not) accepted
*
EXIT     EQU   *
         @EXIT
* DATA
*
CONTAAD  DC    A(CRY2ABC)
*
CGENRALL CGENRAL MF=L,VERSION=002
CSESIONL CSESION MF=L,VERSION=002
CGENKEYL CGENKEY MF=L,VERSION=002
CCRYINIL CCRYINI MF=L
CCRYL    CCRY  MF=L,VERSION=002
*
* mechanism DES_KEY_GEN (no parameter)
MDESKGEN DC    A(CRY0MDES_KEY_GEN),A(0),A(0)
* mechanism DES_ECB (no parameter)
MDESECB  DC    A(CRY0MDES_ECB),A(0),A(0)
*
* string to be encrypted (for DES-ECB, length must be a multiple of 8)
ZINPUT   DC    CL16'that is secret!'
*
*
ZEXALOC  @PAR  D=YES
*
CGENRALC CGENRAL MF=C,VERSION=002
*
CCRYINIC CCRYINI MF=C
*
ENAEIRC  DS    0F
ENAEISC  DS    X
         DS    X
         DS    X
ENAEIMC  DS    X
*
ENACORC  DS    0F
ENACOSC  DS    X
         DS    X
         DS    X
ENACOMC  DS    X
*
OPOSTKEY DS    0D
OPSTKEY1 DS    F
OPSTKEY2 DS    F
*
DPOSTKEY DS    0D
DPSTKEY1 DS    F
DPSTKEY2 DS    F
*
BPOSTKEY DS    0D
BPSTKEY1 DS    F
BPSTKEY2 DS    F
*
* encrypted string area
ZENCOUT  DS    XL24
*
ZEXALOC  @PAR  LEND=YES
         @END
*
**********************************************************************
*
ENTRY CRY2ABC
CRY2ABC  @ENTR TYP=B,BASE=R10,FUNCT='Contingency '  ----------------(10.)
CRY2ABC  AMODE ANY
CRY2ABC  RMODE ANY
*
*  register contents at start of contingency 
*  R1: contingency message - not used
*  R2: event information code
*  R3: post code 1 (byte1: EC type of Crypt; rest: RC)
*  R4: post code 2 (A(PA))
*
         LR    R10,R15
*
         CONTXT STACKR=(R12,R13),OWNR=(R12,R13),FUNCT=READ,PROCESS=LAST
* 
*
         L     R9,=V(CRY2ABV)
         @DATA BASE=R9,CLASS=B,DSECT=AREA
*
         LA    R14,OUTCOID
         LA    R15,OUTEIID
         SOLSIG EIID=(R15),COID=(R14),LIFETIM=600,PARMOD=31  -------(11.)
*
         @IF   NZ
*  error at SOLSIG?
         LTR   R15,R15
         @THEN , error
* error handling 
         B     RETCO
         @BEND , error
*
         ST    R2,CONTIRC
         @IF   EQ
* ok?
         CLI   CONTIMC,X'00'
         @THEN , cont correctly started
         @IF   EQ
         CLI   CONTISC,X'28'
         @OR   EQ
         CLI   CONTISC,X'2C'
         @THEN , ok
*
* nothing to do
*
         @ELSE , what's wrong
         @IF   EQ
* timeout?
         CLI   CONTIMC,X'04'
         @THEN , timeout or EI killed
* timeout handling 
*
         B     RETCO
         @ELSE , something wrong
*
* error handling 
*
         B     RETCO
         @BEND , something wrong/ timeout or EI killed
         @BEND , what's wrong
         @ELSE , something wrong
* error handling 
         B     RETCO
         @BEND , something wrong
*
* cont correctly started
*
         @IF   NE
*  contains post code 1 the ETC of CRYPT?
         CLM   R3,B'1000',=AL1(CRY0EVENT)  -------------------------(12.)
         @THEN , not a CRYPT event
*
* error handling 
*
         B     RETCO
         @BEND , not a CRYPT event
*
         @IF   EQ
*  PA not allocated?
         CLM   R3,B'0011',=AL2(CRY0PA_NOT_ALLOC)
         @THEN , PA not allocated
*
* error handling 
         B     RETCO
         @BEND , PA not allocated
* 
*
         LR    R3,R4
         @DATA BASE=R3,DSECT=ESMFHDR
*
         @CAS2 ESMFCT,COMP=CLI  ------------------------------------(13.)
*
         @OF   ESESION
*
         @DATA BASE=R3,DSECT=CRYO_MDL
         @IF   EQ
         CLC   CRYORET,=F'0'
         @THEN , session function ok
*
@IF   EQ
* action = opensession
         CLI   CRYOACTION,CRYOOPENSESSION
         @THEN , openSession
*
* handle open session 
*
         @BEND , openSession
*
         @ELSE , session function not ok
* error handling 
         B     RETCO
         @BEND , session function (not) ok
*
* end ESESION
*
         @DATA BASE=R3,DSECT=ESMFHDR
         @OF   EGENKEY
*
         @DATA BASE=R3,DSECT=CRYD_MDL
         @IF   EQ
         CLC   CRYDRET,=F'0'
         @THEN , generate key ok
*
* handle generate key
*
         @ELSE , generate key not ok
* error handling 
         B     RETCO
         @BEND , generate key (not) ok
*
* end EGENKEY
*
         @DATA BASE=R3,DSECT=ESMFHDR
         @OF   ECRY
* CRY
         @DATA BASE=R3,DSECT=CRYB_MDL
*
         @IF   EQ
         CLC   CRYBRET,=F'0'
         @THEN , crypt function ok
*
         @IF   EQ
* action = encrypt?
         CLI   CRYBACTION,CRYBENCRYPT
         @THEN , encrypt
*
* handle encrypt
*
         @ELSE , <> encrypt
         @IF   EQ
* action = decrypt?
         CLI   CRYBACTION,CRYBDECRYPT
         @THEN , decrypt
*
* handle decrypt
*
         @ELSE , <> decrypt
*
         @BEND , decrypt ...
         @BEND , encrypt ...
         @ELSE , crypt function not ok
* error handling 
         B     RETCO
         @BEND , crypt function (not) ok
*
* end ECRY
         @DATA BASE=R3,DSECT=ESMFHDR
         @OFRE
* error: unknown function
*
* error handling 
*
         B     RETCO
         @BEND , CAS  ESMFCT,COMP=CLI
*
*
*
RETCO    EQU   *
         RETCO
         @EXIT
********************************************************
* EQUates for the CRYPT functions 
EGENRAL  EQU   1    GENeRAL-purpose functions
ESESION  EQU  20    SESsION management
EOBJMGT  EQU  30    OBJect ManaGemenT
ECRYINI  EQU  40    INIt a CRYptographic function
ECRY     EQU  41    CRYptographic function
ECRYFIN  EQU  42    FINalize a CRYptographic function
EGENKEY  EQU  80    GENerateKEY
EGENKPR  EQU  81    GENerateKeyPaiR
EWRPKEY  EQU  82    WRaPKEY
EUNWKEY  EQU  83    UNWrapKEY
EDRVKEY  EQU  84    DeRiVeKEY
ERANDOM  EQU  90    RANDOM number generation
*-------------------------------------------------------*

*
CONTIRC  DS    0F
CONTISC  DS    X
         DS    X
         DS    X
CONTIMC  DS    X
*