Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This implementation is vulnerable to a timing attack #1

Open
otsmr opened this issue Mar 4, 2023 · 1 comment
Open

This implementation is vulnerable to a timing attack #1

otsmr opened this issue Mar 4, 2023 · 1 comment

Comments

@otsmr
Copy link

otsmr commented Mar 4, 2023

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
@otsmr otsmr changed the title I think this implementation is vulnerable to a timing attack This implementation is vulnerable to a timing attack Mar 9, 2023
@otsmr
Copy link
Author

otsmr commented Jun 20, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant