Skip to content

This implementation is vulnerable to a timing attack #1

@otsmr

Description

@otsmr

This implementation is referenced in this Wikipedia article. The Code is after the sentence “The Montgomery ladder approach computes the point multiplication in a fixed amount of time”. But this implementation has in my understanding a timing issue, leading to a possibly timing attack.

The vulnerable line is here.

for i in (0..=s.bits()).rev()

According to the docs of BigInt, the function bits will return the fewest bits necessary to express the BigInt, but without any leading zeros. Because of the missing leading zeros, there are fewer iterations in the loop when the number is smaller. If you are using for the secret scalar in for example ECDSA random numbers between 1 and 2^256 it is likely that this random numbers can have multiple leading zeros. When you now generate many signatures and measures the time you can detect, when there are multiple leading zeros are present. With this knowledge, you can then perform a Lattice ECDSA attack.

Here is a simple POC to prof the timing issue:

use e521::curve::e521::e521::sec_mul;
use num::BigInt;
use e521::curve::e521::e521::get_e521_gen_point;
use std::time::Instant;

fn main() {
    for i in 0..200  {
        let point = get_e521_gen_point(false);
        let s = BigInt::from(1) << i;
        let now = Instant::now();
        let _result = sec_mul(s, point);
        println!("{} needed {} micro seconds", i, now.elapsed().as_micros());
    }
}

And here are the first lines of the output:

0 needed 1338 micro seconds
1 needed 2582 micro seconds
2 needed 5478 micro seconds
3 needed 9848 micro seconds
4 needed 12429 micro seconds
5 needed 16816 micro seconds
6 needed 21067 micro seconds
7 needed 24940 micro seconds
8 needed 30308 micro seconds
9 needed 34518 micro seconds
10 needed 38180 micro seconds

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions