public byte[] Factom_GetEntryCreditAddress() { const byte returnBytes = 52; Comms.WriteReset(); Comms.WriteByte((byte)eClass.CLA_FACTOM); //Class Instruction for Cryptographic Functions Comms.WriteByte((byte)eFunction.INS_FACTOM_GET_ADDRESS); //Instruction Code for Encryption Key Request Comms.WriteByte((byte)eP1.P1_FACTOM_ADDRESS); //Parameter (P1) reserved for future use Comms.WriteByte((byte)eP2.P2_FACTOM_ADDRESS_EC); //Parameter (P2) reserved for future use Comms.WriteByte(returnBytes); //0x20 32-byte encryption key length of expected return return(Comms.Execute(returnBytes)); }
public byte[] GetFirmwareRevision() { const byte returnBytes = 3; Comms.WriteReset(); Comms.WriteByte((byte)eClass.CLA_DIAG); //Class Instruction for Utility Functions Comms.WriteByte((byte)eFunction.INS_DIAG_FW_VERSION); //Instruction Code for Revision Request Comms.WriteByte(0x00); //Parameter (P1) reserved for future use Comms.WriteByte(0x00); //Parameter (P2) reserved for future use Comms.WriteByte(returnBytes); //3 bytes representing firmware major, minor, and revision version numbers return(Comms.Execute(returnBytes)); }
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)); }
public byte[] 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)); }
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); }