# crypto.ff: faster exponentiation with short/public exponents \(\#17617\) · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/a5c79c79983739630d7269f8583525d83ba9677b)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: a5c79c79983739630d7269f8583525d83ba9677b

Requested commit: a5c79c79983739630d7269f8583525d83ba9677b

Commit: a5c79c79983739630d7269f8583525d83ba9677b

Tree: a1e29fca84b608a66f96fce1feb7d764e308a43a

Author: Frank Denis

Committer: GitHub

## Message

```
crypto.ff: faster exponentiation with short/public exponents (#17617)

RSA exponents are typically 3 or 65537, and public.

For those, we don't need to use conditional moves on the exponent,
and precomputing a lookup table is not worth it. So, save a few
cpu cycles and some memory for that common case.

For safety, make `powWithEncodedExponent()` constant-time by default,
and introduce a `powWithEncodedPublicExponent()` function for exponents
that are assumed to be public.

With `powWithEncodedPublicExponent()`, short (<= 36 bits) exponents
will take the fast path.
```

## Parents

- [54a4f24ea7c76297e97683501aef607b2a27cd16](https://git.cafe/gitcafe/zig/commit/54a4f24ea7c76297e97683501aef607b2a27cd16?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/a5c79c79983739630d7269f8583525d83ba9677b?format=markdown)
