Swiftpack.co - tesseract-one/UncommonCrypto.swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by tesseract-one.
tesseract-one/UncommonCrypto.swift 0.1.3
Wrapper over CommonCrypto with alternative C implementation for Linux
⭐️ 0
🕓 43 weeks ago
.package(url: "https://github.com/tesseract-one/UncommonCrypto.swift.git", from: "0.1.3")

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)

HMAC

import UncommonCrypto

// Some data
let data = Data()

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

// Simple call API. SHA256 and SHA512 are supported
let sign1 = HMAC.authenticate(type: .sha256, key: key, data: data)

// Streaming api
var hmac = HMAC(type: .sha256, key: key)
hmac.update(data)
let sign2 = hmac.finalize()

assert(sign1 == sign2)

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: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Proper HMAC naming
43 weeks ago

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