Date: Tue, 13 Jan 2026 15:33:28 +0100
On 13/01/2026 14:43, Hans Åberg wrote:
>
>> On 13 Jan 2026, at 14:41, David Brown <david.brown_at_[hidden]> wrote:
>>
>> On 13/01/2026 14:34, Hans Åberg via Std-Proposals wrote:
>>> There might be support for modular integers int_mod<m> ≔ ℤ/mℤ for a modulus m that fits into a fixed-sized word, say 4096 bits for use in cryptology, m ≤ 2⁴⁰⁹⁶. With recursive templates, like those I have written, for fixed-size unsigned integral types up to uint4096_t, it should not be difficult to implement.
>>
>> "unsigned _BitInt(4096)" will give you that. That is already part of C23, and I believe it is coming to C++, though I don't know the current status off-hand.
>
> It is too slow.
>
Speed is a quality of implementation issue. The standard specifies the
way these integer types work and their basic arithmetic operations, but
it does not specify how those operations are implemented. So an
implementation can use a simple O(n^2) multiplication algorithm - it
could also use something a lot more sophisticated.
If you want a C++ library for cryptography work, there's a great deal
more involved than just a large modular integer type. You'll want
specific algorithms for particular operations, support for integer power
operations, support for guaranteed clearing of key storage, and all
sorts of other things. And of course none of this will be much use to
ordinary users - they will want high-level cryptographic functions,
without caring about the implementation.
Have you had a look for existing standards proposals in this area? I
have not looked at it myself, but it would surprise me if there weren't
a fair number of related proposals. Check to see what there is, and
what their status is, then you can see if it is worth making a more
specific proposal. But if all you are asking for is a modular integer
type with normal arithmetic operations, it exists already, and if your
only problem is that an implementation you tried was too slow for your
liking, then the way forward is a bug report to the compiler implementer.
>
>> On 13 Jan 2026, at 14:41, David Brown <david.brown_at_[hidden]> wrote:
>>
>> On 13/01/2026 14:34, Hans Åberg via Std-Proposals wrote:
>>> There might be support for modular integers int_mod<m> ≔ ℤ/mℤ for a modulus m that fits into a fixed-sized word, say 4096 bits for use in cryptology, m ≤ 2⁴⁰⁹⁶. With recursive templates, like those I have written, for fixed-size unsigned integral types up to uint4096_t, it should not be difficult to implement.
>>
>> "unsigned _BitInt(4096)" will give you that. That is already part of C23, and I believe it is coming to C++, though I don't know the current status off-hand.
>
> It is too slow.
>
Speed is a quality of implementation issue. The standard specifies the
way these integer types work and their basic arithmetic operations, but
it does not specify how those operations are implemented. So an
implementation can use a simple O(n^2) multiplication algorithm - it
could also use something a lot more sophisticated.
If you want a C++ library for cryptography work, there's a great deal
more involved than just a large modular integer type. You'll want
specific algorithms for particular operations, support for integer power
operations, support for guaranteed clearing of key storage, and all
sorts of other things. And of course none of this will be much use to
ordinary users - they will want high-level cryptographic functions,
without caring about the implementation.
Have you had a look for existing standards proposals in this area? I
have not looked at it myself, but it would surprise me if there weren't
a fair number of related proposals. Check to see what there is, and
what their status is, then you can see if it is worth making a more
specific proposal. But if all you are asking for is a modular integer
type with normal arithmetic operations, it exists already, and if your
only problem is that an implementation you tried was too slow for your
liking, then the way forward is a bug report to the compiler implementer.
Received on 2026-01-13 14:33:35
