Skip to content

Commit

Permalink
[ios] Use tutasdk for argon2id
Browse files Browse the repository at this point in the history
Removes libargon2.a dependency
  • Loading branch information
paw-hub committed Aug 15, 2024
1 parent b959e15 commit ba3cc4f
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 111 deletions.
29 changes: 0 additions & 29 deletions app-ios/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ targets:
excludes:
[
"tutanota-web",
"Sources/Crypto/phc-winner-argon2",
"Sources/sdktest.swift",
]
compilerFlags: ["-Itutanota/Sources/Crypto/phc-winner-argon2/include"]
# XCode will not resolve symbolic links when adding a folder reference, so we will just use a relative path
- path: "../build"
name: "build"
Expand All @@ -63,7 +61,6 @@ targets:
HEADER_SEARCH_PATHS:
[
"${PROJECT_DIR}/tutanota/include",
"tutanota/Sources/Crypto/phc-winner-argon2/include",
]
CLANG_CXX_LANGUAGE_STANDARD: "gnu++14"
GCC_PREPROCESSOR_DEFINITIONS: ["SQLITE_HAS_CODEC=1", "$(inherited)"]
Expand Down Expand Up @@ -111,31 +108,6 @@ targets:
embed: false
- framework: StoreKit.framework
embed: false
- target: argon2
argon2:
type: "library.static"
settings:
PRODUCT_NAME: "argon2"
# Don't show warnings for vendored code
WARNING_CFLAGS: "-w"
sources:
- path: "tutanota/Sources/Crypto/phc-winner-argon2"
includes:
[
"src/argon2.c",
"src/core.c",
"src/encoding.c",
"src/genkat.c",
"src/ref.c",
"src/blake2/blake2b.c",
]
compilerFlags:
[
"-Itutanota/Sources/Crypto/phc-winner-argon2/include",
"-DARGON2_NO_THREADS",
"-O3",
]
platform: "iOS"
tutanotaTests:
templates: ["formatAndLint"]
type: "bundle.unit-test"
Expand All @@ -156,7 +128,6 @@ targets:
HEADER_SEARCH_PATHS:
[
"${PROJECT_DIR}/tutanota/include",
"tutanota/Sources/Crypto/phc-winner-argon2/include",
]
TEST_HOST: "$(BUILT_PRODUCTS_DIR)/Tuta D.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Tuta D"
SWIFT_OBJC_BRIDGING_HEADER: "tutanotaTests/tutanotaTests-Bridging-Header.h"
Expand Down
49 changes: 0 additions & 49 deletions app-ios/tutanota/Sources/Crypto/Argon2.swift

This file was deleted.

14 changes: 2 additions & 12 deletions app-ios/tutanota/Sources/Crypto/IosNativeCryptoFacade.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,8 @@ public actor IosNativeCryptoFacade: NativeCryptoFacade {
.wrap()
}

public func argon2idHashRaw(_ password: DataWrapper, _ salt: DataWrapper, _ timeCost: Int, _ memoryCost: Int, _ parallelism: Int, _ hashLength: Int)
async throws -> DataWrapper
{
try generateArgon2idHash(
ofPassword: password,
ofHashLength: hashLength,
withSalt: salt.data,
withIterations: UInt(timeCost),
withParallelism: UInt(parallelism),
withMemoryCost: UInt(memoryCost)
)
.wrap()
public func argon2idGeneratePassphraseKey(_ passphrase: String, _ salt: DataWrapper) async throws -> DataWrapper {
try tutasdk.argon2idGenerateKeyFromPassphrase(passphrase: passphrase, salt: salt.data).wrap()
}

public func generateKyberKeypair(_ seed: DataWrapper) async throws -> TutanotaSharedFramework.KyberKeyPair {
Expand Down
1 change: 0 additions & 1 deletion app-ios/tutanota/Sources/Crypto/phc-winner-argon2

This file was deleted.

1 change: 0 additions & 1 deletion app-ios/tutanota/Sources/tutanota-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
#import <TutanotaSharedFramework/TUTLog.h>
#import <TutanotaSharedFramework/TUTErrorFactory.h>
#import "Utils/WebviewHacks.h"
#import "argon2.h"
25 changes: 6 additions & 19 deletions app-ios/tutanotaTests/CompatibilityTestSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,20 @@ class CompatibilityTestSwift: XCTestCase {
self.testData = try JSONSerialization.jsonObject(with: jsonData) as? [String: Any]
}

func testArgon2id() {
// same parameters we use everywhere else
let ARGON2ID_HASH_LENGTH: Int = 32
let ARGON2ID_ITERATIONS: UInt = 4
let ARGON2ID_PARALLELISM: UInt = 1
let ARGON2ID_MEMORY_COST: UInt = 32 * 1024

func testArgon2id() async throws {
let facade = IosNativeCryptoFacade()
let tests = (testData!["argon2idTests"] as? [[String: String]])!
for test in tests {
let password = DataWrapper(data: TUTEncodingConverter.string(toBytes: test["password"]!))
let passphrase = test["password"]!
let expectedHash = TUTEncodingConverter.hex(toBytes: test["keyHex"]!)
let salt = TUTEncodingConverter.hex(toBytes: test["saltHex"]!)
let result = try! generateArgon2idHash(
ofPassword: password,
ofHashLength: ARGON2ID_HASH_LENGTH,
withSalt: salt,
withIterations: ARGON2ID_ITERATIONS,
withParallelism: ARGON2ID_PARALLELISM,
withMemoryCost: ARGON2ID_MEMORY_COST
)
XCTAssert(password.data.allSatisfy { $0 == 0 })
XCTAssertEqual(expectedHash, result)
let result = try! await facade.argon2idGeneratePassphraseKey(passphrase, salt.wrap())
XCTAssertEqual(expectedHash, result.data)
}
}

func testRsa() async throws {
let facade = IosNativeCryptoFacade()
let tests = (testData!["rsaEncryptionTests"] as? [[String: String]])!
for test in tests {
let publicKey = try hexToRsaPublicKey(test["publicKey"]!)
Expand All @@ -49,7 +37,6 @@ class CompatibilityTestSwift: XCTestCase {
let encResult = TUTEncodingConverter.hex(toBytes: test["result"]!)
let seed = TUTEncodingConverter.hex(toBytes: test["seed"]!)

let facade = IosNativeCryptoFacade()
let encrypted = try await facade.rsaEncrypt(publicKey, plainText.wrap(), seed.wrap())
XCTAssertEqual(encResult, encrypted.data)
let decrypted = try await facade.rsaDecrypt(privateKey, encResult.wrap())
Expand Down

0 comments on commit ba3cc4f

Please sign in to comment.