diff --git a/Package.swift b/Package.swift old mode 100755 new mode 100644 index 1f78dc5..43474ca --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.1 +// swift-tools-version:5.3 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -6,19 +6,19 @@ import PackageDescription let package = Package( name: "SwiftECC", products: [ - // Products define the executables and libraries produced by a package, and make them visible to other packages. + // Products define the executables and libraries a package produces, and make them visible to other packages. .library( name: "SwiftECC", targets: ["SwiftECC"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. - .package(url: "https://github.com/leif-ibsen/ASN1", from: "1.2.1"), + .package(url: "https://github.com/leif-ibsen/ASN1", from: "2.0.0"), .package(url: "https://github.com/leif-ibsen/BigInt", from: "1.2.5"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages which this package depends on. + // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "SwiftECC", dependencies: ["ASN1", "BigInt"]), diff --git a/README.md b/README.md index aef66a0..73df9ba 100755 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ SwiftECC requires Swift 5.0. It also requires that the Int and UInt types be 64 In your project Package.swift file add a dependency like
dependencies: [ - .package(url: "https://github.com/leif-ibsen/SwiftECC", from: "1.1.0"), + .package(url: "https://github.com/leif-ibsen/SwiftECC", from: "2.0.0"), ]

Basics

@@ -336,7 +336,7 @@ was measured on a MacBook Pro 2018, 2,2 GHz 6-Core Intel Core i7. The results ar The SwiftECC package depends on the ASN1 and BigInt packages dependencies: [ - .package(url: "https://github.com/leif-ibsen/ASN1", from: "1.2.1"), + .package(url: "https://github.com/leif-ibsen/ASN1", from: "2.0.0"), .package(url: "https://github.com/leif-ibsen/BigInt", from: "1.2.5"), ], diff --git a/Sources/SwiftECC/Domain.swift b/Sources/SwiftECC/Domain.swift index 7bcef0d..b1a7ccf 100755 --- a/Sources/SwiftECC/Domain.swift +++ b/Sources/SwiftECC/Domain.swift @@ -55,9 +55,9 @@ public class Domain: CustomStringConvertible { // MARK: - Constants /// Prime characteristic domain OID - public static let OID_P = ASN1ObjectIdentifier("1.2.840.10045.1.1") + public static let OID_P = ASN1ObjectIdentifier("1.2.840.10045.1.1")! /// Characteristic 2 domain OID - public static let OID_2 = ASN1ObjectIdentifier("1.2.840.10045.1.2") + public static let OID_2 = ASN1ObjectIdentifier("1.2.840.10045.1.2")! // MARK: Static Methods @@ -303,18 +303,6 @@ public class Domain: CustomStringConvertible { // MARK: Instance Methods - /// Doubles a curve Point - DEPRECATED, use *doublePoint* instead - /// - /// - Precondition: *self* contains *p* - /// - Parameters: - /// - p: A curve point - /// - Returns: p + p - @available(*, deprecated, message: "use doublePoint instead") - public func double(_ p: Point) -> Point { - precondition(self.contains(p)) - return self.characteristic2 ? self.domain2!.double(Point2.fromPoint(domain2!.rp, p)).toPoint() : self.domainP!.double(p) - } - /// Doubles a curve Point /// /// - Parameters: @@ -328,20 +316,6 @@ public class Domain: CustomStringConvertible { return self.characteristic2 ? self.domain2!.double(Point2.fromPoint(domain2!.rp, p)).toPoint() : self.domainP!.double(p) } - /// Adds two curve Points - DEPRECATED, use *addPoints* instead - /// - /// - Precondition: *self* contains *p1* and *self* contains *p2* - /// - Parameters: - /// - p1: The first curve point - /// - p2: The second curve point - /// - Returns: p1 + p2 - @available(*, deprecated, message: "use addPoints instead") - public func add(_ p1: Point, _ p2: Point) -> Point { - precondition(self.contains(p1)) - precondition(self.contains(p2)) - return self.characteristic2 ? self.domain2!.add(Point2.fromPoint(domain2!.rp, p1), Point2.fromPoint(domain2!.rp, p2)).toPoint() : self.domainP!.add(p1, p2) - } - /// Adds two curve Points /// /// - Parameters: @@ -356,20 +330,6 @@ public class Domain: CustomStringConvertible { return self.characteristic2 ? self.domain2!.add(Point2.fromPoint(domain2!.rp, p1), Point2.fromPoint(domain2!.rp, p2)).toPoint() : self.domainP!.add(p1, p2) } - /// Subtracts two curve Points - DEPRECATED, use *subtractPoints* instead - /// - /// - Precondition: *self* contains *p1* and *self* contains *p2* - /// - Parameters: - /// - p1: The first curve point - /// - p2: The second curve point - /// - Returns: p1 - p2 - @available(*, deprecated, message: "use subtractPoints instead") - public func subtract(_ p1: Point, _ p2: Point) -> Point { - precondition(self.contains(p1)) - precondition(self.contains(p2)) - return self.characteristic2 ? self.domain2!.subtract(Point2.fromPoint(domain2!.rp, p1), Point2.fromPoint(domain2!.rp, p2)).toPoint() : self.domainP!.subtract(p1, p2) - } - /// Subtracts two curve Points /// /// - Parameters: @@ -384,18 +344,6 @@ public class Domain: CustomStringConvertible { return self.characteristic2 ? self.domain2!.subtract(Point2.fromPoint(domain2!.rp, p1), Point2.fromPoint(domain2!.rp, p2)).toPoint() : self.domainP!.subtract(p1, p2) } - /// Negates a curve Point - DEPRECATED, use *negatePoint* instead - /// - /// - Precondition: *self* contains *p* - /// - Parameters: - /// - p: A curve point - /// - Returns: -p - @available(*, deprecated, message: "use negatePoint instead") - public func negate(_ p: Point) -> Point { - precondition(self.contains(p)) - return self.characteristic2 ? self.domain2!.negate(Point2.fromPoint(domain2!.rp, p)).toPoint() : self.domainP!.negate(p) - } - /// Negates a curve Point /// /// - Parameters: @@ -409,20 +357,6 @@ public class Domain: CustomStringConvertible { return self.characteristic2 ? self.domain2!.negate(Point2.fromPoint(domain2!.rp, p)).toPoint() : self.domainP!.negate(p) } - /// Multiplies a curve Point by an integer - DEPRECATED, use *multiplyPoint* instead - /// - /// - Precondition: *self* contains *p* - /// - Parameters: - /// - p: The curve point to multiply - /// - n: The integer to multiply with - /// - Returns: n * p - @available(*, deprecated, message: "use multiplyPoint instead") - public func multiply(_ p: Point, _ n: BInt) -> Point { - precondition(self.contains(p)) - let multiplier = n.mod(self.order) - return self.characteristic2 ? self.domain2!.multiply(Point2.fromPoint(domain2!.rp, p), multiplier).toPoint() : self.domainP!.multiply(p, multiplier) - } - /// Multiplies a curve Point by an integer /// /// - Parameters: diff --git a/Sources/SwiftECC/Domain2/EC163.swift b/Sources/SwiftECC/Domain2/EC163.swift index f8d0aec..04d7aa4 100755 --- a/Sources/SwiftECC/Domain2/EC163.swift +++ b/Sources/SwiftECC/Domain2/EC163.swift @@ -20,7 +20,7 @@ class EC163k1: Domain2 { static let gy = BInt("289070fb05d38ff58321f2e800536d538ccdaa3d9", radix: 16)! static let order = BInt("4000000000000000000020108a2e0cc0d99f8a5ef", radix: 16)! static let cofactor = 2 - static let oid = ASN1ObjectIdentifier("1.3.132.0.1") + static let oid = ASN1ObjectIdentifier("1.3.132.0.1")! init() { super.init(EC163k1.name, EC163k1.rp, EC163k1.a, EC163k1.b, EC163k1.gx, EC163k1.gy, EC163k1.order, EC163k1.cofactor, EC163k1.oid) @@ -44,7 +44,7 @@ class EC163r2: Domain2 { static let gy = BInt("0d51fbc6c71a0094fa2cdd545b11c5c0c797324f1", radix: 16)! static let order = BInt("40000000000000000000292fe77e70c12a4234c33", radix: 16)! static let cofactor = 2 - static let oid = ASN1ObjectIdentifier("1.3.132.0.15") + static let oid = ASN1ObjectIdentifier("1.3.132.0.15")! init() { super.init(EC163r2.name, EC163r2.rp, EC163r2.a, EC163r2.b, EC163r2.gx, EC163r2.gy, EC163r2.order, EC163r2.cofactor, EC163r2.oid) diff --git a/Sources/SwiftECC/Domain2/EC233.swift b/Sources/SwiftECC/Domain2/EC233.swift index bf0e6e1..9311e97 100755 --- a/Sources/SwiftECC/Domain2/EC233.swift +++ b/Sources/SwiftECC/Domain2/EC233.swift @@ -20,7 +20,7 @@ class EC233k1: Domain2 { static let gy = BInt("1db537dece819b7f70f555a67c427a8cd9bf18aeb9b56e0c11056fae6a3", radix: 16)! static let order = BInt("8000000000000000000000000000069d5bb915bcd46efb1ad5f173abdf", radix: 16)! /// The cofactor static let cofactor = 4 - static let oid = ASN1ObjectIdentifier("1.3.132.0.26") + static let oid = ASN1ObjectIdentifier("1.3.132.0.26")! init() { super.init(EC233k1.name, EC233k1.rp, EC233k1.a, EC233k1.b, EC233k1.gx, EC233k1.gy, EC233k1.order, EC233k1.cofactor, EC233k1.oid) @@ -44,7 +44,7 @@ class EC233r1: Domain2 { static let gy = BInt("1006a08a41903350678e58528bebf8a0beff867a7ca36716f7e01f81052", radix: 16)! static let order = BInt("1000000000000000000000000000013e974e72f8a6922031d2603cfe0d7", radix: 16)! static let cofactor = 2 - static let oid = ASN1ObjectIdentifier("1.3.132.0.27") + static let oid = ASN1ObjectIdentifier("1.3.132.0.27")! init() { super.init(EC233r1.name, EC233r1.rp, EC233r1.a, EC233r1.b, EC233r1.gx, EC233r1.gy, EC233r1.order, EC233r1.cofactor, EC233r1.oid) diff --git a/Sources/SwiftECC/Domain2/EC283.swift b/Sources/SwiftECC/Domain2/EC283.swift index b894a53..e791421 100755 --- a/Sources/SwiftECC/Domain2/EC283.swift +++ b/Sources/SwiftECC/Domain2/EC283.swift @@ -20,7 +20,7 @@ class EC283k1: Domain2 { static let gy = BInt("1ccda380f1c9e318d90f95d07e5426fe87e45c0e8184698e45962364e34116177dd2259", radix: 16)! static let order = BInt("1ffffffffffffffffffffffffffffffffffe9ae2ed07577265dff7f94451e061e163c61", radix: 16)! static let cofactor = 4 - static let oid = ASN1ObjectIdentifier("1.3.132.0.16") + static let oid = ASN1ObjectIdentifier("1.3.132.0.16")! init() { super.init(EC283k1.name, EC283k1.rp, EC283k1.a, EC283k1.b, EC283k1.gx, EC283k1.gy, EC283k1.order, EC283k1.cofactor, EC283k1.oid) @@ -44,7 +44,7 @@ class EC283r1: Domain2 { static let gy = BInt("3676854fe24141cb98fe6d4b20d02b4516ff702350eddb0826779c813f0df45be8112f4", radix: 16)! static let order = BInt("3ffffffffffffffffffffffffffffffffffef90399660fc938a90165b042a7cefadb307", radix: 16)! static let cofactor = 2 - static let oid = ASN1ObjectIdentifier("1.3.132.0.17") + static let oid = ASN1ObjectIdentifier("1.3.132.0.17")! init() { super.init(EC283r1.name, EC283r1.rp, EC283r1.a, EC283r1.b, EC283r1.gx, EC283r1.gy, EC283r1.order, EC283r1.cofactor, EC283r1.oid) diff --git a/Sources/SwiftECC/Domain2/EC409.swift b/Sources/SwiftECC/Domain2/EC409.swift index 67029ff..fb44b5f 100755 --- a/Sources/SwiftECC/Domain2/EC409.swift +++ b/Sources/SwiftECC/Domain2/EC409.swift @@ -20,7 +20,7 @@ class EC409k1: Domain2 { static let gy = BInt("1e369050b7c4e42acba1dacbf04299c3460782f918ea427e6325165e9ea10e3da5f6c42e9c55215aa9ca27a5863ec48d8e0286b", radix: 16)! static let order = BInt("7ffffffffffffffffffffffffffffffffffffffffffffffffffe5f83b2d4ea20400ec4557d5ed3e3e7ca5b4b5c83b8e01e5fcf", radix: 16)! static let cofactor = 4 - static let oid = ASN1ObjectIdentifier("1.3.132.0.36") + static let oid = ASN1ObjectIdentifier("1.3.132.0.36")! init() { super.init(EC409k1.name, EC409k1.rp, EC409k1.a, EC409k1.b, EC409k1.gx, EC409k1.gy, EC409k1.order, EC409k1.cofactor, EC409k1.oid) @@ -44,7 +44,7 @@ class EC409r1: Domain2 { static let gy = BInt("61b1cfab6be5f32bbfa78324ed106a7636b9c5a7bd198d0158aa4f5488d08f38514f1fdf4b4f40d2181b3681c364ba0273c706", radix: 16)! static let order = BInt("10000000000000000000000000000000000000000000000000001e2aad6a612f33307be5fa47c3c9e052f838164cd37d9a21173", radix: 16)! static let cofactor = 2 - static let oid = ASN1ObjectIdentifier("1.3.132.0.37") + static let oid = ASN1ObjectIdentifier("1.3.132.0.37")! init() { super.init(EC409r1.name, EC409r1.rp, EC409r1.a, EC409r1.b, EC409r1.gx, EC409r1.gy, EC409r1.order, EC409r1.cofactor, EC409r1.oid) diff --git a/Sources/SwiftECC/Domain2/EC571.swift b/Sources/SwiftECC/Domain2/EC571.swift index 1953071..a0dc179 100755 --- a/Sources/SwiftECC/Domain2/EC571.swift +++ b/Sources/SwiftECC/Domain2/EC571.swift @@ -20,7 +20,7 @@ class EC571k1: Domain2 { static let gy = BInt("349dc807f4fbf374f4aeade3bca95314dd58cec9f307a54ffc61efc006d8a2c9d4979c0ac44aea74fbebbb9f772aedcb620b01a7ba7af1b320430c8591984f601cd4c143ef1c7a3", radix: 16)! static let order = BInt("20000000000000000000000000000000000000000000000000000000000000000000000131850e1f19a63e4b391a8db917f4138b630d84be5d639381e91deb45cfe778f637c1001", radix: 16)! static let cofactor = 4 - static let oid = ASN1ObjectIdentifier("1.3.132.0.38") + static let oid = ASN1ObjectIdentifier("1.3.132.0.38")! init() { super.init(EC571k1.name, EC571k1.rp, EC571k1.a, EC571k1.b, EC571k1.gx, EC571k1.gy, EC571k1.order, EC571k1.cofactor, EC571k1.oid) @@ -44,7 +44,7 @@ class EC571r1: Domain2 { static let gy = BInt("37bf27342da639b6dccfffeb73d69d78c6c27a6009cbbca1980f8533921e8a684423e43bab08a576291af8f461bb2a8b3531d2f0485c19b16e2f1516e23dd3c1a4827af1b8ac15b", radix: 16)! static let order = BInt("3ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe661ce18ff55987308059b186823851ec7dd9ca1161de93d5174d66e8382e9bb2fe84e47", radix: 16)! static let cofactor = 2 - static let oid = ASN1ObjectIdentifier("1.3.132.0.39") + static let oid = ASN1ObjectIdentifier("1.3.132.0.39")! init() { super.init(EC571r1.name, EC571r1.rp, EC571r1.a, EC571r1.b, EC571r1.gx, EC571r1.gy, EC571r1.order, EC571r1.cofactor, EC571r1.oid) diff --git a/Sources/SwiftECC/DomainP/BP160.swift b/Sources/SwiftECC/DomainP/BP160.swift index 920247e..b7066bc 100755 --- a/Sources/SwiftECC/DomainP/BP160.swift +++ b/Sources/SwiftECC/DomainP/BP160.swift @@ -18,7 +18,7 @@ class BP160r1: DomainP { static let gy = BInt("1667cb477a1a8ec338f94741669c976316da6321", radix: 16)! static let order = BInt("e95e4a5f737059dc60df5991d45029409e60fc09", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.1") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.1")! init() { super.init(BP160r1.name, BP160r1.p, BP160r1.a, BP160r1.b, BP160r1.gx, BP160r1.gy, BP160r1.order, BP160r1.cofactor, BP160r1.oid) @@ -36,7 +36,7 @@ class BP160t1: DomainP { static let gy = BInt("add6718b7c7c1961f0991b842443772152c9e0ad", radix: 16)! static let order = BInt("e95e4a5f737059dc60df5991d45029409e60fc09", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.2") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.2")! init() { super.init(BP160t1.name, BP160t1.p, BP160t1.a, BP160t1.b, BP160t1.gx, BP160t1.gy, BP160t1.order, BP160t1.cofactor, BP160t1.oid) diff --git a/Sources/SwiftECC/DomainP/BP192.swift b/Sources/SwiftECC/DomainP/BP192.swift index db354fb..fefeff2 100755 --- a/Sources/SwiftECC/DomainP/BP192.swift +++ b/Sources/SwiftECC/DomainP/BP192.swift @@ -18,7 +18,7 @@ class BP192r1: DomainP { static let gy = BInt("14b690866abd5bb88b5f4828c1490002e6773fa2fa299b8f", radix: 16)! static let order = BInt("c302f41d932a36cda7a3462f9e9e916b5be8f1029ac4acc1", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.3") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.3")! init() { super.init(BP192r1.name, BP192r1.p, BP192r1.a, BP192r1.b, BP192r1.gx, BP192r1.gy, BP192r1.order, BP192r1.cofactor, BP192r1.oid) @@ -36,7 +36,7 @@ class BP192t1: DomainP { static let gy = BInt("097e2c5667c2223a902ab5ca449d0084b7e5b3de7ccc01c9", radix: 16)! static let order = BInt("c302f41d932a36cda7a3462f9e9e916b5be8f1029ac4acc1", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.4") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.4")! init() { super.init(BP192t1.name, BP192t1.p, BP192t1.a, BP192t1.b, BP192t1.gx, BP192t1.gy, BP192t1.order, BP192t1.cofactor, BP192t1.oid) diff --git a/Sources/SwiftECC/DomainP/BP224.swift b/Sources/SwiftECC/DomainP/BP224.swift index 7e6e673..8f1aab9 100755 --- a/Sources/SwiftECC/DomainP/BP224.swift +++ b/Sources/SwiftECC/DomainP/BP224.swift @@ -18,7 +18,7 @@ class BP224r1: DomainP { static let gy = BInt("58aa56f772c0726f24c6b89e4ecdac24354b9e99caa3f6d3761402cd", radix: 16)! static let order = BInt("d7c134aa264366862a18302575d0fb98d116bc4b6ddebca3a5a7939f", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.5") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.5")! init() { super.init(BP224r1.name, BP224r1.p, BP224r1.a, BP224r1.b, BP224r1.gx, BP224r1.gy, BP224r1.order, BP224r1.cofactor, BP224r1.oid) @@ -36,7 +36,7 @@ class BP224t1: DomainP { static let gy = BInt("0374e9f5143e568cd23f3f4d7c0d4b1e41c8cc0d1c6abd5f1a46db4c", radix: 16)! static let order = BInt("d7c134aa264366862a18302575d0fb98d116bc4b6ddebca3a5a7939f", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.6") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.6")! init() { super.init(BP224t1.name, BP224t1.p, BP224t1.a, BP224t1.b, BP224t1.gx, BP224t1.gy, BP224t1.order, BP224r1.cofactor, BP224t1.oid) diff --git a/Sources/SwiftECC/DomainP/BP256.swift b/Sources/SwiftECC/DomainP/BP256.swift index 2bf40e1..772d3c4 100755 --- a/Sources/SwiftECC/DomainP/BP256.swift +++ b/Sources/SwiftECC/DomainP/BP256.swift @@ -18,7 +18,7 @@ class BP256r1: DomainP { static let gy = BInt("547ef835c3dac4fd97f8461a14611dc9c27745132ded8e545c1d54c72f046997", radix: 16)! static let order = BInt("a9fb57dba1eea9bc3e660a909d838d718c397aa3b561a6f7901e0e82974856a7", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.7") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.7")! init() { super.init(BP256r1.name, BP256r1.p, BP256r1.a, BP256r1.b, BP256r1.gx, BP256r1.gy, BP256r1.order, BP256r1.cofactor, BP256r1.oid) @@ -36,7 +36,7 @@ class BP256t1: DomainP { static let gy = BInt("2d996c823439c56d7f7b22e14644417e69bcb6de39d027001dabe8f35b25c9be", radix: 16)! static let order = BInt("a9fb57dba1eea9bc3e660a909d838d718c397aa3b561a6f7901e0e82974856a7", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.8") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.8")! init() { super.init(BP256t1.name, BP256t1.p, BP256t1.a, BP256t1.b, BP256t1.gx, BP256t1.gy, BP256t1.order, BP256t1.cofactor, BP256t1.oid) diff --git a/Sources/SwiftECC/DomainP/BP320.swift b/Sources/SwiftECC/DomainP/BP320.swift index 564e9ec..e949317 100755 --- a/Sources/SwiftECC/DomainP/BP320.swift +++ b/Sources/SwiftECC/DomainP/BP320.swift @@ -18,7 +18,7 @@ class BP320r1: DomainP { static let gy = BInt("14fdd05545ec1cc8ab4093247f77275e0743ffed117182eaa9c77877aaac6ac7d35245d1692e8ee1", radix: 16)! static let order = BInt("d35e472036bc4fb7e13c785ed201e065f98fcfa5b68f12a32d482ec7ee8658e98691555b44c59311", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.9") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.9")! init() { super.init(BP320r1.name, BP320r1.p, BP320r1.a, BP320r1.b, BP320r1.gx, BP320r1.gy, BP320r1.order, BP320r1.cofactor, BP320r1.oid) @@ -36,7 +36,7 @@ class BP320t1: DomainP { static let gy = BInt("63ba3a7a27483ebf6671dbef7abb30ebee084e58a0b077ad42a5a0989d1ee71b1b9bc0455fb0d2c3", radix: 16)! static let order = BInt("d35e472036bc4fb7e13c785ed201e065f98fcfa5b68f12a32d482ec7ee8658e98691555b44c59311", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.10") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.10")! init() { super.init(BP320t1.name, BP320t1.p, BP320t1.a, BP320t1.b, BP320t1.gx, BP320t1.gy, BP320t1.order, BP320t1.cofactor, BP320t1.oid) diff --git a/Sources/SwiftECC/DomainP/BP384.swift b/Sources/SwiftECC/DomainP/BP384.swift index 8d4c3ed..20620d8 100755 --- a/Sources/SwiftECC/DomainP/BP384.swift +++ b/Sources/SwiftECC/DomainP/BP384.swift @@ -18,7 +18,7 @@ class BP384r1: DomainP { static let gy = BInt("8abe1d7520f9c2a45cb1eb8e95cfd55262b70b29feec5864e19c054ff99129280e4646217791811142820341263c5315", radix: 16)! static let order = BInt("8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b31f166e6cac0425a7cf3ab6af6b7fc3103b883202e9046565", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.11") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.11")! init() { super.init(BP384r1.name, BP384r1.p, BP384r1.a, BP384r1.b, BP384r1.gx, BP384r1.gy, BP384r1.order, BP384r1.cofactor, BP384r1.oid) @@ -36,7 +36,7 @@ class BP384t1: DomainP { static let gy = BInt("25ab056962d30651a114afd2755ad336747f93475b7a1fca3b88f2b6a208ccfe469408584dc2b2912675bf5b9e582928", radix: 16)! static let order = BInt("8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b31f166e6cac0425a7cf3ab6af6b7fc3103b883202e9046565", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.12") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.12")! init() { super.init(BP384t1.name, BP384t1.p, BP384t1.a, BP384t1.b, BP384t1.gx, BP384t1.gy, BP384t1.order, BP384t1.cofactor, BP384t1.oid) diff --git a/Sources/SwiftECC/DomainP/BP512.swift b/Sources/SwiftECC/DomainP/BP512.swift index 1db8763..f6a21b2 100755 --- a/Sources/SwiftECC/DomainP/BP512.swift +++ b/Sources/SwiftECC/DomainP/BP512.swift @@ -18,7 +18,7 @@ class BP512r1: DomainP { static let gy = BInt("7dde385d566332ecc0eabfa9cf7822fdf209f70024a57b1aa000c55b881f8111b2dcde494a5f485e5bca4bd88a2763aed1ca2b2fa8f0540678cd1e0f3ad80892", radix: 16)! static let order = BInt("aadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca70330870553e5c414ca92619418661197fac10471db1d381085ddaddb58796829ca90069", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.13") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.13")! init() { super.init(BP512r1.name, BP512r1.p, BP512r1.a, BP512r1.b, BP512r1.gx, BP512r1.gy, BP512r1.order, BP512r1.cofactor, BP512r1.oid) @@ -36,7 +36,7 @@ class BP512t1: DomainP { static let gy = BInt("5b534bd595f5af0fa2c892376c84ace1bb4e3019b71634c01131159cae03cee9d9932184beef216bd71df2dadf86a627306ecff96dbb8bace198b61e00f8b332", radix: 16)! static let order = BInt("aadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca70330870553e5c414ca92619418661197fac10471db1d381085ddaddb58796829ca90069", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.14") + static let oid = ASN1ObjectIdentifier("1.3.36.3.3.2.8.1.1.14")! init() { super.init(BP512t1.name, BP512t1.p, BP512t1.a, BP512t1.b, BP512t1.gx, BP512t1.gy, BP512t1.order, BP512t1.cofactor, BP512t1.oid) diff --git a/Sources/SwiftECC/DomainP/DomainP.swift b/Sources/SwiftECC/DomainP/DomainP.swift index bd927a5..fccf4d6 100755 --- a/Sources/SwiftECC/DomainP/DomainP.swift +++ b/Sources/SwiftECC/DomainP/DomainP.swift @@ -215,7 +215,7 @@ class DomainP { return self.oid! } - // Barrett reduction algorithm from Project Nayuki - www.nayuki.io + // Barrett reduction algorithm from Project Nayuki - https://www.nayuki.io/page/barrett-reduction-algorithm // Requires 0 <= x and x < self.p ** 2, which is the case for all invocations func reduceModP(_ x: BInt) -> BInt { assert(0 <= x && x < self.p ** 2) diff --git a/Sources/SwiftECC/DomainP/EC192.swift b/Sources/SwiftECC/DomainP/EC192.swift index e544d16..8606d30 100755 --- a/Sources/SwiftECC/DomainP/EC192.swift +++ b/Sources/SwiftECC/DomainP/EC192.swift @@ -19,7 +19,7 @@ class EC192k1: DomainP { static let gy = BInt("9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d", radix: 16)! static let order = BInt("fffffffffffffffffffffffe26f2fc170f69466a74defd8d", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.132.0.31") + static let oid = ASN1ObjectIdentifier("1.3.132.0.31")! init() { super.init(EC192k1.name, EC192k1.p, EC192k1.a, EC192k1.b, EC192k1.gx, EC192k1.gy, EC192k1.order, EC192k1.cofactor, EC192k1.oid) @@ -37,7 +37,7 @@ class EC192r1: DomainP { static let gy = BInt("07192b95ffc8da78631011ed6b24cdd573f977a11e794811", radix: 16)! static let order = BInt("ffffffffffffffffffffffff99def836146bc9b1b4d22831", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.2.840.10045.3.1.1") + static let oid = ASN1ObjectIdentifier("1.2.840.10045.3.1.1")! init() { super.init(EC192r1.name, EC192r1.p, EC192r1.a, EC192r1.b, EC192r1.gx, EC192r1.gy, EC192r1.order, EC192r1.cofactor, EC192r1.oid) diff --git a/Sources/SwiftECC/DomainP/EC224.swift b/Sources/SwiftECC/DomainP/EC224.swift index 4ab3ff0..03d9870 100755 --- a/Sources/SwiftECC/DomainP/EC224.swift +++ b/Sources/SwiftECC/DomainP/EC224.swift @@ -19,7 +19,7 @@ class EC224k1: DomainP { static let gy = BInt("7e089fed7fba344282cafbd6f7e319f7c0b0bd59e2ca4bdb556d61a5", radix: 16)! static let order = BInt("10000000000000000000000000001dce8d2ec6184caf0a971769fb1f7", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.132.0.32") + static let oid = ASN1ObjectIdentifier("1.3.132.0.32")! init() { super.init(EC224k1.name, EC224k1.p, EC224k1.a, EC224k1.b, EC224k1.gx, EC224k1.gy, EC224k1.order, EC224k1.cofactor, EC224k1.oid) @@ -37,7 +37,7 @@ class EC224r1: DomainP { static let gy = BInt("bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34", radix: 16)! static let order = BInt("ffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.132.0.33") + static let oid = ASN1ObjectIdentifier("1.3.132.0.33")! init() { super.init(EC224r1.name, EC224r1.p, EC224r1.a, EC224r1.b, EC224r1.gx, EC224r1.gy, EC224r1.order, EC224r1.cofactor, EC224r1.oid) diff --git a/Sources/SwiftECC/DomainP/EC256.swift b/Sources/SwiftECC/DomainP/EC256.swift index c29a255..81507c3 100755 --- a/Sources/SwiftECC/DomainP/EC256.swift +++ b/Sources/SwiftECC/DomainP/EC256.swift @@ -19,7 +19,7 @@ class EC256k1: DomainP { static let gy = BInt("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", radix: 16)! static let order = BInt("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.132.0.10") + static let oid = ASN1ObjectIdentifier("1.3.132.0.10")! init() { super.init(EC256k1.name, EC256k1.p, EC256k1.a, EC256k1.b, EC256k1.gx, EC256k1.gy, EC256k1.order, EC256k1.cofactor, EC256k1.oid) @@ -37,7 +37,7 @@ class EC256r1: DomainP { static let gy = BInt("4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5", radix: 16)! static let order = BInt("ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.2.840.10045.3.1.7") + static let oid = ASN1ObjectIdentifier("1.2.840.10045.3.1.7")! init() { super.init(EC256r1.name, EC256r1.p, EC256r1.a, EC256r1.b, EC256r1.gx, EC256r1.gy, EC256r1.order, EC256r1.cofactor, EC256r1.oid) diff --git a/Sources/SwiftECC/DomainP/EC384.swift b/Sources/SwiftECC/DomainP/EC384.swift index 257d55b..d0045f7 100755 --- a/Sources/SwiftECC/DomainP/EC384.swift +++ b/Sources/SwiftECC/DomainP/EC384.swift @@ -18,7 +18,7 @@ class EC384r1: DomainP { static let gy = BInt("3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f", radix: 16)! static let order = BInt("ffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.132.0.34") + static let oid = ASN1ObjectIdentifier("1.3.132.0.34")! init() { super.init(EC384r1.name, EC384r1.p, EC384r1.a, EC384r1.b, EC384r1.gx, EC384r1.gy, EC384r1.order, EC384r1.cofactor, EC384r1.oid) diff --git a/Sources/SwiftECC/DomainP/EC521.swift b/Sources/SwiftECC/DomainP/EC521.swift index daecda5..1d400c5 100755 --- a/Sources/SwiftECC/DomainP/EC521.swift +++ b/Sources/SwiftECC/DomainP/EC521.swift @@ -19,7 +19,7 @@ class EC521r1: DomainP { static let gy = BInt("11839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650", radix: 16)! static let order = BInt("1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409", radix: 16)! static let cofactor = 1 - static let oid = ASN1ObjectIdentifier("1.3.132.0.35") + static let oid = ASN1ObjectIdentifier("1.3.132.0.35")! init() { super.init(EC521r1.name, EC521r1.p, EC521r1.a, EC521r1.b, EC521r1.gx, EC521r1.gy, EC521r1.order, EC521r1.cofactor, EC521r1.oid) diff --git a/Sources/SwiftECC/PrivateKey.swift b/Sources/SwiftECC/PrivateKey.swift index aee7710..2de25f7 100755 --- a/Sources/SwiftECC/PrivateKey.swift +++ b/Sources/SwiftECC/PrivateKey.swift @@ -81,7 +81,7 @@ public class ECPrivateKey: CustomStringConvertible { // MARK: Computed Properties /// The ASN1 encoding of *self* - public var asn1: ASN1 { get { do { return ASN1Sequence().add(ASN1.ONE).add(ASN1OctetString(self.domain.align(self.s.asMagnitudeBytes()))).add(ASN1Ctx(0, [self.domain.asn1])).add(ASN1Ctx(1, [ASN1BitString(try self.domain.encodePoint(self.domain.multiplyG(self.s)), 0)])) } catch { return ASN1.NULL } } } + public var asn1: ASN1 { get { do { return ASN1Sequence().add(ASN1.ONE).add(ASN1OctetString(self.domain.align(self.s.asMagnitudeBytes()))).add(ASN1Ctx(0, [self.domain.asn1])).add(ASN1Ctx(1, [try ASN1BitString(self.domain.encodePoint(self.domain.multiplyG(self.s)), 0)])) } catch { return ASN1.NULL } } } /// The PEM base 64 encoding of *self* public var pem: String { get { return Base64.pemEncode(self.asn1.encode(), "EC PRIVATE KEY") } } /// A textual representation of the ASN1 encoding of *self* diff --git a/Sources/SwiftECC/PublicKey.swift b/Sources/SwiftECC/PublicKey.swift index e4f172c..e9a0bc6 100755 --- a/Sources/SwiftECC/PublicKey.swift +++ b/Sources/SwiftECC/PublicKey.swift @@ -92,8 +92,8 @@ public class ECPublicKey: CustomStringConvertible { // MARK: Computed Properties /// The ASN1 encoding of *self* - public var asn1: ASN1 { get { do { return ASN1Sequence().add(ASN1Sequence().add(ASN1ObjectIdentifier("1.2.840.10045.2.1")).add(self.domain.asn1)).add(ASN1BitString( - try self.domain.encodePoint(self.w), 0)) } catch { return ASN1.NULL } } } + public var asn1: ASN1 { get { do { return ASN1Sequence().add(ASN1Sequence().add(ASN1ObjectIdentifier("1.2.840.10045.2.1")!).add(self.domain.asn1)).add(try ASN1BitString( + self.domain.encodePoint(self.w), 0)) } catch { return ASN1.NULL } } } /// The PEM encoding of *self* public var pem: String { get { return Base64.pemEncode(self.asn1.encode(), "PUBLIC KEY") } } /// A textual representation of the ASN1 encoding of *self* diff --git a/Tests/SwiftECCTests/ExceptionTest.swift b/Tests/SwiftECCTests/ExceptionTest.swift index e492458..b0652ba 100755 --- a/Tests/SwiftECCTests/ExceptionTest.swift +++ b/Tests/SwiftECCTests/ExceptionTest.swift @@ -161,7 +161,7 @@ jaIqUG0ZPxgrLNoic4S+euqwVc3o6QX4JbMVy5hqAPjAPZBqwpo41MuHCeZYxKt3FOZPwQ== func testUnknownOid() { do { - let _ = try Domain.instance(oid: ASN1ObjectIdentifier("1.2.3")) + let _ = try Domain.instance(oid: ASN1ObjectIdentifier("1.2.3")!) XCTFail("Expected ECException.unknownOid") } catch ECException.unknownOid { } catch { diff --git a/docs/Classes.html b/docs/Classes.html index 45f8423..06ed453 100644 --- a/docs/Classes.html +++ b/docs/Classes.html @@ -224,7 +224,7 @@

Declaration

diff --git a/docs/Classes/Domain.html b/docs/Classes/Domain.html index bc1132c..336bf86 100644 --- a/docs/Classes/Domain.html +++ b/docs/Classes/Domain.html @@ -1017,62 +1017,6 @@

Instance Methods