Skip to content

Commit

Permalink
Release 2.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
leif-ibsen committed Sep 15, 2024
1 parent 27f656f commit 9f5af60
Show file tree
Hide file tree
Showing 269 changed files with 291 additions and 523 deletions.
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/leif-ibsen/BigInt", from: "1.17.0"),
.package(url: "https://github.com/leif-ibsen/ASN1", from: "2.5.0"),
.package(url: "https://github.com/leif-ibsen/Digest", from: "1.6.0"),
.package(url: "https://github.com/leif-ibsen/BigInt", from: "1.19.0"),
.package(url: "https://github.com/leif-ibsen/ASN1", from: "2.6.0"),
.package(url: "https://github.com/leif-ibsen/Digest", from: "1.8.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
165 changes: 0 additions & 165 deletions Sources/SwiftHPKE/Base64.swift

This file was deleted.

5 changes: 0 additions & 5 deletions Sources/SwiftHPKE/Exception.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public enum HPKEException: Error, CustomStringConvertible {
/// Textual description of `self`
public var description: String {
switch self {
case .base64:
return "Base64 decoding exception"
case .asn1Structure:
return "ASN1 structure is wrong"
case .pemStructure:
Expand All @@ -38,9 +36,6 @@ public enum HPKEException: Error, CustomStringConvertible {
}
}

/// Base64 decoding exception
case base64

/// ASN1 structure is wrong
case asn1Structure

Expand Down
6 changes: 5 additions & 1 deletion Sources/SwiftHPKE/PrivateKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import ASN1
import BigInt
import Digest

public struct PrivateKey: CustomStringConvertible, Equatable {

Expand Down Expand Up @@ -146,7 +147,10 @@ public struct PrivateKey: CustomStringConvertible, Equatable {
/// - pem: The PEM encoding of the key
/// - Throws: An exception if the PEM encoding is wrong
public init(pem: String) throws {
try self.init(der: Base64.pemDecode(pem, "PRIVATE KEY"))
guard let der = Base64.pemDecode(pem, "PRIVATE KEY") else {
throw HPKEException.pemStructure
}
try self.init(der: der)
}


Expand Down
6 changes: 5 additions & 1 deletion Sources/SwiftHPKE/PublicKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import ASN1
import BigInt
import Digest

public struct PublicKey: CustomStringConvertible, Equatable {

Expand Down Expand Up @@ -143,7 +144,10 @@ public struct PublicKey: CustomStringConvertible, Equatable {
/// - pem: The PEM encoding of the key
/// - Throws: An exception if the PEM encoding is wrong
public init(pem: String) throws {
try self.init(der: Base64.pemDecode(pem, "PUBLIC KEY"))
guard let der = Base64.pemDecode(pem, "PUBLIC KEY") else {
throw HPKEException.pemStructure
}
try self.init(der: der)
}


Expand Down
15 changes: 7 additions & 8 deletions Sources/SwiftHPKE/SwiftHPKE.docc/Articles/KeyManagement.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ import SwiftHPKE
let pubKeyPem =
"""
-----BEGIN PUBLIC KEY-----
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEQW/MahMwMTFjwY95uOEdfBVC7HrQhTGG
TwxiPlgDiARqC6y6EQ1Ajkuhe4A02WOltRYQRXKytzspOR25UfgtagURAwxVFYzR
9cmi6FRmvvq/Tsigd/dAi4FNjniR7/Pg
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEQW/MahMwMTFjwY95uOEdfBVC7HrQhTGGTwxiPlgDiARq
C6y6EQ1Ajkuhe4A02WOltRYQRXKytzspOR25UfgtagURAwxVFYzR9cmi6FRmvvq/Tsigd/dAi4FN
jniR7/Pg
-----END PUBLIC KEY-----
"""
let pubKey = try PublicKey(pem: pubKeyPem)
Expand All @@ -55,11 +55,10 @@ let pubKey = try PublicKey(pem: pubKeyPem)
let privKeyPem =
"""
-----BEGIN PRIVATE KEY-----
MIG/AgEAMBAGByqGSM49AgEGBSuBBAAiBIGnMIGkAgEBBDBmpNziSYmGoWwl7apJ
M9ZdDBxkJqmxMScHGXG45ZQXSv7fIuJlsSwxK76nUiiO7gigBwYFK4EEACKhZANi
AARBb8xqEzAxMWPBj3m44R18FULsetCFMYZPDGI+WAOIBGoLrLoRDUCOS6F7gDTZ
Y6W1FhBFcrK3Oyk5HblR+C1qBREDDFUVjNH1yaLoVGa++r9OyKB390CLgU2OeJHv
8+A=
MIG/AgEAMBAGByqGSM49AgEGBSuBBAAiBIGnMIGkAgEBBDBmpNziSYmGoWwl7apJM9ZdDBxkJqmx
MScHGXG45ZQXSv7fIuJlsSwxK76nUiiO7gigBwYFK4EEACKhZANiAARBb8xqEzAxMWPBj3m44R18
FULsetCFMYZPDGI+WAOIBGoLrLoRDUCOS6F7gDTZY6W1FhBFcrK3Oyk5HblR+C1qBREDDFUVjNH1
yaLoVGa++r9OyKB390CLgU2OeJHv8+A=
-----END PRIVATE KEY-----
"""
let privKey = try PrivateKey(pem: privKeyPem)
Expand Down
16 changes: 0 additions & 16 deletions Sources/SwiftHPKE/SwiftHPKE.docc/Extensions/Base64Ext.md

This file was deleted.

9 changes: 4 additions & 5 deletions Sources/SwiftHPKE/SwiftHPKE.docc/SwiftHPKE.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ To use SwiftHPKE, in your project *Package.swift* file add a dependency like

```swift
dependencies: [
.package(url: "https://github.com/leif-ibsen/SwiftHPKE", from: "2.5.0"),
.package(url: "https://github.com/leif-ibsen/SwiftHPKE", from: "2.6.0"),
]
```

SwiftHPKE itself depends on the ASN1, BigInt and Digest packages

```swift
dependencies: [
.package(url: "https://github.com/leif-ibsen/ASN1", from: "2.5.0"),
.package(url: "https://github.com/leif-ibsen/BigInt", from: "1.17.0"),
.package(url: "https://github.com/leif-ibsen/Digest", from: "1.6.0"),
.package(url: "https://github.com/leif-ibsen/ASN1", from: "2.6.0"),
.package(url: "https://github.com/leif-ibsen/BigInt", from: "1.19.0"),
.package(url: "https://github.com/leif-ibsen/Digest", from: "1.8.0"),
],
```

Expand All @@ -140,7 +140,6 @@ for iOS the version must be at least 13, and for watchOS the version must be at
- ``SwiftHPKE/CipherSuite``
- ``SwiftHPKE/PrivateKey``
- ``SwiftHPKE/PublicKey``
- ``SwiftHPKE/Base64``

### Type Aliases

Expand Down
37 changes: 15 additions & 22 deletions Sources/SwiftHPKE/X255_448/Field25519.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,28 +285,21 @@ struct Field25519: CustomStringConvertible {
}

func invert() -> Field25519 {
let z2 = self.square()
var t = z2.square(2)
let z9 = t.mul(self)
let z11 = z9.mul(z2)
t = z11.square()
let z2_5_0 = t.mul(z9)
t = z2_5_0.square(5)
let z2_10_0 = t.mul(z2_5_0)
t = z2_10_0.square(10)
let z2_20_0 = t.mul(z2_10_0)
t = z2_20_0.square(20)
t = t.mul(z2_20_0)
t = t.square(10)
let z2_50_0 = t.mul(z2_10_0)
t = z2_50_0.square(50)
let z2_100_0 = t.mul(z2_50_0)
t = z2_100_0.square(100)
t = t.mul(z2_100_0)
t = t.square(50)
t = t.mul(z2_50_0)
t = t.square(5)
return t.mul(z11)

// 2^255 - 19 - 2 bit pattern: 250 x 1 1 x 0 1 x 1 1 x 0 2 x 1
// Addition chain: 1 2 3 5 10 15 25 50 75 125 250

let x2 = self.square().mul(self)
let x3 = x2.square().mul(self)
let x5 = x3.square(2).mul(x2)
let x10 = x5.square(5).mul(x5)
let x15 = x10.square(5).mul(x5)
let x25 = x15.square(10).mul(x10)
let x50 = x25.square(25).mul(x25)
let x75 = x50.square(25).mul(x25)
let x125 = x75.square(50).mul(x50)
let x250 = x125.square(125).mul(x125)
return x250.square(2).mul(self).square(3).mul(x2)
}

}
4 changes: 4 additions & 0 deletions Sources/SwiftHPKE/X255_448/Field448.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ struct Field448: CustomStringConvertible {
}

func invert() -> Field448 {

// 2^448 - 2^224 - 1 - 2 bit pattern: 223 x 1 1 x 0 222 x 1 1 x 0 1 x 1
// Addition chain: 1 2 3 6 9 18 19 37 74 111 222 223

let x2 = self.square().mul(self)
let x3 = x2.square().mul(self)
let x6 = x3.square(3).mul(x3)
Expand Down
2 changes: 1 addition & 1 deletion SwiftHPKE.doccarchive/data/documentation/swifthpke.json

Large diffs are not rendered by default.

Loading

0 comments on commit 9f5af60

Please sign in to comment.