|
Forum Index : Microcontroller and PC projects : Xmas Puzzle Challenge and Response
| Author | Message | ||||
| retepsnikrep Senior Member Joined: 31/12/2007 Location: United KingdomPosts: 134 |
Seasons Greetings to all. If you get bored with relatives and feasting today perhaps you might cast your eye over the below. I have an electronic gadget that has a challenge/response seed/key? going on. It sends me two bytes. I have to respond with two bytes somehow derived from the ones it sent me. I have a few examples below of correct challenges and responses. Any ideas on how it is working and generating the response? Challenge $E3 $C5 Response $82 $CB Challenge $79 $71 Response $04 $35 Challenge $84 $15 Response $ED $85 Challenge $9B $B6 Response $6F $C9 Challenge $C7 $B0 Response $1A $DD Challenge $AB $19 Response $9A $69 Many thanks and best wishes for the new year. Edited 2020-12-25 20:33 by retepsnikrep Gen1 Honda Insights. |
||||
| pdeivendran Newbie Joined: 18/09/2020 Location: MalaysiaPosts: 9 |
It uses a simple XOR encryption using a 2-byte master key with its algorithm coupled with the challenge key. I have done this before on a micromite with an 8-byte challenge key and master key. |
||||
| retepsnikrep Senior Member Joined: 31/12/2007 Location: United KingdomPosts: 134 |
Thanks for the response. Could I look at your MM code or could you explain in more detail how the algorithm works. Thanks. Gen1 Honda Insights. |
||||
| pdeivendran Newbie Joined: 18/09/2020 Location: MalaysiaPosts: 9 |
Dear Retepsnikrep, No worries, just give me a few days, by this coming week, I will update you with the code. I have developed this code to be used with serial EEPROMs with UID. I have done this to protect the product design from being reversed engineered and manufactured. As you know, PIC chips can be read via PICKIT, although the code is protected via Micromite "PIN" routine, the board design and electronics are not. The serial EEPROM solves this. The unique ID from the chip is your challenge key, which you can read, apply your XOR encryption with your own 8-byte master key and store the results onto the PIC's allocated memory space using the "VAR SAVE" routine in Micromite. If somebody tries to imitate your design and copies the content of your PIC32, uses a UID EEPROM, the challenge result would be different, thus you can terminate your program. The manufacturer of UID EEPROMs ensures that every chip produced has a unique ID of its own. Although using a UID EEPROM does require to use of any form of encryption, the added encryption ensures that, if anyone eves drops on the SPI or I2C data from the UID chip and mimic it, they still won't be able to solve the result of the challenge key. Sorry for the lengthy story line. |
||||
| retepsnikrep Senior Member Joined: 31/12/2007 Location: United KingdomPosts: 134 |
Apologies I think the seed/key are both 3 bytes each. I found a C++ solution written in Visual Studio 19 that accepts the seed and squirts out the key, but i don't understand C++ and want to convert the basic actual algorithm into MMBasic. Can anyone offer any help or break down what is happening into plain english then i can write my own code.. I appreciate the help so far.. C++ Text attached. Seed_Key_Calculation C++.zip Gen1 Honda Insights. |
||||
| GerryL Regular Member Joined: 24/01/2019 Location: AustraliaPosts: 41 |
I could not open your C++ link. Gerry |
||||
| retepsnikrep Senior Member Joined: 31/12/2007 Location: United KingdomPosts: 134 |
I have Uploaded it again.. SeedKey.zip Gen1 Honda Insights. |
||||
| pdeivendran Newbie Joined: 18/09/2020 Location: MalaysiaPosts: 9 |
Dear Retepsnikrep, I have attached One of my working Encryption/Decryption Micromite code for your test, evaluation and modification. The code attached uses a simple but sufficient XOR encryption. I have done also RC4 algorithms but based on your requirement, I believe the code attached is sufficient. I am a bit busy for now but once I get a bit more time, I will update you with further working examples. I have commented the code as much I can, for your understanding. I believe you can further simplify the code by substituting some of the processes via FUNTION calls. If you any further questions, please do flag me. Dave aka "siliconfreak" XOR_Crypto.bas.zip |
||||
| retepsnikrep Senior Member Joined: 31/12/2007 Location: United KingdomPosts: 134 |
I appreciate the input from forum members. Thanks Dave does your code reflect/mirror what the C in my source is doing? Gerry L I uploaded the C source again.. Gen1 Honda Insights. |
||||
| pdeivendran Newbie Joined: 18/09/2020 Location: MalaysiaPosts: 9 |
Dear R, Your C code uses a fixed polynomial number lookup table. Based on my experience, some encryption algorithms (eg. RSA, 3DES) use these methods to calculate the encrypted/decrypted message. However, I don't recommend using this method as its tedious on processing power and memory. Furthermore, I need to study the fixed polynomial numbers given to determine which method is being used. It looks like the stuff I use in my CRC-16 or CRC-32 calculation for MODBUS communications. Also, polynomial number lookup tables need to be tested thoroughly as a small variance in any one value, will give results errors based on certain scenarios. So stay away from it, if you can. End of the day, the kind of encryption algorithm used, defines your required end result. The more sensitive your data, the more complex algorithm used, especially when it comes to money related data. Use these methods only if you require it. These tables are published on white papers for the related encryption algorithms. The one I shared with you will definitely suit your requirement and more. I have used the codes given to you, to implement my version of "revolving encryption". The master key is the "Network IP Address". That means the same set of data gives different results for different "Network IP Address". So if anyone trying to eavesdrop on your encrypted data will always get a different result on the same sets of data from different "Network IP Address". I will post you my RC4 algorithm, also implemented on Micromite, sometimes this week. Sorry I working on something and trying to get around using the Microchip / ATMEL 24CS01 (SPI / i2C), UID EEPROM. Don't seem to get it working, its a real bitch. Its something to do with Micromite's iC2 handshake with these chips. If you have any insight on this, I would really appreciate it. Remember, the PIC32 is a powerful MCU but does not have the resources of a PC. If you share a little further on your end application, maybe I can throw in some ideas of tips on what you should implement as the end result. Take Care. Dave aka siliconfreak |
||||
| retepsnikrep Senior Member Joined: 31/12/2007 Location: United KingdomPosts: 134 |
Apologies if there is a misunderstanding. I didn't want to implement a new algorithm, I wanted to duplicate the one in my C code in MMBASIC as is. But of course if you have a brilliant idea for a new algorithm that produces the same results then great.. I have some unflashable hardware which is using this scheme and it is sending me the three byte seed and I need to respond with the 3 byte key. Sorry for any confusion.. Edited 2020-12-30 16:00 by retepsnikrep Gen1 Honda Insights. |
||||
| retepsnikrep Senior Member Joined: 31/12/2007 Location: United KingdomPosts: 134 |
Thanks to generous help on this and other forums I have cracked this now. Much appreciated. This pseudo code seems to work. In the end I did not need the large lookup table as it was always using the same table entry. So my code ended up being tiny. W0 VAR WORD W1 VAR WORD W2 VAR WORD SEED1 VAR BYTE SEED2 VAR BYTE SEED3 VAR BYTE 'KEY1 = 46336; 'KEY3 = 32973; 'SHIFT1 = 1; (-1) 'SHIFT2 = 3; ' Calculates and stores the results of two cryptographic operations ' on the first two seed bytes in W1 and W2 ' ' The operation being carried out consists of adding two 16-bit values ' and performing a bitwise rotation on the result. ' ' The two results are calculated from adding the 2 seed bytes to both ' KEY1 and KEY2, with a rotation of SHIFT1 and SHIFT2 respectively. SEED1 = $C7 SEED2 = $B0 SEED3 = $6B 'Answer should be $82 $CB $6B W1.BYTE0 = SEED2 W1.BYTE1 = SEED1 W0 = W1 + 46336 'Key1 ' Does a cyclic bitwise rotation of B0-bits on W0 W0 = (W0 >> 1 | W0 << ($10 - 1)) 'Note this is a negative shift W2 = W0 W0 = W1 ' Does a cyclic bitwise rotation of B0-bits on W0 W0 = (W0 << 3 | W0 >> ($10 - 3)) 'Note this is a positive shift W1 = W0 ' Multiplies the contents of W1 and W2 and adds KEY3, stores in W0 ' Impicitly calculates 16-bit overflow only W0 = W1 * W2 W0 = W0 + 32973 'KEY3 SEED1 = W0.BYTE1 SEED2 = W0.BYTE0 Gen1 Honda Insights. |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |