# crypto.ff: allow seamless chaining regardless of representation \(\#30913\) · gitcafe/zig

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

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

Visibility: public

Requested revision: 8709f53d440ed8479f711d871a2d6c2c35dc1014

Requested commit: 8709f53d440ed8479f711d871a2d6c2c35dc1014

Commit: 8709f53d440ed8479f711d871a2d6c2c35dc1014

Tree: e08bf46306b640e8e73def890dbb40081568e0b8

Author: Frank Denis

Committer: Frank Denis

## Message

```
crypto.ff: allow seamless chaining regardless of representation (#30913)

Finite field elements can be in regular or Montgomery form, and
chaining different operations use to require manual and error-prone
conversions.

Now:

- `add`, `sub` and `mul` convert the second operand to match the
first operand's form
- `sq` and `pow` preserve the input's Montgomery form
- `toPrimitive` and `toBytes` return `UnexpectedRepresentation` if
the element is in Montgomery form, preventing incorrect serialization

This is fully backwards compatible and allows seamless chaining of
operations regardless of their representation.

```

## Parents

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

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