Author Topic: Encryption function works in windows program, but not on microcontroller  (Read 602 times)

0 Members and 1 Guest are viewing this topic.

Offline eTobeyTopic starter

  • Frequent Contributor
  • **
  • Posts: 596
  • Country: de
I have made an encryption function, that i use for both a windows program and on a microcontroller (STM32G431). It works as expected on windows, but on the chip it doesnt.

It use multiple bit shift and XOR. I already casted the function parameters to what they should be, but it still does not work.
What else could also be different on these two systems?

"Sometimes, after talking with a person, you want to pet a dog, wave at a monkey, and take off your hat to an elephant." (Maxim Gorki)
 

Offline PlainName

  • Super Contributor
  • ***
  • Posts: 6867
  • Country: va
Re: Encryption function works in windows program, but not on microcontroller
« Reply #1 on: December 18, 2023, 05:16:08 pm »
Quote
I already casted the function parameters to what they should be

Sounds dodgy - why would you need to cast them? Are they not properly defined?

Other than that, there is absolutely zero to go on here. Some code where it is failing would be useful. Even just saying what language and which compilers you're using would be a help!

Windows is probably 64-bit, but that's so obvious and you surely aren't using 64-bit ints on Windows and casting to 32-bits on the STM. Has it worked previously on some other micro? Another desktop OS? Go on, give us some info...
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 8184
  • Country: fi
Re: Encryption function works in windows program, but not on microcontroller
« Reply #2 on: December 18, 2023, 05:25:35 pm »
Show the code.

Generally, use stdint.h stuff and be careful with integer promotion rules.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26994
  • Country: nl
    • NCT Developments
Re: Encryption function works in windows program, but not on microcontroller
« Reply #3 on: December 18, 2023, 05:33:57 pm »
I have made an encryption function, that i use for both a windows program and on a microcontroller (STM32G431). It works as expected on windows, but on the chip it doesnt.

It use multiple bit shift and XOR. I already casted the function parameters to what they should be, but it still does not work.
What else could also be different on these two systems?
If you need casting function parameters, then you are likely looking at alignment issues. Look whether the code accesses data to be encrypted in chunks more than 1 byte long. If so, this code is likely not portable.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline eTobeyTopic starter

  • Frequent Contributor
  • **
  • Posts: 596
  • Country: de
Re: Encryption function works in windows program, but not on microcontroller
« Reply #4 on: December 18, 2023, 05:43:17 pm »
I found the problem: just a few inches in fron of the screen  :-DD

I was so focused on my encryption function, that i did not check the parameters that were coming in. Guess what... Sometimes you got to focus, but sometimes you should not at all!
"Sometimes, after talking with a person, you want to pet a dog, wave at a monkey, and take off your hat to an elephant." (Maxim Gorki)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf