private byte[] SHA1(byte[] data, int offset, int count, bool final) { byte returnBytes = final ? (byte)20 : (byte)0; Comms.WriteReset(); Comms.WriteByte((byte)eClass.CLA_CRYPTO); //Class Instruction for Cryptographic Functions Comms.WriteByte((byte)eFunction.INS_CRYPTO_HASH); //Instruction Code for Cryptographic HASH Function Comms.WriteByte((byte)eP1.P1_CRYPTO_HASH_SHA1); //Parameter (P1) for SHA-1 hash function Comms.WriteByte(final ? (byte)eP2.P2_FINAL : (byte)eP2.P2_MORE); //Parameter (P1) for SHA-1 hash function Comms.WriteEncodedLength((UInt16)count); // L Comms.Write(data, offset, count); //N bytes of data Comms.WriteByte(returnBytes); //0x14 20-byte hash of expected return return(Comms.Execute(returnBytes)); }
UInt16 SASPreUpgrade(byte[] data, int offset, int count) { Console.WriteLine("Entering firmware upgrade mode"); Comms.WriteReset(); Comms.WriteByte((byte)eClass.CLA_DIAG); //Class Instruction for Firmware upgrade CLA_DIAG Comms.WriteByte((byte)eFunction.INS_DIAG_FIRMWARE_UPDATE); //INS_DIAG_FIRMWARE_UPDATE Comms.WriteByte(0x02); //Instruction Code for Cryptographic HASH Function Comms.WriteByte((byte)eP2.P2_FINAL); //P2_FINAL Comms.WriteEncodedLength((UInt16)count); // L Comms.Write(data, offset, count); //N bytes of data UInt16 errCode; Comms.Execute(0, out errCode); return(errCode); }
public byte[] Factom_Sign(byte[] data, int offset, int count) { const byte returnBytes = 64; Comms.WriteReset(); Comms.WriteByte((byte)eClass.CLA_FACTOM); //Class Instruction for Cryptographic Functions Comms.WriteByte((byte)eFunction.INS_FACTOM_SIGN_ENTRY); //Instruction Code for Cryptographic HASH Function Comms.WriteByte((byte)eP1.P1_CRYPTO_HASH_SHA256); //Parameter (P1) for SHA-1 hash function Comms.WriteByte((byte)eP2.P2_FACTOM_ADDRESS_ID); //Parameter (P2) reserved for future use Comms.WriteEncodedLength((UInt16)count); // L Comms.Write(data, offset, count); // N bytes of data Comms.WriteByte(returnBytes); // 64 byte hash of expected return return(Comms.Execute(returnBytes)); }
public void IncrementMonotonicCounter(byte[] upperSeed = null) { const byte returnBytes = 0x40; Comms.WriteReset(); Comms.WriteByte((byte)eClass.CLA_DIAG); //Class Instruction for Utility Functions Comms.WriteByte((byte)eFunction.INS_CRYPTO_MONOTONIC_COUNTER); //Instruction Code for Monotonic Counter Comms.WriteByte(0x00); //Parameter (P1) reserved for future use Comms.WriteByte(0x00); //Parameter (P2) reserved for future use if (upperSeed != null) { Comms.WriteByte(0x04); // R Comms.Write(upperSeed); } Comms.WriteByte(returnBytes); // this is the size of the returned 64-bit monotonic counter }