USING Siemens.Simatic.S71500.Crypto;
PROGRAM SampleProgram
VAR
data : ARRAY[0..2] OF BYTE := [BYTE#1, BYTE#2, BYTE#3];
hashValue : ARRAY[0..31] OF BYTE;
buttonPushed : BOOL;
sha2Inst : SHA2;
END_VAR
// triggered by the rising edge of buttonPushed
sha2Inst(REQ := buttonPushed, HashLen := UINT#256, Data := data, Hash := hashValue);
IF sha2Inst.Done AND NOT sha2Inst.Error THEN
; // do something with the hash value
END_IF;
END_PROGRAM
Here is another example that shows how to calculate a hash value from elementary data types:
USING Siemens.Simatic.S71500.Crypto;
USING System.Serialization;
PROGRAM SampleProgram
VAR
data : UINT := UINT#1234;
dataSerialized : ARRAY[0..1] OF BYTE;
hashValue : ARRAY[0..31] OF BYTE;
buttonPushed : BOOL;
sha2Inst : SHA2;
END_VAR
Serialize(value := data, buffer := dataSerialized);
// triggered by the rising edge of buttonPushed
sha2Inst(REQ := buttonPushed, HashLen := UINT#256, Data := dataSerialized, Hash := hashValue);
IF sha2Inst.Done AND NOT sha2Inst.Error THEN
; // do something with the hash value
END_IF;
END_PROGRAM