Skip to content

Commit

Permalink
Lipsticks
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyzanowskim committed Oct 4, 2019
1 parent c91564c commit 939a3d7
Show file tree
Hide file tree
Showing 37 changed files with 224 additions and 215 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @krzyzanowskim
* @krzyzanowskim
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- CryptoSwift version:
- Swift version:
- Platform (iOS/macOS/Linux/...):
- Installation method (CocoaPods/Carthage/SPM/...):
- CryptoSwift version:
- Swift version:
- Platform (iOS/macOS/Linux/...):
- Installation method (CocoaPods/Carthage/SPM/...):
- Project name:

# Description
Expand Down
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1.
1.

**Sample code**

Expand All @@ -23,9 +23,9 @@ Steps to reproduce the behavior:


**Environment (please complete the following information):**
- Swift version:
- Platform (iOS/macOS/Linux/...):
- Installation method (CocoaPods/Carthage/SPM/...):
- Swift version:
- Platform (iOS/macOS/Linux/...):
- Installation method (CocoaPods/Carthage/SPM/...):
- Project name:

**Additional context**
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Checklist:
- [ ] Tests added.

Changes proposed in this pull request:
-
-
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 19.3b0
hooks:
- id: black
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0
5.0
2 changes: 1 addition & 1 deletion CNAME
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cryptoswift.io
cryptoswift.io
1 change: 0 additions & 1 deletion CryptoSwift-TestHostApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {


}

2 changes: 1 addition & 1 deletion CryptoSwift.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos' display-mode='rendered'>
<timeline fileName='timeline.xctimeline'/>
</playground>
</playground>
6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Copyright (C) 2014-2017 Marcin Krzyżanowski <[email protected]>
This software is provided 'as-is', without any express or implied warranty.
This software is provided 'as-is', without any express or implied warranty.

In no event will the authors be held liable for any damages arising from the use of this software.
In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

- The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation is required.
- Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
- This notice may not be removed or altered from any source or binary distribution.
- Redistributions of any form whatsoever must retain the following acknowledgment: 'This product includes software developed by the "Marcin Krzyzanowski" (http://krzyzanowskim.com/).'
- Redistributions of any form whatsoever must retain the following acknowledgment: 'This product includes software developed by the "Marcin Krzyzanowski" (http://krzyzanowskim.com/).'
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Check out [CONTRIBUTING.md](CONTRIBUTING.md) for more information on how to help
To install CryptoSwift, add it as a submodule to your project (on the top level project directory):

git submodule add https://github.com/krzyzanowskim/CryptoSwift.git

It is recommended to enable [Whole-Module Optimization](https://swift.org/blog/whole-module-optimizations/) to gain better performance. Non-optimized build results in significantly worse performance.

#### Embedded Framework
Expand Down Expand Up @@ -160,8 +160,8 @@ pod 'CryptoSwift', :git => "https://github.com/krzyzanowskim/CryptoSwift", :bran

Bear in mind that CocoaPods will build CryptoSwift without [Whole-Module Optimization](https://swift.org/blog/whole-module-optimizations/) that may impact performance. You can change it manually after installation, or use [cocoapods-wholemodule](https://github.com/jedlewison/cocoapods-wholemodule) plugin.

#### Carthage
You can use [Carthage](https://github.com/Carthage/Carthage).
#### Carthage
You can use [Carthage](https://github.com/Carthage/Carthage).
Specify in Cartfile:

```ruby
Expand All @@ -170,8 +170,8 @@ github "krzyzanowskim/CryptoSwift"

Run `carthage` to build the framework and drag the built CryptoSwift.framework into your Xcode project. Follow [build instructions](https://github.com/Carthage/Carthage#getting-started). [Common issues](https://github.com/krzyzanowskim/CryptoSwift/issues/492#issuecomment-330822874).

#### Accio
You can use [Accio](https://github.com/JamitLabs/Accio).
#### Accio
You can use [Accio](https://github.com/JamitLabs/Accio).
Specify in Package.swift:

```swift
Expand Down Expand Up @@ -211,7 +211,7 @@ dependencies: [
See: [Package.swift - manual](http://blog.krzyzanowskim.com/2016/08/09/package-swift-manual/)

---

## How-to

* [Basics (data types, conversion, ...)](#basics)
Expand Down Expand Up @@ -290,7 +290,7 @@ let hash = data.sha1()
let hash = data.sha224()
let hash = data.sha256()
let hash = data.sha384()
let hash = data.sha512()
let hash = data.sha512()
```
```swift
do {
Expand All @@ -300,7 +300,7 @@ do {
let result = try digest.finish()
} catch { }
```

Hashing a String and printing result

```swift
Expand Down Expand Up @@ -356,7 +356,7 @@ let key = try HKDF(password: password, salt: salt, variant: .sha256).calculate()


##### Data Padding

Some content-encryption algorithms assume the input length is a multiple of `k` octets, where `k` is greater than one. For such algorithms, the input shall be padded.

```swift
Expand Down Expand Up @@ -409,7 +409,7 @@ do {

###### Incremental updates

Incremental operations use instance of Cryptor and encrypt/decrypt one part at a time, this way you can save on memory for large files.
Incremental operations use instance of Cryptor and encrypt/decrypt one part at a time, this way you can save on memory for large files.

```swift
do {
Expand Down Expand Up @@ -443,9 +443,9 @@ do {
let decrypted = try AES(key: key, blockMode: CBC(iv: iv), padding: .pkcs7).decrypt(encrypted)
} catch {
print(error)
}
}
```

AES without data padding

```swift
Expand All @@ -454,7 +454,7 @@ let encrypted: Array<UInt8> = try! AES(key: Array("secret0key000000".utf8), bloc
```

Using convenience extensions

```swift
let plain = Data( [0x01, 0x02, 0x03])
let encrypted = try! plain.encrypt(ChaCha20(key: key, iv: iv))
Expand Down Expand Up @@ -532,9 +532,9 @@ This distribution includes cryptographic software. The country in which you curr
## License

Copyright (C) 2014-2017 Marcin Krzyżanowski <marcin@krzyzanowskim.com>
This software is provided 'as-is', without any express or implied warranty.
This software is provided 'as-is', without any express or implied warranty.

In no event will the authors be held liable for any damages arising from the use of this software.
In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

Expand Down
2 changes: 1 addition & 1 deletion Sources/CryptoSwift/BlockDecryptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class BlockDecryptor: Cryptor, Updatable {
for var chunk in accumulatedWithoutSuffix.batched(by: blockSize) {
if isLast || (accumulatedWithoutSuffix.count - processedBytesCount) >= blockSize {
let isLastChunk = processedBytesCount + chunk.count == accumulatedWithoutSuffix.count

if isLast, isLastChunk, var finalizingWorker = worker as? FinalizingDecryptModeWorker {
chunk = try finalizingWorker.willDecryptLast(bytes: chunk + accumulated.suffix(worker.additionalBufferSize)) // tag size
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/CryptoSwift/BlockMode/GCM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class GCM: BlockMode {
private let iv: Array<UInt8>
private let additionalAuthenticatedData: Array<UInt8>?
private let mode: Mode

/// Length of authentication tag, in bytes.
/// For encryption, the value is given as init parameter.
/// For decryption, the lenght of given authentication tag is used.
Expand Down Expand Up @@ -126,7 +126,7 @@ final class GCMModeWorker: BlockModeWorker, FinalizingEncryptModeWorker, Finaliz
} else {
self.additionalBufferSize = 0
}

// Assume nonce is 12 bytes long, otherwise initial counter would be calulated from GHASH
// counter = GF.ghash(aad: [UInt8](), ciphertext: nonce)
if iv.count == GCMModeWorker.nonceSize {
Expand Down
2 changes: 1 addition & 1 deletion Sources/CryptoSwift/ChaCha20.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ extension ChaCha20 {

extension ChaCha20: Cryptors {
//TODO: Use BlockEncryptor/BlockDecryptor

public func makeEncryptor() -> Cryptor & Updatable {
return ChaCha20.ChaChaEncryptor(chacha: self)
}
Expand Down
26 changes: 13 additions & 13 deletions Tests/Tests/AESTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ final class AESTests: XCTestCase {
do {
let aes = try AES(key: key, blockMode: CTR(iv: iv), padding: .noPadding)
var encryptor = try aes.makeEncryptor()

let encrypted1 = try encryptor.update(withBytes: [0x00, 0x01, 0x02, 0x03] as [UInt8])
XCTAssertEqual(encrypted1, Array<UInt8>(hex: "d79d0344"))
let encrypted2 = try encryptor.update(withBytes: [0x04, 0x05, 0x06, 0x07] as [UInt8])
Expand Down Expand Up @@ -521,69 +521,69 @@ extension AESTests {
XCTAssertEqual(Array(encrypted), [UInt8](hex: "")) // C
XCTAssertEqual(gcm.authenticationTag, [UInt8](hex: "0xcd33b28ac773f74ba00ed1f312572435")) // T (128-bit)
}

func testAESGCMTagLengthDetached() {
// Test Case 2
let key = Array<UInt8>(hex: "0x00000000000000000000000000000000")
let plaintext = Array<UInt8>(hex: "0x00000000000000000000000000000000")
let iv = Array<UInt8>(hex: "0x000000000000000000000000")

let gcm = GCM(iv: iv, tagLength: 12, mode: .detached)
let aes = try! AES(key: key, blockMode: gcm, padding: .noPadding)
let encrypted = try! aes.encrypt(plaintext)
XCTAssertEqual(Array(encrypted), [UInt8](hex: "0388dace60b6a392f328c2b971b2fe78")) // C
XCTAssertEqual(gcm.authenticationTag, [UInt8](hex: "ab6e47d42cec13bdf53a67b2")) // T (96-bit)

// decrypt
func decrypt(_ encrypted: Array<UInt8>) -> Array<UInt8> {
let decGCM = GCM(iv: iv, authenticationTag: gcm.authenticationTag!, mode: .detached)
let aes = try! AES(key: key, blockMode: decGCM, padding: .noPadding)
return try! aes.decrypt(encrypted)
}

let decrypted = decrypt(encrypted)
XCTAssertEqual(decrypted, plaintext)
}

func testAESGCMTagLengthCombined() {
// Test Case 2
let key = Array<UInt8>(hex: "0x00000000000000000000000000000000")
let plaintext = Array<UInt8>(hex: "0x00000000000000000000000000000000")
let iv = Array<UInt8>(hex: "0x000000000000000000000000")

let gcm = GCM(iv: iv, tagLength: 12, mode: .combined)
let aes = try! AES(key: key, blockMode: gcm, padding: .noPadding)
let encrypted = try! aes.encrypt(plaintext)
XCTAssertEqual(Array(encrypted), [UInt8](hex: "0388dace60b6a392f328c2b971b2fe78ab6e47d42cec13bdf53a67b2")) // C
XCTAssertEqual(gcm.authenticationTag, [UInt8](hex: "ab6e47d42cec13bdf53a67b2")) // T (96-bit)

// decrypt
func decrypt(_ encrypted: Array<UInt8>) -> Array<UInt8> {
let decGCM = GCM(iv: iv, authenticationTag: gcm.authenticationTag!, mode: .combined)
let aes = try! AES(key: key, blockMode: decGCM, padding: .noPadding)
return try! aes.decrypt(encrypted)
}

let decrypted = decrypt(encrypted)
XCTAssertEqual(decrypted, plaintext)
}

func testAESGCMTagLengthCombined2() {
let key = Array<UInt8>(hex: "0x00000000000000000000000000000000")
let plaintext = Array<UInt8>(hex: "0x0000000000000000000000000000000000000000")
let iv = Array<UInt8>(hex: "0x000000000000")

let gcm = GCM(iv: iv, tagLength: 12, mode: .combined)
let aes = try! AES(key: key, blockMode: gcm, padding: .noPadding)
let encrypted = try! aes.encrypt(plaintext)

// decrypt
func decrypt(_ encrypted: Array<UInt8>) -> Array<UInt8> {
let decGCM = GCM(iv: iv, authenticationTag: gcm.authenticationTag!, mode: .combined)
let aes = try! AES(key: key, blockMode: decGCM, padding: .noPadding)
return try! aes.decrypt(encrypted)
}

let decrypted = decrypt(encrypted)
XCTAssertEqual(decrypted, plaintext)
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/Tests/ScryptTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import XCTest

class Scrypt: XCTestCase {

func testScrypt_0() {
let password = Array("password".data(using: .ascii)!)
let salt = Array("NaCl".data(using: .ascii)!)
Expand All @@ -31,7 +31,7 @@ class Scrypt: XCTestCase {
""".replacingOccurrences(of: " ", with: "").replacingOccurrences(of: "\n", with: "").replacingOccurrences(of: "\t", with: ""))
XCTAssertEqual(derived, expected)
}

func testScrypt_1() {
let password = Array("pleaseletmein".data(using: .ascii)!)
let salt = Array("SodiumChloride".data(using: .ascii)!)
Expand All @@ -45,7 +45,7 @@ class Scrypt: XCTestCase {
""".replacingOccurrences(of: " ", with: "").replacingOccurrences(of: "\n", with: "").replacingOccurrences(of: "\t", with: ""))
XCTAssertEqual(derived, expected)
}

// Takes too long to run in debug mode!
func testScrypt_2() {
#if !DEBUG
Expand All @@ -62,7 +62,7 @@ class Scrypt: XCTestCase {
XCTAssertEqual(derived, expected)
#endif
}

static let allTests = [
("testScrypt_0", testScrypt_0),
("testScrypt_1", testScrypt_1),
Expand Down
2 changes: 1 addition & 1 deletion Tests/Tests/ScryptTestsPerf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ScryptTestsPeft: XCTestCase {
_ = try! CryptoSwift.Scrypt(password: password, salt: salt, dkLen: 64, N: N, r: 8, p: 1).calculate()
}
}

}

extension ScryptTestsPeft {
Expand Down
Loading

0 comments on commit 939a3d7

Please sign in to comment.