Generating a one-way hash
The examples in this appendix are REXX executables that can be used to generate an SHA-512 one-way hash, using CCA and PKCS#11.
This appendix includes the following topics:
 
F.1 CCA SHA-512 one-way hash REXX sample
A CCA SHA-512 one-way hash REXX sample is shown in Example F-1.
Example F-1 CCA SHA-512 one-way hash REXX sample
/* Rexx */
/*-------------------------------------------------------------------*/
/* Generate SHA-512 hash using CCA One-Way Hash service     */
/*-------------------------------------------------------------------*/
/* expected results */
ExpRc = '00000000'x
ExpRs = '00000000'x
 
BOWH_Rule_Array = 'SHA-512 ' || 'ONLY ' ;
BOWH_Text = '0123456789ABCDEF';
BOWH_Hash = copies('00'x, 64);
BOWH_Chain_Vector = copies('00'x,128);
call CSNBOWH
 
say 'BOWH Hash: ' c2x(BOWH_Hash)
 
Exit
 
/* --------------------------------------------------------------- */
/* One-Way Hash Generate */
/* */
/* Used to generate a one-way hash */
/* */
/* See the ICSF Application Programmer's Guide for more details. */
/* --------------------------------------------------------------- */
 
CSNBOWH:
 
/* initialize parameter list */
BOWH_rc = 'FFFFFFFF'x ;
BOWH_rs = 'FFFFFFFF'x ;
BOWH_Exit_Length = '00000000'x ;
BOWH_Exit_Data = '00000000'x ;
BOWH_Rule_Count = d2c(length(BOWH_Rule_Array)/8,4);
BOWH_Text_Length = d2c(length(BOWH_Text),4);
BOWH_Chain_Vector_Length = d2c(length(BOWH_Chain_Vector),4);
BOWH_Hash_Length = d2c(Length(BOWH_Hash),4);
/* call CSNBOWH */
address linkpgm 'CSNBOWH' ,
'BOWH_rc' 'BOWH_rs' ,
'BOWH_Exit_Data_Length' 'BOWH_Exit_Data' ,
'BOWH_Rule_Count' 'BOWH_Rule_Array' ,
'BOWH_Text_Length' 'BOWH_Text' ,
'BOWH_Chain_Vector_Length' 'BOWH_Chain_Vector' ,
'BOWH_Hash_Length' 'BOWH_Hash' ;
 
if (BOWH_rc = ExpRc | BOWH_rs = ExpRs) then
say 'BOWH failed: rc =' c2x(BOWH_rc) 'rs =' c2x(BOWH_rs) ;
else
say 'BOWH successful: rc =' c2x(BOWH_rc) 'rs =' c2x(BOWH_rs) ;
 
return
F.2 PKCS #11 SHA-512 one-way hash REXX sample
A PKCS #11 SHA-512 one-way hash REXX sample is shown in Example F-2.
Example F-2 PKCS #11 SHA-512 one-way hash REXX sample
/* Rexx */
/*-------------------------------------------------------------------*/
/* Generate SHA-512 hash using PKCS #11 One-Way Hash service         */
/*-------------------------------------------------------------------*/
/* expected results */
ExpRc = '00000000'x
ExpRs = '00000000'x
/* Call PKCS#11 One-Way Hash with generated token */
POWH_Rule_Array = 'SHA-512 ' || 'ONLY ' ;
POWH_Text = '0123456789ABCDEF';
POWH_Hash = copies('00'x, 64);
POWH_Chain_Vector = copies('00'x,128);
POWH_Handle = Left('QSAFE.TEST.TOKEN',44)
call CSNPOWH
say 'POWH Hash: ' c2x(POWH_Hash)
Exit
/* --------------------------------------------------------------- */
/* PKCS #11 One-Way Hash, Sign, or Verify */
/* */
/* Use the PKCS #11 One-Way Hash, Sign, or Verify callable service */
/* to generate a one-way hash on specified text, sign specified */
/* text, or verify a signature on specified text. */
/* */
/* See the ICSF Application Programmer's Guide for more details. */
/* --------------------------------------------------------------- */
CSNPOWH:
/* initialize parameter list */
POWH_RC = 'FFFFFFFF'x ;
POWH_RS = 'FFFFFFFF'x ;
POWH_Exit_Length = '00000000'x ;
POWH_Exit_Data = '' ;
POWH_Rule_Count = d2c(length(POWH_Rule_Array)/8,4);
POWH_Text_Length = d2c(length(POWH_Text),4);
POWH_Text_id = '00000000'x ;
POWH_Chain_Vector_Length = d2c(length(POWH_Chain_Vector),4);
POWH_Hash_Length = D2C(Length(POWH_Hash),4);
 
/* call CSNPOWH */
address linkpgm 'CSFPOWH' ,
'POWH_RC' 'POWH_RS' ,
'POWH_Exit_Length' 'POWH_Exit_Data' ,
'POWH_Rule_Count' 'POWH_Rule_Array' ,
'POWH_Text_Length' 'POWH_Text' ,
'POWH_Text_id' ,
'POWH_Chain_Vector_Length' 'POWH_Chain_Vector' ,
'POWH_Handle' ,
'POWH_Hash_Length' 'POWH_Hash' ;
 
if (POWH_rc = ExpRc | POWH_rs = ExpRs) then
say 'POWH failed: rc =' c2x(POWH_rc) 'rs =' c2x(POWH_rs) ;
else
say 'POWH successful: rc =' c2x(POWH_rc) 'rs =' c2x(POWH_rs) ;
 
 
return
 
 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset