Skip to content

Commit

Permalink
Replace PBKDF2 implementation with the swift-crypto version (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovetodream authored Oct 29, 2024
1 parent 9c65ded commit 6b6bca8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 361 deletions.
12 changes: 6 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "21f7878f2b39d46fd8ba2b06459ccb431cdf876c",
"version" : "3.8.1"
"revision" : "8fa345c2081cfbd4851dffff5dd5bed48efe6081",
"version" : "3.9.0"
}
},
{
Expand All @@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "f7dc3f527576c398709b017584392fb58592e7f5",
"version" : "2.75.0"
"revision" : "914081701062b11e3bb9e21accc379822621995e",
"version" : "2.76.1"
}
},
{
Expand All @@ -77,8 +77,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "dbace16f126fdcd80d58dc54526c561ca17327d7",
"version" : "1.22.0"
"revision" : "bbd5e63cf949b7db0c9edaf7a21e141c52afe214",
"version" : "1.23.0"
}
},
{
Expand Down
6 changes: 2 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-nio.git", from: "2.67.0"),
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.21.0"),
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.27.0"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "3.4.0"),
.package(url: "https://github.com/apple/swift-crypto.git", "3.9.0"..<"5.0.0"),
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.3"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.2.0"),
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.6.0"),
Expand All @@ -34,8 +34,6 @@ let package = Package(
],
path: "Sources/VendoredConnectionPoolModule"
),
.target(name: "_PBKDF2", dependencies: [.product(name: "Crypto", package: "swift-crypto")]),
.testTarget(name: "_PBKDF2Tests", dependencies: ["_PBKDF2"]),
.target(
name: "OracleNIO",
dependencies: [
Expand All @@ -49,7 +47,7 @@ let package = Package(
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "_CryptoExtras", package: "swift-crypto"),
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
"_PBKDF2", "_ConnectionPoolModule",
"_ConnectionPoolModule",
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
Expand Down
12 changes: 9 additions & 3 deletions Sources/OracleNIO/Helper/Crypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import Crypto
import RegexBuilder
import _CryptoExtras
import _PBKDF2

import struct Foundation.Data

Expand Down Expand Up @@ -48,8 +47,15 @@ func encryptCBC(_ key: [UInt8], _ plainText: [UInt8], zeros: Bool = false) throw
}

func getDerivedKey(key: Data, salt: [UInt8], length: Int, iterations: Int) throws -> [UInt8] {
Array(
try PBKDF2<SHA512>.calculate(length: length, password: key, salt: salt, rounds: iterations))
try KDF.Insecure.PBKDF2.deriveKey(
from: key,
salt: salt,
using: .sha512,
outputByteCount: length,
unsafeUncheckedRounds: iterations
).withUnsafeBytes { bytes in
Array(bytes)
}
}

/// Returns a signed version of the given payload (used for Oracle IAM token authentication) in base64
Expand Down
179 changes: 0 additions & 179 deletions Sources/_PBKDF2/PBKDF2.swift

This file was deleted.

Loading

0 comments on commit 6b6bca8

Please sign in to comment.