Measuring Arduino Power Consumption with a Shunt Resistor but Signal Too Weak

Hello,

As part of a school project, I am trying to perform a simple power analysis attack on a naïve RSA implementation by exploiting the modular exponentiation algorithm. I run my algorithm on a Joy-IT Arduino UNO R3 DIP (ATmega328P). To measure power consumption, I inserted a 1 Ω shunt resistor in series with the power supply.

Hardware Setup:
External power supply: 5 V voltage generator
Oscilloscope: RIGOL DS1042C (40 MHz, 400 MSa/s)
Measurement method: measuring the voltage across the shunt resistor to deduce current variations
A GPIO (PIN_SYNC) is used as a synchronization signal to trigger the oscilloscope. Basically, the Arduino outputs a continuous 5 V signal while executing the modular exponentiation algorithm. This allows me to know precisely when the Arduino is performing that part (it is clearer when you check out the code).

My objective is to observe temporal variations in power consumption during modular exponentiation, in order to distinguish between square and multiply operations.
Code running on the Arduino:


const int PIN_SYNC = 12;

void setup(){
    pinMode(PIN_SYNC, OUTPUT);
    digitalWrite(PIN_SYNC, LOW);
}


unsigned long modexp(unsigned long base, unsigned long exposant, unsigned long mod){
    unsigned long resultat = 1;
    base = base % mod;


    while (exposant > 0) {
        if (exposant & 1) {
            resultat = (resultat * base) % mod;
        }
        base = (base * base) % mod;
        exposant >>= 1;
    }
    return resultat;
}


void loop(){
    digitalWrite(PIN_SYNC, HIGH);
    modexp(7, 105, 187);  // 105 = 1101001 in binary
    digitalWrite(PIN_SYNC, LOW);
    delay(1000);
}

Problem: the voltage variation across the shunt resistor is very small, close to the noise, and I struggle to clearly distinguish the operations in the power trace.

I am therefore wondering:
Is 1 Ω too small for this type of attack on an Arduino? Maybe I am having a shunt issue. I tried to take a higher shunt but it wasn’t effective.
Is it realistic to expect exploitable observations without signal amplification or current sensor?
Is a 40 MHz oscilloscope sufficient for this type of measurement?
Do you have any practical advice (shunt placement, AC/DC coupling, filtering, clock frequency, etc.) to improve my setup?

I would greatly appreciate any feedback or suggestions. I have added in attachment a picture of my circuit (in french sorry).
Thank you in advance.

1 Like

Welcome to the Arduino forum. Lots of descriptions, but, notice, there is never a value given for what currents you are looking for. All answers depend on what you are testing for, right?

I doubt you would be measuring any variation by measuring the current draw of the whole board. The two 47uF electrolytic capacitors and various 100n ceramic capacitors on the board's VCC rail will smooth out any variation. Killing noise is what they are there for.

Maybe you could put your shunt on the VCC pin of the ATmega chip by lifting it out of the socket. But I doubt there will be a lot of varyation, if any. An MCU is not a computer with clock frequency and core switching. An MCU always runs at 100%, even when doing nothing.
Leo..

The AVR does not have the fancy multiple execution units of some more advanced CPUs, so a "square" is going to be implemented by a sequence of the same sorts of instructions that implement a "multiply."
Ie, maybe you're not seeing current variations because there are no current variations...

Welcome!

There is an old timers way to get more voltage, it is called an amplifier. You can amplify the signal from your shunt to a value you can work with. This can be done with an op-amp. You could also change the reference voltage either the internal reference or use a different one placing it on the Aref pin but be sure you do it correctly or you could damage the UNO.

I think the average scope has more than enough gain,
but there isn't much to measure (or amplify) if the source signal is shorted with capacitors.
Leo..

Have you considered that no variation might be the answer you are looking for?

The CPU sees instructions coming in from flash and does what they tell it to do. OR this byte with that byte, ADD this byte to that byte. It has no idea whether what it is doing is spinning its wheels in a long delay or calculating the required trajectory to get a rocket to Io. As far as the CPU is concerned it's just another simple instruction. They all consume about the same amount of power, there's nothing to measure.

This is irrelevant because silence1828403 is not using the Uno's ADC to measure the supply current.
He/she is using an oscilloscope to make the measurement.

If you are using a scope why not use a current probe. I do that all the time with my teck scope, there are many that will work with your scope.

There is also an amplifier available designed specifically for your scope: PA1011 Rigol Amplifier