Skip to content
main
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

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]()
let password = [UInt8]()

// 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.

About

Wrapper over CommonCrypto with alternative C implementation for Linux

Resources

License

Packages

No packages published