Browse Source

Merge branch 'main' into feat/draft-irtf-cfrg-xchacha-03

Zsombor Szabo 2 years ago
parent
commit
b82ce81f5b

+ 3 - 0
CHANGELOG

@@ -1,3 +1,6 @@
+1.7.1
+- Address Swift 5.8 warnings
+
 1.7.0
 1.7.0
 - Fix compilation warnings
 - Fix compilation warnings
 - Ignore unknown character for base64 decoding
 - Ignore unknown character for base64 decoding

+ 3 - 0
CONTRIBUTORS.txt

@@ -3,6 +3,7 @@ organizations who have contributed source code to CryptoSwift.
 
 
 ### Contributors
 ### Contributors
 
 
+- 0xabhisek <128348758+0xabhisek@users.noreply.github.com>
 - Adolfo Martinelli <adolfo@airmap.com>
 - Adolfo Martinelli <adolfo@airmap.com>
 - Aidan Woods <aidantwoods@gmail.com>
 - Aidan Woods <aidantwoods@gmail.com>
 - Alejandro Isaza <alejandro.isaza@gmail.com>
 - Alejandro Isaza <alejandro.isaza@gmail.com>
@@ -71,10 +72,12 @@ organizations who have contributed source code to CryptoSwift.
 - Matias Cudich <mcudich@gmail.com>
 - Matias Cudich <mcudich@gmail.com>
 - Matias Piipari <matias.piipari@gmail.com>
 - Matias Piipari <matias.piipari@gmail.com>
 - Matthew Chung <matthewchung74@gmail.com>
 - Matthew Chung <matthewchung74@gmail.com>
+- Maxence Mottard <mottard.maxence@gmail.com>
 - Michael Ledin <m.ledin@appheads.ru>
 - Michael Ledin <m.ledin@appheads.ru>
 - Michael Redig <mredig@gmail.com>
 - Michael Redig <mredig@gmail.com>
 - Mikael LE GOFF <mikael@mercari.com>
 - Mikael LE GOFF <mikael@mercari.com>
 - Mo Ramezanpoor <me@mohsenr.com>
 - Mo Ramezanpoor <me@mohsenr.com>
+- Nabil Elqatib <nabilelqatib@gmail.com>
 - Nate West <nwest@detroitlabs.com>
 - Nate West <nwest@detroitlabs.com>
 - Nathan Fallet <contact@nathanfallet.me>
 - Nathan Fallet <contact@nathanfallet.me>
 - Nicholas Maccharoli <nicko@screaming-cactus.com>
 - Nicholas Maccharoli <nicko@screaming-cactus.com>

+ 1 - 1
CryptoSwift.podspec

@@ -1,6 +1,6 @@
 Pod::Spec.new do |s|
 Pod::Spec.new do |s|
   s.name         = "CryptoSwift"
   s.name         = "CryptoSwift"
-  s.version      = "1.6.0"
+  s.version      = "1.7.1"
   s.source       = { :git => "https://github.com/krzyzanowskim/CryptoSwift.git", :tag => "#{s.version}" }
   s.source       = { :git => "https://github.com/krzyzanowskim/CryptoSwift.git", :tag => "#{s.version}" }
   s.summary      = "Cryptography in Swift. SHA, MD5, CRC, PBKDF, Poly1305, HMAC, CMAC, HDKF, Scrypt, ChaCha20, Rabbit, Blowfish, AES, RSA."
   s.summary      = "Cryptography in Swift. SHA, MD5, CRC, PBKDF, Poly1305, HMAC, CMAC, HDKF, Scrypt, ChaCha20, Rabbit, Blowfish, AES, RSA."
   s.description  = "Cryptography functions and helpers for Swift implemented in Swift. SHA-1, SHA-2, SHA-3, MD5, PBKDF1, PBKDF2, Scrypt, CRC, Poly1305, HMAC, ChaCha20, Rabbit, Blowfish, AES, RSA"
   s.description  = "Cryptography functions and helpers for Swift implemented in Swift. SHA-1, SHA-2, SHA-3, MD5, PBKDF1, PBKDF2, Scrypt, CRC, Poly1305, HMAC, ChaCha20, Rabbit, Blowfish, AES, RSA"

+ 1 - 1
LICENSE

@@ -1,4 +1,4 @@
-Copyright (C) 2014-2017 Marcin Krzyżanowski <marcin.krzyzanowski@gmail.com>
+Copyright (C) 2014-3099 Marcin Krzyżanowski <marcin.krzyzanowski@gmail.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.

+ 2 - 2
README.md

@@ -129,7 +129,7 @@ It is recommended to enable [Whole-Module Optimization](https://swift.org/blog/w
 You can use [Swift Package Manager](https://swift.org/package-manager/) and specify dependency in `Package.swift` by adding this:
 You can use [Swift Package Manager](https://swift.org/package-manager/) and specify dependency in `Package.swift` by adding this:
 
 
 ```swift
 ```swift
-.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", .upToNextMajor(from: "1.7.0"))
+.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", .upToNextMajor(from: "1.7.1"))
 ```
 ```
 
 
 See: [Package.swift - manual](http://blog.krzyzanowskim.com/2016/08/09/package-swift-manual/)
 See: [Package.swift - manual](http://blog.krzyzanowskim.com/2016/08/09/package-swift-manual/)
@@ -141,7 +141,7 @@ Notice: Swift Package Manager uses debug configuration for debug Xcode build, th
 You can use [CocoaPods](https://cocoapods.org/pods/CryptoSwift).
 You can use [CocoaPods](https://cocoapods.org/pods/CryptoSwift).
 
 
 ```ruby
 ```ruby
-pod 'CryptoSwift', '~> 1.7.0'
+pod 'CryptoSwift', '~> 1.7.1'
 ```
 ```
 
 
 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.
 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.

+ 12 - 7
Sources/CryptoSwift/RSA/RSA.swift

@@ -109,7 +109,7 @@ public final class RSA: DERCodable {
     }
     }
 
 
     // Initialize
     // Initialize
-    self.init(n: n, e: e, d: d, p: p, q: q)
+    try self.init(n: n, e: e, d: d, p: p, q: q)
   }
   }
 
 
   /// Initialize with RSA parameters
   /// Initialize with RSA parameters
@@ -119,7 +119,16 @@ public final class RSA: DERCodable {
   ///   - d: The RSA Private Exponent
   ///   - d: The RSA Private Exponent
   ///   - p: The 1st Prime used to generate the Private Exponent
   ///   - p: The 1st Prime used to generate the Private Exponent
   ///   - q: The 2nd Prime used to generate the Private Exponent
   ///   - q: The 2nd Prime used to generate the Private Exponent
-  private init(n: BigUInteger, e: BigUInteger, d: BigUInteger, p: BigUInteger, q: BigUInteger) {
+  public init(n: BigUInteger, e: BigUInteger, d: BigUInteger, p: BigUInteger, q: BigUInteger) throws {
+    // Ensure the supplied parameters are correct...
+    // Calculate modulus
+    guard n == p * q else { throw Error.invalidPrimes }
+
+    // Calculate public and private exponent
+    let phi = (p - 1) * (q - 1)
+    guard d == e.inverse(phi) else { throw Error.invalidPrimes }
+
+    // Regular initialization
     self.n = n
     self.n = n
     self.e = e
     self.e = e
     self.d = d
     self.d = d
@@ -209,10 +218,6 @@ extension RSA {
     // - TODO: Support multiple primes 0x01 version defined in [RFC3447](https://www.rfc-editor.org/rfc/rfc3447#appendix-A.1.2)
     // - TODO: Support multiple primes 0x01 version defined in [RFC3447](https://www.rfc-editor.org/rfc/rfc3447#appendix-A.1.2)
     guard version == Data(hex: "0x00") else { throw Error.unsupportedRSAVersion }
     guard version == Data(hex: "0x00") else { throw Error.unsupportedRSAVersion }
 
 
-    // Ensure the supplied parameters are correct...
-    // Calculate modulus
-    guard BigUInteger(modulus) == BigUInteger(prime1) * BigUInteger(prime2) else { throw Error.invalidPrimes }
-
     // Calculate public and private exponent
     // Calculate public and private exponent
     let phi = (BigUInteger(prime1) - 1) * (BigUInteger(prime2) - 1)
     let phi = (BigUInteger(prime1) - 1) * (BigUInteger(prime2) - 1)
     guard let d = BigUInteger(publicExponent).inverse(phi) else { throw Error.invalidPrimes }
     guard let d = BigUInteger(publicExponent).inverse(phi) else { throw Error.invalidPrimes }
@@ -227,7 +232,7 @@ extension RSA {
     guard (d % (BigUInteger(prime2) - 1)) == BigUInteger(exponent2) else { throw RSA.Error.invalidPrimes }
     guard (d % (BigUInteger(prime2) - 1)) == BigUInteger(exponent2) else { throw RSA.Error.invalidPrimes }
 
 
     // Proceed with regular initialization
     // Proceed with regular initialization
-    self.init(n: BigUInteger(modulus), e: BigUInteger(publicExponent), d: BigUInteger(privateExponent), p: BigUInteger(prime1), q: BigUInteger(prime2))
+    try self.init(n: BigUInteger(modulus), e: BigUInteger(publicExponent), d: BigUInteger(privateExponent), p: BigUInteger(prime1), q: BigUInteger(prime2))
   }
   }
 
 
   /// Attempts to instantiate an RSA Key when given the ASN1 DER encoded external representation of the Key
   /// Attempts to instantiate an RSA Key when given the ASN1 DER encoded external representation of the Key

+ 4 - 0
Sources/CryptoSwift/Scrypt.swift

@@ -121,7 +121,11 @@ private extension Scrypt {
 
 
     /* 1: X <-- B */
     /* 1: X <-- B */
     let typedBlock = block.assumingMemoryBound(to: UInt32.self)
     let typedBlock = block.assumingMemoryBound(to: UInt32.self)
+#if compiler(>=5.8)
+    X.update(from: typedBlock, count: 32 * self.r)
+#else
     X.assign(from: typedBlock, count: 32 * self.r)
     X.assign(from: typedBlock, count: 32 * self.r)
+#endif
 
 
     /* 2: for i = 0 to N - 1 do */
     /* 2: for i = 0 to N - 1 do */
     for i in stride(from: 0, to: self.N, by: 2) {
     for i in stride(from: 0, to: self.N, by: 2) {

+ 2 - 0
Sources/CryptoSwift/String+Extension.swift

@@ -13,6 +13,8 @@
 //  - This notice may not be removed or altered from any source or binary distribution.
 //  - This notice may not be removed or altered from any source or binary distribution.
 //
 //
 
 
+import Foundation
+
 /** String extension */
 /** String extension */
 extension String {
 extension String {
 
 

+ 1 - 1
config/Project-Shared.xcconfig

@@ -1,4 +1,4 @@
-MARKETING_VERSION = 1.7.0
+MARKETING_VERSION = 1.7.1
 
 
 SUPPORTED_PLATFORMS = iphonesimulator iphoneos macosx appletvos watchos appletvsimulator watchsimulator
 SUPPORTED_PLATFORMS = iphonesimulator iphoneos macosx appletvos watchos appletvsimulator watchsimulator