Swiftpack.co -  tesseract-one/UncommonCrypto.swift as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
tesseract-one/UncommonCrypto.swift
Wrapper over CommonCrypto with alternative C implementation for Linux
.package(url: "https://github.com/tesseract-one/UncommonCrypto.swift.git", from: "0.1.1")

UncommonCrypto.swift

🐧 linux: ready GitHub license Build Status GitHub release SPM compatible CocoaPods version Platform macOS | iOS | tvOS | watchOS | Linux

Wrapper over CommonCrypto with alternative C implementation for Linux.

Alternative C implementations copied from trezor-crypto repository.

Installation

UncommonCrypto.swift deploys to macOS, iOS, tvOS, watchOS and Linux. It has been tested on the latest OS releases only however, as the module uses very few platform-provided APIs, there should be very few issues with earlier versions.

UncommonCrypto.swift can be ported to more platforms. If OS has built-in crypto APIs they can be used instead of provided C versions. On Apple plaforms library uses CommonCrypto framework. Secure random generator should be ported too.

Setup instructions:

  • Swift Package Manager: Add this to the dependency section of your Package.swift manifest:

    .package(url: "https://github.com/tesseract-one/UncommonCrypto.swift.git", from: "0.1.0")
    
  • CocoaPods: Put this in your Podfile:

    pod 'UncommonCrypto', '~> 0.1'
    

Usage Examples

SHA1

import UncommonCrypto

// Some data
let data = Data()

// Simple call API
let hash1 = SHA1.hash(data: data)

// Streaming api
var sha1 = SHA1()
sha1.update(data)
let hash2 = sha1.finalize()

assert(hash1 == hash2)

SHA2

import UncommonCrypto

// Some data
let data = Data()

// Simple call API. SHA256 and SHA512 are supported
let hash1 = SHA2.hash(type: .sha256, data: data)

// Streaming api
var sha2 = SHA2(type: .sha256)
sha2.update(data)
let hash2 = sha2.finalize()

assert(hash1 == hash2)

SHA3

import UncommonCrypto

// Some data
let data = Data()

// Simple call API. Different Keccak and SHA3 variants supported.
let hash1 = SHA3.hash(type: .sha256, data: data)

// Streaming api
var sha3 = SHA3(type: .sha256)
sha3.update(data)
let hash2 = sha3.finalize()

assert(hash1 == hash2)

PBKDF2

import UncommonCrypto

let salt = [UInt8](https://raw.github.com/tesseract-one/UncommonCrypto.swift/main/)
let password = [UInt8](https://raw.github.com/tesseract-one/UncommonCrypto.swift/main/)

// SHA512 or SHA256 HMAC can be used
let derived = try! PBKDF2.derive(type: .sha512, password: password, salt: salt) 

print("Derived: ", derived)

License

UncommonCrypto.swift can be used, distributed and modified under the Apache 2.0 license.

GitHub

link
Stars: 0
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

SHA2 optimization
3 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API