Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzanowskim committed Oct 15, 2017
2 parents d3352f9 + 77efdc9 commit d0084e4
Show file tree
Hide file tree
Showing 44 changed files with 647 additions and 650 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
0.8.0
- Adds SHA3 Keccak variants
- Adds String.bytes helper to convert String to array of bytes
- Improves AES performance
- Speeds up compilation times with Swift 4
- Fixes: Blowfish minimum key size is 5
- Removes Ciphers "iv" parameter (value moved to BlockMode)
- BlockMode uses associated value for IV value where apply e.g. .CBC(iv: ivbytes)
- Refactors internal hacks no longer needed with Swift 4

0.7.2
- Adds Padding enum (.pkcs5, .pkcs7, .noPadding, .zeroPadding)
- Removes Generics from the public API.
Expand Down
4 changes: 2 additions & 2 deletions CryptoSwift.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Digest.sha1(bytes)
//: Digest calculated incrementally
do {
var digest = MD5()
let _ = try digest.update(withBytes: [0x31, 0x32])
let _ = try digest.update(withBytes: [0x33])
_ = try digest.update(withBytes: [0x31, 0x32])
_ = try digest.update(withBytes: [0x33])
let result = try digest.finish()
print(result)
} catch {}
Expand Down
6 changes: 3 additions & 3 deletions CryptoSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Pod::Spec.new do |s|
s.name = "CryptoSwift"
s.version = "0.7.2"
s.version = "0.8.0"
s.source = { :git => "https://github.com/krzyzanowskim/CryptoSwift.git", :tag => "#{s.version}" }
s.summary = "Cryptography in Swift. SHA, MD5, CRC, PBKDF, Poly1305, HMAC, ChaCha20, Rabbit, Blowfish, AES."
s.description = "Cryptography functions and helpers for Swift implemented in Swift. SHA, MD5, PBKDF1, PBKDF2, CRC, Poly1305, HMAC, ChaCha20, Rabbit, Blowfish, AES."
s.description = "Cryptography functions and helpers for Swift implemented in Swift. SHA-1, SHA-2, SHA-3, MD5, PBKDF1, PBKDF2, CRC, Poly1305, HMAC, ChaCha20, Rabbit, Blowfish, AES"
s.homepage = "https://github.com/krzyzanowskim/CryptoSwift"
s.license = {:type => "Attribution License", :file => "LICENSE"}
s.authors = {'Marcin Krzyżanowski' => 'marcin@krzyzanowskim.com'}
Expand All @@ -14,5 +14,5 @@ Pod::Spec.new do |s|
s.tvos.deployment_target = "9.0"
s.source_files = "Sources/CryptoSwift/**/*.swift"
s.requires_arc = true
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '4.0', 'SWIFT_OPTIMIZATION_LEVEL' => '-Owholemodule', 'SWIFT_DISABLE_SAFETY_CHECKS' => 'YES', 'GCC_UNROLL_LOOPS' => 'YES'}
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '4.0', 'SWIFT_OPTIMIZATION_LEVEL' => '-Owholemodule', 'SWIFT_DISABLE_SAFETY_CHECKS' => 'YES', 'SWIFT_ENFORCE_EXCLUSIVE_ACCESS' => 'compile-time', 'GCC_UNROLL_LOOPS' => 'YES'}
end
29 changes: 16 additions & 13 deletions CryptoSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
750509991F6BEF2A00394A1B /* PKCS7.swift in Sources */ = {isa = PBXBuildFile; fileRef = 750509981F6BEF2A00394A1B /* PKCS7.swift */; };
750CC3EB1DC0CACE0096BE6E /* BlowfishTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 750CC3EA1DC0CACE0096BE6E /* BlowfishTests.swift */; };
75100F8F19B0BC890005C5F5 /* Poly1305Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75100F8E19B0BC890005C5F5 /* Poly1305Tests.swift */; };
751EE9781F93996100161FFC /* AES.Cryptors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 751EE9771F93996100161FFC /* AES.Cryptors.swift */; };
753B33011DAB84D600D06422 /* RandomBytesSequenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 753B33001DAB84D600D06422 /* RandomBytesSequenceTests.swift */; };
75482EA41CB310B7001F66A5 /* PBKDF.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75482EA31CB310B7001F66A5 /* PBKDF.swift */; };
754BE46819693E190098E6F3 /* DigestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 754BE46719693E190098E6F3 /* DigestTests.swift */; };
Expand Down Expand Up @@ -156,6 +157,7 @@
750509981F6BEF2A00394A1B /* PKCS7.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PKCS7.swift; sourceTree = "<group>"; };
750CC3EA1DC0CACE0096BE6E /* BlowfishTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlowfishTests.swift; sourceTree = "<group>"; };
75100F8E19B0BC890005C5F5 /* Poly1305Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Poly1305Tests.swift; sourceTree = "<group>"; };
751EE9771F93996100161FFC /* AES.Cryptors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AES.Cryptors.swift; sourceTree = "<group>"; };
753B33001DAB84D600D06422 /* RandomBytesSequenceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RandomBytesSequenceTests.swift; sourceTree = "<group>"; };
75482EA31CB310B7001F66A5 /* PBKDF.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PBKDF.swift; sourceTree = "<group>"; };
754BE45519693E190098E6F3 /* CryptoSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CryptoSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -285,6 +287,7 @@
754BE46419693E190098E6F3 /* Tests */ = {
isa = PBXGroup;
children = (
E3FD2D511D6B813C00A9F35F /* Error+Extension.swift */,
754BE46719693E190098E6F3 /* DigestTests.swift */,
75100F8E19B0BC890005C5F5 /* Poly1305Tests.swift */,
758A94271A65C59200E46135 /* HMACTests.swift */,
Expand All @@ -299,7 +302,6 @@
75C2E76C1D55F097003D2BCA /* Access.swift */,
756BFDCA1A82B87300B9D9A4 /* Bridging.h */,
754BE46519693E190098E6F3 /* Supporting Files */,
E3FD2D511D6B813C00A9F35F /* Error+Extension.swift */,
);
name = Tests;
path = Tests/CryptoSwiftTests;
Expand Down Expand Up @@ -327,6 +329,7 @@
isa = PBXGroup;
children = (
75EC52381EE8B6CA0048EB3B /* AES.swift */,
751EE9771F93996100161FFC /* AES.Cryptors.swift */,
75EC52391EE8B6CA0048EB3B /* Array+Extension.swift */,
75EC523A1EE8B6CA0048EB3B /* Authenticator.swift */,
75EC523B1EE8B6CA0048EB3B /* BatchedCollection.swift */,
Expand All @@ -345,7 +348,6 @@
75EC52521EE8B6CA0048EB3B /* Foundation */,
75EC525C1EE8B6CA0048EB3B /* Generics.swift */,
75EC525D1EE8B6CA0048EB3B /* HMAC.swift */,
75EC525F1EE8B6CA0048EB3B /* Int+Extension.swift */,
75EC52611EE8B6CA0048EB3B /* MD5.swift */,
75EC52621EE8B6CA0048EB3B /* NoPadding.swift */,
75EC52631EE8B6CA0048EB3B /* Operators.swift */,
Expand All @@ -360,10 +362,11 @@
75EC52701EE8B6CA0048EB3B /* SHA2.swift */,
75EC52711EE8B6CA0048EB3B /* SHA3.swift */,
75EC52721EE8B6CA0048EB3B /* String+Extension.swift */,
75EC525F1EE8B6CA0048EB3B /* Int+Extension.swift */,
75EC52761EE8B6CA0048EB3B /* UInt8+Extension.swift */,
75EC52731EE8B6CA0048EB3B /* UInt16+Extension.swift */,
75EC52741EE8B6CA0048EB3B /* UInt32+Extension.swift */,
75EC52751EE8B6CA0048EB3B /* UInt64+Extension.swift */,
75EC52761EE8B6CA0048EB3B /* UInt8+Extension.swift */,
75EC52771EE8B6CA0048EB3B /* Updatable.swift */,
75EC52781EE8B6CA0048EB3B /* Utils.swift */,
75EC52791EE8B6CA0048EB3B /* ZeroPadding.swift */,
Expand Down Expand Up @@ -578,6 +581,7 @@
75EC52891EE8B8170048EB3B /* OFB.swift in Sources */,
75EC52831EE8B8170048EB3B /* BlockModeOptions.swift in Sources */,
75EC52961EE8B8200048EB3B /* Blowfish+Foundation.swift in Sources */,
751EE9781F93996100161FFC /* AES.Cryptors.swift in Sources */,
75EC528B1EE8B8170048EB3B /* RandomAccessBlockModeWorker.swift in Sources */,
75EC527D1EE8B8130048EB3B /* Array+Extension.swift in Sources */,
75EC52B31EE8B83D0048EB3B /* UInt16+Extension.swift in Sources */,
Expand Down Expand Up @@ -689,13 +693,13 @@
CODE_SIGNING_REQUIRED = NO;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand All @@ -713,7 +717,6 @@
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = CryptoSwift;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx appletvos watchos appletvsimulator watchsimulator";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
Expand Down Expand Up @@ -751,6 +754,7 @@
CODE_SIGNING_REQUIRED = NO;
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -769,7 +773,6 @@
METAL_ENABLE_DEBUG_INFO = NO;
PRODUCT_NAME = CryptoSwift;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx appletvos watchos appletvsimulator watchsimulator";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
Expand All @@ -793,10 +796,11 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
OTHER_SWIFT_FLAGS = "-Xfrontend -debug-time-function-bodies";
PRODUCT_BUNDLE_IDENTIFIER = com.krzyzanowskim.CryptoSwift;
PRODUCT_NAME = CryptoSwift;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
Expand Down Expand Up @@ -824,7 +828,9 @@
PRODUCT_NAME = CryptoSwift;
SKIP_INSTALL = YES;
SWIFT_DISABLE_SAFETY_CHECKS = YES;
SWIFT_ENFORCE_EXCLUSIVE_ACCESS = "compile-time";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
Expand All @@ -835,10 +841,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
"includes/**",
Expand Down Expand Up @@ -903,6 +905,7 @@
CODE_SIGNING_REQUIRED = NO;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -924,7 +927,6 @@
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = CryptoSwift;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx appletvos watchos appletvsimulator watchsimulator";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
Expand All @@ -946,7 +948,6 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_BITCODE = YES;
"ENABLE_BITCODE[sdk=macosx*]" = NO;
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_UNROLL_LOOPS = YES;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
Expand All @@ -956,7 +957,9 @@
PRODUCT_NAME = CryptoSwift;
SKIP_INSTALL = YES;
SWIFT_DISABLE_SAFETY_CHECKS = YES;
SWIFT_ENFORCE_EXCLUSIVE_ACCESS = "compile-time";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
SWIFT_VERSION = 4.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
disableMainThreadChecker = "YES"
language = ""
systemAttachmentLifetime = "keepNever"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand Down
12 changes: 6 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import PackageDescription

let _ = Package(name: "CryptoSwift", products: [.library(name: "CryptoSwift", targets: ["CryptoSwift"])],
targets: [
.target(name:"CryptoSwift"),
.testTarget(name:"CryptoSwiftTests",dependencies:["CryptoSwift"])
],
swiftLanguageVersions: [4])
_ = Package(name: "CryptoSwift", products: [.library(name: "CryptoSwift", targets: ["CryptoSwift"])],
targets: [
.target(name: "CryptoSwift"),
.testTarget(name: "CryptoSwiftTests", dependencies: ["CryptoSwift"]),
],
swiftLanguageVersions: [4])
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ also check [Playground](/CryptoSwift.playground/Contents.swift)
import CryptoSwift
```

CryptoSwift uses array of bytes aka `Array<UInt8>` as a base type for all operations. Every data may be converted to a stream of bytes. You will find convenience functions that accept String or NSData, and it will be internally converted to the array of bytes.
CryptoSwift uses array of bytes aka `Array<UInt8>` as a base type for all operations. Every data may be converted to a stream of bytes. You will find convenience functions that accept `String` or `Data`, and it will be internally converted to the array of bytes.

##### Data types conversion

For you convenience **CryptoSwift** provides two functions to easily convert array of bytes to NSData and another way around:
For you convenience **CryptoSwift** provides two functions to easily convert array of bytes to `Data` and another way around:

Data from bytes:

Expand All @@ -213,7 +213,7 @@ let hex = bytes.toHexString() // "010203"

Build bytes out of `String`
```swift
let bytes = Array("string".utf8)
let bytes: Array<UInt8> = "password".bytes // Array("password".utf8)
```

Also... check out helpers that work with **Base64** encoded data:
Expand Down Expand Up @@ -255,7 +255,7 @@ do {
Hashing a String and printing result

```swift
let hash = "123".md5()
let hash = "123".md5() // "123".bytes.md5()
```

##### Calculate CRC
Expand Down Expand Up @@ -312,8 +312,8 @@ let decrypted = try Rabbit(key: key, iv: iv).decrypt(encrypted)
##### Blowfish

```swift
let encrypted = try Blowfish(key: key, iv: iv, blockMode: .CBC, padding: .pkcs7).encrypt(message)
let decrypted = try Blowfish(key: key, iv: iv, blockMode: .CBC, padding: .pkcs7).decrypt(encrypted)
let encrypted = try Blowfish(key: key, blockMode: .CBC(iv: iv), padding: .pkcs7).encrypt(message)
let decrypted = try Blowfish(key: key, blockMode: .CBC(iv: iv), padding: .pkcs7).decrypt(encrypted)
```

##### AES
Expand All @@ -328,7 +328,7 @@ Variant of AES encryption (AES-128, AES-192, AES-256) depends on given key lengt

AES-256 example
```swift
try AES(key: [1,2,3,...,32], iv: [1,2,3,...,16], blockMode: .CBC, padding: .pkcs7)
try AES(key: [1,2,3,...,32], blockMode: .CBC(iv: [1,2,3,...,16]), padding: .pkcs7)
```

###### All at once
Expand Down Expand Up @@ -371,8 +371,8 @@ let key: Array<UInt8> = [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
let iv: Array<UInt8> = AES.randomIV(AES.blockSize)

do {
let encrypted = try AES(key: key, iv: iv, blockMode: .CBC, padding: .pkcs7).encrypt(input)
let decrypted = try AES(key: key, iv: iv, blockMode: .CBC, padding: .pkcs7).decrypt(encrypted)
let encrypted = try AES(key: key, blockMode: .CBC(iv: iv), padding: .pkcs7).encrypt(input)
let decrypted = try AES(key: key, blockMode: .CBC(iv: iv), padding: .pkcs7).decrypt(encrypted)
} catch {
print(error)
}
Expand All @@ -382,7 +382,7 @@ AES without data padding

```swift
let input: Array<UInt8> = [0,1,2,3,4,5,6,7,8,9]
let encrypted: Array<UInt8> = try! AES(key: "secret0key000000", iv:"0123456789012345", blockMode: .CBC, padding: .noPadding).encrypt(input)
let encrypted: Array<UInt8> = try! AES(key: Array("secret0key000000".utf8), blockMode: .CBC(iv: Array("0123456789012345".utf8)), padding: .noPadding).encrypt(input)
```

Using convenience extensions
Expand Down
Loading

0 comments on commit d0084e4

Please sign in to comment.