apple / swift-crypto

Open-source implementation of a substantial portion of the API of Apple CryptoKit suitable for use on Linux platforms.
https://apple.github.io/swift-crypto
Apache License 2.0
1.45k stars 157 forks source link

Change inclusiveMin param of ArbitraryPrecisionInteger.random from UInt64 to UInt #242

Closed simonjbeaumont closed 3 months ago

simonjbeaumont commented 3 months ago

Motivation

Currently ArbitraryPrecisionInteger.random(inclusiveMin:exclusiveMax:) takes a UInt64 for inclusiveMin and uses this for the BN_ULONG parameter of BN_rand_range_ex, but BN_ULONG is UInt32 on 32-bit platforms. For example, when compiling for "Any watchOS Simulator Device", we get the following compiler error:

swift-crypto/Sources/CryptoBoringWrapper/ArbitraryPrecisionInteger.swift:444:62: error: cannot convert value of type 'UInt64' to expected argument type 'BN_ULONG' (aka 'UInt32')
                CCryptoBoringSSL_BN_rand_range_ex(resultPtr, inclusiveMin, exclusiveMaxPtr)
                                                             ^
                                                             BN_ULONG(   )

Modifications

Change inclusiveMin param of ArbitraryPrecisionInteger.random from UInt64 to UInt.

Result

Can now build on 32-bit platforms, where BN_ULONG is uint32_t.

simonjbeaumont commented 3 months ago

/cc @finagolfin

finagolfin commented 3 months ago

Thanks, this fixed it on Android armv7 also.