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

Side Channels #10

Closed
nsc opened this issue Jul 29, 2018 · 0 comments
Closed

Side Channels #10

nsc opened this issue Jul 29, 2018 · 0 comments

Comments

@nsc
Copy link
Owner

nsc commented Jul 29, 2018

Part one of issue #9
In (

public func modular_pow<T : BinaryInteger>(_ base : T, _ exponent : T, _ mod : T) -> T
) you implement modular exponentiation using square-and-multiply. However this leaks the bits of the exponent (which in RSA and DH are secrets) to a timing or side channel attack. Also the reductions are implemented using Knuth's Algorithm D, which probably leak information about the inputs.

In ECDSA signature https://github.com/nsc/SwiftTLS/blob/master/SwiftTLS/Sources/Crypto/ECDSA.swift#L72 you must invert the k nonce modulo the group order during ECDSA signature. This is done using extended Euclidean algorithm (

public func modular_inverse<T : BinaryInteger>(_ x : T, _ y : T, mod : T) -> T
) which is known to leak information due to input dependent branches. The most common solution to this is to use Fermat's little theorem to compute the inverse (for any prime p and any x < p, x^{p-2} mod p == x^-1 mod p)

nsc added a commit that referenced this issue Jul 29, 2018
)

- introduce ModularReduction protocol
- implement Barrett and Montgomery reductions
- add constantTime parameter to relevant methods
nsc added a commit that referenced this issue Jul 29, 2018
)

- introduce ModularReduction protocol
- implement Barrett and Montgomery reductions
- add constantTime parameter to relevant methods
nsc added a commit that referenced this issue Jul 29, 2018
)

- introduce ModularReduction protocol
- implement Barrett and Montgomery reductions
- add constantTime parameter to relevant methods
@nsc nsc closed this as completed in a79fd42 Dec 25, 2018
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