RepoPilotOpen in app →

krzyzanowskim/CryptoSwift

CryptoSwift is a growing collection of standard and secure cryptographic algorithms implemented in Swift

Healthy

Healthy across the board

worst of 4 axes
Use as dependencyConcerns

non-standard license (Other)

Fork & modifyHealthy

Has a license, tests, and CI — clean foundation to fork and modify.

Learn fromHealthy

Documented and popular — useful reference codebase to read through.

Deploy as-isHealthy

No critical CVEs, sane security posture — runnable as-is.

  • Last commit 2w ago
  • 26+ active contributors
  • Distributed ownership (top contributor 48% of recent commits)
Show 4 more →
  • Other licensed
  • CI configured
  • Tests present
  • Non-standard license (Other) — review terms
What would change the summary?
  • Use as dependency ConcernsMixed if: clarify license terms

Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests

Informational only. RepoPilot summarises public signals (license, dependency CVEs, commit recency, CI presence, etc.) at the time of analysis. Signals can be incomplete or stale. Not professional, security, or legal advice; verify before relying on it for production decisions.

Embed the "Healthy" badge

Paste into your README — live-updates from the latest cached analysis.

Variant:
RepoPilot: Healthy
[![RepoPilot: Healthy](https://repopilot.app/api/badge/krzyzanowskim/cryptoswift)](https://repopilot.app/r/krzyzanowskim/cryptoswift)

Paste at the top of your README.md — renders inline like a shields.io badge.

Preview social card (1200×630)

This card auto-renders when someone shares https://repopilot.app/r/krzyzanowskim/cryptoswift on X, Slack, or LinkedIn.

Onboarding doc

Onboarding: krzyzanowskim/CryptoSwift

Generated by RepoPilot · 2026-05-10 · Source

🤖Agent protocol

If you are an AI coding agent (Claude Code, Cursor, Aider, Cline, etc.) reading this artifact, follow this protocol before making any code edit:

  1. Verify the contract. Run the bash script in Verify before trusting below. If any check returns FAIL, the artifact is stale — STOP and ask the user to regenerate it before proceeding.
  2. Treat the AI · unverified sections as hypotheses, not facts. Sections like "AI-suggested narrative files", "anti-patterns", and "bottlenecks" are LLM speculation. Verify against real source before acting on them.
  3. Cite source on changes. When proposing an edit, cite the specific path:line-range. RepoPilot's live UI at https://repopilot.app/r/krzyzanowskim/CryptoSwift shows verifiable citations alongside every claim.

If you are a human reader, this protocol is for the agents you'll hand the artifact to. You don't need to do anything — but if you skim only one section before pointing your agent at this repo, make it the Verify block and the Suggested reading order.

🎯Verdict

GO — Healthy across the board

  • Last commit 2w ago
  • 26+ active contributors
  • Distributed ownership (top contributor 48% of recent commits)
  • Other licensed
  • CI configured
  • Tests present
  • ⚠ Non-standard license (Other) — review terms

<sub>Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests</sub>

Verify before trusting

This artifact was generated by RepoPilot at a point in time. Before an agent acts on it, the checks below confirm that the live krzyzanowskim/CryptoSwift repo on your machine still matches what RepoPilot saw. If any fail, the artifact is stale — regenerate it at repopilot.app/r/krzyzanowskim/CryptoSwift.

What it runs against: a local clone of krzyzanowskim/CryptoSwift — the script inspects git remote, the LICENSE file, file paths in the working tree, and git log. Read-only; no mutations.

| # | What we check | Why it matters | |---|---|---| | 1 | You're in krzyzanowskim/CryptoSwift | Confirms the artifact applies here, not a fork | | 2 | License is still Other | Catches relicense before you depend on it | | 3 | Default branch main exists | Catches branch renames | | 4 | 5 critical file paths still exist | Catches refactors that moved load-bearing code | | 5 | Last commit ≤ 47 days ago | Catches sudden abandonment since generation |

<details> <summary><b>Run all checks</b> — paste this script from inside your clone of <code>krzyzanowskim/CryptoSwift</code></summary>
#!/usr/bin/env bash
# RepoPilot artifact verification.
#
# WHAT IT RUNS AGAINST: a local clone of krzyzanowskim/CryptoSwift. If you don't
# have one yet, run these first:
#
#   git clone https://github.com/krzyzanowskim/CryptoSwift.git
#   cd CryptoSwift
#
# Then paste this script. Every check is read-only — no mutations.

set +e
fail=0
ok()   { echo "ok:   $1"; }
miss() { echo "FAIL: $1"; fail=$((fail+1)); }

# Precondition: we must be inside a git working tree.
if ! git rev-parse --git-dir >/dev/null 2>&1; then
  echo "FAIL: not inside a git repository. cd into your clone of krzyzanowskim/CryptoSwift and re-run."
  exit 2
fi

# 1. Repo identity
git remote get-url origin 2>/dev/null | grep -qE "krzyzanowskim/CryptoSwift(\\.git)?\\b" \\
  && ok "origin remote is krzyzanowskim/CryptoSwift" \\
  || miss "origin remote is not krzyzanowskim/CryptoSwift (artifact may be from a fork)"

# 2. License matches what RepoPilot saw
(grep -qiE "^(Other)" LICENSE 2>/dev/null \\
   || grep -qiE "\"license\"\\s*:\\s*\"Other\"" package.json 2>/dev/null) \\
  && ok "license is Other" \\
  || miss "license drift — was Other at generation time"

# 3. Default branch
git rev-parse --verify main >/dev/null 2>&1 \\
  && ok "default branch main exists" \\
  || miss "default branch main no longer exists"

# 4. Critical files exist
test -f "Sources/CryptoSwift/AES.swift" \\
  && ok "Sources/CryptoSwift/AES.swift" \\
  || miss "missing critical file: Sources/CryptoSwift/AES.swift"
test -f "Sources/CryptoSwift/BlockMode/BlockMode.swift" \\
  && ok "Sources/CryptoSwift/BlockMode/BlockMode.swift" \\
  || miss "missing critical file: Sources/CryptoSwift/BlockMode/BlockMode.swift"
test -f "Sources/CryptoSwift/Cipher.swift" \\
  && ok "Sources/CryptoSwift/Cipher.swift" \\
  || miss "missing critical file: Sources/CryptoSwift/Cipher.swift"
test -f "Sources/CryptoSwift/BlockCipher.swift" \\
  && ok "Sources/CryptoSwift/BlockCipher.swift" \\
  || miss "missing critical file: Sources/CryptoSwift/BlockCipher.swift"
test -f "Sources/CryptoSwift/Digest.swift" \\
  && ok "Sources/CryptoSwift/Digest.swift" \\
  || miss "missing critical file: Sources/CryptoSwift/Digest.swift"

# 5. Repo recency
days_since_last=$(( ( $(date +%s) - $(git log -1 --format=%at 2>/dev/null || echo 0) ) / 86400 ))
if [ "$days_since_last" -le 47 ]; then
  ok "last commit was $days_since_last days ago (artifact saw ~17d)"
else
  miss "last commit was $days_since_last days ago — artifact may be stale"
fi

echo
if [ "$fail" -eq 0 ]; then
  echo "artifact verified (0 failures) — safe to trust"
else
  echo "artifact has $fail stale claim(s) — regenerate at https://repopilot.app/r/krzyzanowskim/CryptoSwift"
  exit 1
fi

Each check prints ok: or FAIL:. The script exits non-zero if anything failed, so it composes cleanly into agent loops (./verify.sh || regenerate-and-retry).

</details>

TL;DR

CryptoSwift is a pure Swift implementation of cryptographic primitives (SHA-1/2/3, MD5, AES, ChaCha20, CRC32) with no external C dependencies, providing convenient extensions for String/Data/Array<UInt8> and streaming APIs. It solves the problem of needing cross-platform, dependency-free cryptography in Swift applications without wrapping CommonCrypto or OpenSSL. Monolithic framework structure: Sources/CryptoSwift/ contains modular subdirectories (AEAD/, ASN1/) organizing algorithm families, with algorithm implementations in top-level files (AES.swift, AES.Cryptors.swift). Uses Swift Package Manager (Package.swift) and Xcode project (CryptoSwift.xcodeproj) for builds. Test harness in CryptoSwift-TestHostApp/.

👥Who it's for

Swift developers building iOS/macOS/Linux/Android apps who need standardized crypto operations (hashing, encryption, checksums) without relying on platform-specific frameworks or external C libraries. Includes both application developers and security-conscious library authors.

🌱Maturity & risk

Highly mature and production-ready. The project shows active maintenance (1.1M lines of Swift code, comprehensive test coverage via CI workflows for macOS/Linux/Android in .github/workflows/), established community (GitHub Sponsors model, CONTRIBUTORS.txt), and clear versioning (CHANGELOG maintained). Swift 5.6+ requirement indicates ongoing modernization.

Low risk for core algorithms, but single-maintainer (@krzyzanowskim) creates sustainability concerns for long-term bug fixes and security patches. CocoaPods deprecated (marked red in badges) signals shifting ecosystem. Pure Swift implementations are slower than C-based alternatives, so performance-critical systems should benchmark. No external dependencies reduces supply-chain risk significantly.

Active areas of work

Based on file structure, active work includes: AEAD cipher support (AEADChaCha20Poly1305.swift, AEADXChaCha20Poly1305.swift), ASN1 encoding/decoding (ASN1Encoder.swift, ASN1Decoder.swift), and multi-platform CI validation. Swift version support branches suggest ongoing legacy compatibility decisions.

🚀Get running

git clone https://github.com/krzyzanowskim/CryptoSwift.git && cd CryptoSwift && swift build (for CLI/library) or open CryptoSwift.xcodeproj && Product > Build (in Xcode). SPM users: add .package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.8.0") to Package.swift.

Daily commands: Development: swift build in repo root. Tests: swift test or xcodebuild -scheme Tests -destination 'platform=macOS'. Performance tests: xcodebuild -scheme TestsPerformance-Mac. See Makefile for additional targets (Makefile exists but not detailed in structure).

🗺️Map of the codebase

  • Sources/CryptoSwift/AES.swift — Core AES block cipher implementation—foundational for multiple encryption modes and essential reference for understanding the cipher abstraction pattern used throughout.
  • Sources/CryptoSwift/BlockMode/BlockMode.swift — Abstract protocol defining the block cipher mode interface (CBC, CTR, GCM, etc.); all mode-of-operation implementations depend on this contract.
  • Sources/CryptoSwift/Cipher.swift — High-level encryption/decryption API entry point that orchestrates ciphers with modes and padding; most user-facing code flows through here.
  • Sources/CryptoSwift/BlockCipher.swift — Protocol defining the low-level block cipher contract (encrypt/decrypt single blocks); all cipher implementations (AES, Blowfish, ChaCha20) conform to this.
  • Sources/CryptoSwift/Digest.swift — Hashing API entry point; provides factory and composition for hash algorithms (SHA, HMAC, etc.) used in authentication and key derivation.
  • Sources/CryptoSwift/CS_BigInt/BigInt.swift — Arbitrary-precision integer arithmetic core; required for RSA, ECC, and cryptographic number theory operations.
  • Package.swift — Swift Package Manager manifest defining module structure, platform targets (iOS, macOS, Linux, Android), and build configuration.

🛠️How to make changes

Add a new block cipher (e.g., Twofish)

  1. Create a new file Sources/CryptoSwift/Twofish.swift conforming to BlockCipher protocol (Sources/CryptoSwift/BlockCipher.swift)
  2. Implement encrypt(_:withKey:) and decrypt(_:withKey:) methods, plus blockSize property (Sources/CryptoSwift/Twofish.swift)
  3. Update Cipher.swift or factory methods to instantiate Twofish with the new key parameter (Sources/CryptoSwift/Cipher.swift)
  4. Add test cases in the test suite (e.g., known test vectors) to validate encrypt/decrypt round-trips (Tests (not listed, but standard location))

Add a new block mode (e.g., CFB variant)

  1. Create Sources/CryptoSwift/BlockMode/CFB_NewVariant.swift conforming to BlockMode protocol (Sources/CryptoSwift/BlockMode/BlockMode.swift)
  2. Implement makeEncryptor(with:) and makeDecryptor(with:) returning CipherModeWorker instances (Sources/CryptoSwift/BlockMode/CipherModeWorker.swift)
  3. Follow the pattern in CFB.swift (or CBC.swift) for IV handling and block-chaining logic (Sources/CryptoSwift/BlockMode/CFB.swift)
  4. Register the mode in any top-level factory/enum that offers mode selection (Sources/CryptoSwift/Cipher.swift)

Add a new hash algorithm (e.g., Blake3)

  1. Create Sources/CryptoSwift/Blake3.swift conforming to Digest protocol (or similar checksum interface) (Sources/CryptoSwift/Digest.swift)
  2. Implement update(_:) and finalize() for incremental hashing, and blockSize/digestSize properties (Sources/CryptoSwift/Checksum.swift)
  3. If creating a MAC variant, also add a Blake3HMAC.swift conforming to Authenticator (Sources/CryptoSwift/Authenticator.swift)
  4. Add unit tests with known test vectors (NIST or Blake3 test suite) (Tests (not listed))

Add an AEAD cipher (e.g., AES-GCM variant)

  1. Create Sources/CryptoSwift/AEAD/AEADMyVariant.swift conforming to AEAD protocol (Sources/CryptoSwift/AEAD/AEAD.swift)
  2. Implement encrypt(key:plaintext:associatedData:nonce:) and matching decrypt(...) method (Sources/CryptoSwift/AEAD/AEADChaCha20Poly1305.swift)
  3. Reuse existing authentication tag computation (Poly1305, or GCM from BlockMode/GCM.swift) (Sources/CryptoSwift/BlockMode/GCM.swift)
  4. Document nonce/key size constraints and add comprehensive test vectors (Tests (not listed))

🪤Traps & gotchas

Pure Swift implementations are 5-10x slower than C-based alternatives (CommonCrypto, OpenSSL) — benchmark before shipping performance-critical paths. ASN1Decoder may fail silently on malformed input without detailed error context. No constant-time guarantees documented for timing-attack resistance. Swift version branches (legacy support) can cause dependency resolution confusion if using older SPM versions. Incremental API (streaming) requires manual state management — easy to misuse by reusing state across unrelated operations.

🏗️Architecture

💡Concepts to learn

  • AEAD (Authenticated Encryption with Associated Data) — CryptoSwift implements ChaCha20-Poly1305 and XChaCha20-Poly1305 AEAD ciphers; understanding this pattern is essential because naive encryption + authentication composition is cryptographically unsafe
  • Block cipher modes (ECB, CBC, CTR, GCM, etc.) — AES.swift implements multiple modes of operation; using ECB is insecure, and mode selection directly impacts security and performance trade-offs in this library
  • ASN.1 Distinguished Encoding Rules (DER) — ASN1Encoder.swift and ASN1Decoder.swift handle DER, the binary format for X.509 certificates and PKCS structures; required for importing/exporting cryptographic keys
  • Padding schemes (PKCS#7, no padding) — Block ciphers require padding; incorrect padding implementation is a common source of padding oracle attacks and plaintext leakage in CryptoSwift implementations
  • Incremental/streaming hashing — CryptoSwift supports update()-style APIs for large files without loading into memory; this is non-obvious in pure Swift without C bindings
  • XChaCha20 extended nonce (192-bit) — CryptoSwift's AEADXChaCha20Poly1305.swift solves the nonce-reuse problem of standard ChaCha20 by extending nonce length; critical for high-volume random nonce scenarios
  • Constant-time comparison — MAC/tag verification must use constant-time comparison to prevent timing attacks; CryptoSwift needs this for AEAD but implementation timing guarantees are undocumented
  • apple/swift-crypto — Official Apple cryptography library for Swift, wraps secure enclave and CommonCrypto; direct alternative with platform backing but less portable
  • twostraws/CryptoKit — High-level Swift wrapper around native crypto; complements CryptoSwift for developers who prefer Apple's native implementations
  • jedisct1/libsodium — Battle-tested C crypto library that inspired many CryptoSwift API patterns; reference for secure defaults and constant-time implementations
  • vapor/crypto — Server-side Swift framework that wraps CryptoSwift for web applications; primary consumer ecosystem for pure-Swift crypto
  • insidegui/KeychainAccess — Complementary iOS library for secure credential storage; used alongside CryptoSwift for complete key management workflows

🪄PR ideas

To work on one of these in Claude Code or Cursor, paste: Implement the "<title>" PR idea from CLAUDE.md, working through the checklist as the task list.

Add comprehensive test coverage for AEAD modes (ChaCha20Poly1305 and XChaCha20Poly1305)

The AEAD directory contains AEADChaCha20Poly1305.swift and AEADXChaCha20Poly1305.swift, but there's no visible corresponding test files in the file structure. AEAD modes are critical for authenticated encryption and require extensive test vectors (NIST test vectors, RFC 7539 test vectors). This would ensure correctness and security of these widely-used algorithms.

  • [ ] Create Tests/CryptoSwift/AEAD/ directory if it doesn't exist
  • [ ] Add AEADChaCha20Poly1305Tests.swift with RFC 7539 Section 2.8.2 test vectors
  • [ ] Add AEADXChaCha20Poly1305Tests.swift with extended nonce test vectors
  • [ ] Include edge cases: empty plaintext, empty AAD, wrong authentication tag rejection
  • [ ] Add performance benchmarks for AEAD operations

Add block mode integration tests for all cipher modes against test vectors

The BlockMode directory has CBC, CCM, CFB, CTR, ECB, GCM, OCB, and OFB implementations, but without visible comprehensive test coverage. Each mode needs validation against NIST SP 800-38 test vectors and edge cases (various IV sizes, plaintext lengths, etc.). This is critical security infrastructure.

  • [ ] Create Tests/CryptoSwift/BlockMode/ directory structure
  • [ ] Add NistTestVector.swift helper to parse and validate NIST SP 800-38 vectors
  • [ ] Add tests for each mode (CBC, CTR, GCM, etc.) with official test vectors
  • [ ] Test edge cases: empty input, single block, non-aligned lengths
  • [ ] Add tests for mode-specific failures (invalid IV size, tag validation for GCM/CCM/OCB)

Create ASN1 encoding/decoding roundtrip tests with real-world certificate and key structures

The ASN1 module (ASN1.swift, ASN1Decoder.swift, ASN1Encoder.swift, ASN1Scanner.swift) lacks visible test coverage for roundtrip encoding/decoding. ASN1 is fundamental for cryptographic key and certificate handling, and errors here cause serious security issues. Tests should validate encoding/decoding of X.509 certificates, PKCS#8 keys, and other real structures.

  • [ ] Create Tests/CryptoSwift/ASN1/ directory
  • [ ] Add ASN1RoundtripTests.swift testing encode->decode->encode consistency
  • [ ] Add tests decoding real X.509 certificate samples (from test fixtures)
  • [ ] Add PKCS#8 private key encoding/decoding tests
  • [ ] Add edge case tests: deeply nested structures, maximum length encoding, invalid tag handling

🌿Good first issues

  • Add comprehensive documentation to Sources/CryptoSwift/ASN1/ASN1Encoder.swift with examples showing how to encode common key formats (PKCS#8, SubjectPublicKeyInfo). Currently ASN1 support is sparse and underdocumented.: ASN1 is critical for interop but lacks usage examples, blocking new contributors from understanding the API
  • Create performance benchmarking tests comparing CryptoSwift algorithms against platform defaults (CommonCrypto on Apple, OpenSSL on Linux) in TestsPerformance-Mac.xcscheme and add Linux equivalent. Currently only Mac performance tests exist.: Users need data on performance trade-offs of pure Swift vs. C; missing Linux benchmarks create parity gap
  • Extend the CryptoSwift-TestHostApp to demonstrate streaming SHA256/AES updates on large files, with before/after memory usage. Current app is minimal and doesn't showcase incremental API.: Streaming APIs are powerful but under-documented; a working demo would clarify memory-efficient patterns for new users

Top contributors

Click to expand

📝Recent commits

Click to expand
  • f2a627b — README: remove Emerge Tools listing; set Premium Sponsors to None (krzyzanowskim)
  • 351d250 — CI: drop Swift -Xfrontend solver-memory-threshold override from macOS/Linux tests (krzyzanowskim)
  • 0e458fd — Release 1.10.0: refresh README (requirements, SPM, defaults, examples) and add (krzyzanowskim)
  • 2491896 — Bump version to 1.10.0 across podspec, README, and project config (krzyzanowskim)
  • a423c18 — Add test asserting XChaCha20-Poly1305 nonce length metadata matches XChaCha20 (krzyzanowskim)
  • 454c2b8 — Point PrivacyInfo.xcprivacy to CryptoSwiftResources in podspec and project (krzyzanowskim)
  • c89bf0b — Merge pull request #1084 from james-kwong/fixXChaChaIVLen (krzyzanowskim)
  • e690f44 — ChaCha20: add convenience init with explicit 4-byte counter; add QUIC tests (krzyzanowskim)
  • 93a3bd4 — Prefer FoundationEssentials when available; fall back to Foundation (krzyzanowskim)
  • 17e6b20 — Make privacy manifest Apple-only via new resources target; add visionOS/macCatalyst (krzyzanowskim)

🔒Security observations

CryptoSwift is a well-structured cryptographic library with generally sound architecture. The primary security concerns relate to the inherent risks of pure Swift cryptographic implementations without platform-specific optimizations, and custom mathematical implementations that could be vulnerable to side-channel attacks. The project demonstrates good security practices with modern block modes (GCM, CTR) and AEAD support. However, the lack of a visible security policy and potential for timing attacks in pure software implementations are areas requiring attention. The codebase appears to be actively maintained and well-documented, which is positive for long-term security maintenance.

  • Medium · Pure Swift Cryptographic Implementation Risks — Sources/CryptoSwift/ (entire cryptographic implementation). CryptoSwift is a pure Swift implementation of cryptographic algorithms without leveraging native/platform-specific secure cryptographic libraries. While the project implements standard algorithms, pure software implementations may be more susceptible to side-channel attacks (timing attacks, cache attacks) compared to hardware-accelerated or platform-provided cryptographic functions. Fix: Consider leveraging platform-specific secure cryptographic APIs where available (e.g., CryptoKit on Apple platforms). Implement constant-time operations for sensitive comparisons. Conduct regular security audits and side-channel analysis. Document the security limitations of the pure Swift implementation clearly.
  • Low · Custom BigInt Implementation — Sources/CryptoSwift/CS_BigInt/. The codebase includes a custom BigInt implementation (Sources/CryptoSwift/CS_BigInt/) for cryptographic operations. Custom implementations of complex mathematical operations can introduce subtle bugs that compromise security, especially in encryption/decryption operations. Fix: Ensure the BigInt implementation undergoes rigorous testing and formal verification where possible. Consider using well-tested third-party libraries. Implement constant-time operations for cryptographic operations involving BigInt. Add comprehensive unit tests for edge cases.
  • Low · Lack of Visible Security Policy — Repository root. No SECURITY.md file is visible in the repository structure, which is a best practice for projects handling cryptographic code. Users and security researchers need clear guidance on reporting vulnerabilities responsibly. Fix: Create a SECURITY.md file that includes: vulnerability disclosure policy, security contact information, supported versions receiving security updates, and procedures for reporting security issues responsibly.
  • Low · Missing Deprecation Warnings for Weak Algorithms — Sources/CryptoSwift/BlockMode/ECB.swift, Sources/CryptoSwift/AES.swift. Based on the file structure showing support for ECB, CBC, and other older block modes/ciphers, there may not be clear deprecation warnings for cryptographically weak combinations (e.g., ECB mode, single DES equivalents). Fix: Add clear deprecation warnings and documentation for weak cipher modes (e.g., ECB). Provide migration guidance to stronger alternatives (e.g., GCM, CTR). Consider adding runtime warnings when weak modes are used in production builds.

LLM-derived; treat as a starting point, not a security audit.


Generated by RepoPilot. Verdict based on maintenance signals — see the live page for receipts. Re-run on a new commit to refresh.

Healthy signals · krzyzanowskim/CryptoSwift — RepoPilot