apple/swift-crypto logo

apple/swift-crypto

Free

Open-source implementation of a substantial portion of the API of Apple CryptoKit suitable for use on Linux platforms.

FreeFree tier
Type
Open Source
Company
Apple

About apple/swift-crypto

Swift Crypto is an open-source implementation of a substantial portion of Apple CryptoKit's API, designed for use on Linux and Windows platforms. It provides safe, high-level Swift interfaces for cryptographic operations including key exchange, key derivation, encryption, decryption, hashing, and message authentication. On Apple platforms, it transparently delegates to the native CryptoKit. The library uses vendored copies of BoringSSL and XKCP on non-Apple platforms and also offers a CryptoExtras product with additional functionality. It is distributed via Swift Package Manager and follows cryptographic best practices to encourage safe usage.

Key Features

Key exchange (e.g., Diffie-Hellman)
Key derivation (e.g., HKDF)
Symmetric encryption and decryption
Hashing (e.g., SHA family)
Message authentication (e.g., HMAC)
Safe, high-level Swift APIs that abstract over cryptographic primitives
BoringSSL backend for Linux and Windows
XKCP backend for some primitives on non-Apple platforms
CryptoExtras product with additional functionality
Drop-in replacement for Apple CryptoKit on Apple platforms (re-exports native CryptoKit)

Pros & Cons

Pros
  • Open-source and free to use
  • Cross-platform compatibility (Linux, Windows, Apple)
  • Provides safe, high-level Swift API that encourages best practices
  • Leverages well-vetted cryptographic libraries (BoringSSL, XKCP)
  • Mirrors Apple CryptoKit API, easing development and porting
  • Available via Swift Package Manager for easy integration
Cons
  • Not a full replacement for Apple CryptoKit on Apple platforms (only a subset of APIs)
  • May have performance differences compared to hardware-backed CryptoKit on Apple hardware
  • Limited to software-based cryptography; no hardware security module support
  • Requires Swift Package Manager and Swift toolchain for integration

Best For

Cross-platform server applications requiring cryptographyBuilding secure Swift applications on Linux or WindowsIntegrating cryptographic operations without dependence on hardware featuresDeveloping frameworks or libraries that need a consistent CryptoKit API across platforms

FAQ

What platforms does Swift Crypto support?
Swift Crypto supports Linux, ARM64 Windows, and Apple platforms. On Apple platforms it re-exports the native CryptoKit, while on Linux and Windows it uses a backed implementation with BoringSSL and XKCP.
Is Swift Crypto a full replacement for Apple CryptoKit?
Swift Crypto implements a substantial portion of the CryptoKit API, but it does not include features that rely on specialized hardware not available on non-Apple platforms. It is designed to be API compatible for the subset it covers.
How does Swift Crypto work on Apple platforms?
When built for Apple platforms, Swift Crypto compiles its entire API surface down to nothing and simply re-exports Apple's CryptoKit, effectively delegating all cryptographic operations to the native implementation.
What cryptographic libraries does Swift Crypto use on Linux and Windows?
It uses a vendored copy of BoringSSL's libcrypto and a vendored copy of XKCP's libXKCP for the backing implementation.