Skip to content

Commit

Permalink
Release 5.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
leif-ibsen committed Feb 28, 2024
1 parent 404843f commit 0efa7ee
Show file tree
Hide file tree
Showing 752 changed files with 1,274 additions and 1,223 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/ASN1", from: "2.3.0"),
.package(url: "https://github.com/leif-ibsen/BigInt", from: "1.15.0"),
.package(url: "https://github.com/leif-ibsen/Digest", from: "1.2.0"),
.package(url: "https://github.com/leif-ibsen/ASN1", from: "2.5.0"),
.package(url: "https://github.com/leif-ibsen/BigInt", from: "1.16.0"),
.package(url: "https://github.com/leif-ibsen/Digest", from: "1.4.0"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This encompasses:

SwiftECC requires Swift 5.0. It also requires that the `Int` and `UInt` types be 64 bit types.

Its documentation is build with the DocC tool and published on GitHub Pages at this location:
Its documentation is build with the DocC plugin and published on GitHub Pages at this location:

https://leif-ibsen.github.io/SwiftECC/documentation/swiftecc

Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftECC/Cipher/Cipher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ typealias Words = [Word]
typealias Limb = UInt64
typealias Limbs = [Limb]

/// AES block ciphers
/// The AES block ciphers
public enum AESCipher: CaseIterable {
/// AES 128 bit block cipher
case AES128
Expand All @@ -23,7 +23,7 @@ public enum AESCipher: CaseIterable {
case AES256
}

/// Block cipher modes
/// The block cipher modes
public enum BlockMode: CaseIterable {
/// Cipher Block Chaining mode
case CBC
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftECC/Curve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Leif Ibsen on 18/02/2020.
//

/// Predefined elliptic curves
/// The predefined elliptic curves
public enum ECCurve: CaseIterable {
/// brainpoolP160r1 curve
case BP160r1
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftECC/Domain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public typealias Byte = UInt8
/// Array of unsigned 8 bit values
public typealias Bytes = [UInt8]

/// An elliptic curve domain
public class Domain: CustomStringConvertible, Equatable {

init(_ domainP: DomainP) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftECC/Exception.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Leif Ibsen on 18/02/2020.
//

/// Elliptic curve exceptions
/// The elliptic curve exceptions
public enum ECException: Error, CustomStringConvertible {

/// Textual description of `self`
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftECC/Point.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public struct Point: CustomStringConvertible, Equatable {

// MARK: Instance Methods

/// Tests equality of Points
/// Equality of Points
///
/// - Parameters:
/// - p1: First point
/// - p2: Second point
/// - Returns: `true` if p1 = p2, else `false`
/// - Returns: `true` if p1 and p2 are equal, `false` otherwise
public static func == (p1: Point, p2: Point) -> Bool {
return p1.x == p2.x && p1.y == p2.y && p1.infinity == p2.infinity
}
Expand Down
3 changes: 0 additions & 3 deletions Sources/SwiftECC/PrivateKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import ASN1
import BigInt
import Digest

///
/// An elliptic curve private key
///
public class ECPrivateKey: CustomStringConvertible {

static let AES128CBC_OID = ASN1ObjectIdentifier("2.16.840.1.101.3.4.1.2")!
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftECC/PublicKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ASN1
import BigInt
import Digest

/// An elliptic curve public key
public class ECPublicKey: CustomStringConvertible {

// Cache multiples of w to speed up signature verification
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftECC/RP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public struct RP: CustomStringConvertible, Equatable {

// MARK: Instance Methods

/// Tests equality of reduction polynomials
/// Equality of reduction polynomials
///
/// - Parameters:
/// - rp1: First reduction polynomial
/// - rp2: Second reduction polynomial
/// - Returns: `true` if rp1 = rp2 else `false`
/// - Returns: `true` if rp1 and rp2 are equal, `false` otherwise
public static func == (rp1: RP, rp2: RP) -> Bool {
return rp1.m == rp2.m && rp1.k3 == rp2.k3 && rp1.k2 == rp2.k2 && rp1.k1 == rp2.k1
}
Expand Down
3 changes: 0 additions & 3 deletions Sources/SwiftECC/Signature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import ASN1
import BigInt

///
/// An elliptic curve signature
///
public class ECSignature {

// MARK: Initializers
Expand Down
Binary file modified Sources/SwiftECC/SwiftECC.docc/.DS_Store
Binary file not shown.
50 changes: 27 additions & 23 deletions Sources/SwiftECC/SwiftECC.docc/Articles/AEADEncryptDecrypt.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# AEAD Encrypt and Decrypt

Authenticated Encryption with Associated Data

##

Authenticated Encryption with Associated Data (AEAD) is implemented with the ChaCha20 / Poly1305 algorithm and the AES / GCM algorithm.
Both implementations use Apple's CryptoKit framework, that takes advantage of hardware support for the AES and GCM algorithms.
Both implementations use the CryptoKit framework, that takes advantage of hardware support for the AES and GCM algorithms.

#### Example

### Example
```swift
import SwiftECC

Expand All @@ -26,11 +30,14 @@ do {
print("Exception: \(error)")
}
```

giving:

```swift
Hi, there!
Hi, there!
```

The encryption and decryption speed for domain EC256k1 (the bitcoin domain) measured on an iMac 2021,
Apple M1 chip is shown below - units are Megabytes per second.

Expand All @@ -40,34 +47,31 @@ Apple M1 chip is shown below - units are Megabytes per second.
| AES-128/GCM | 2000 MByte/Sec | 1200 MByte/Sec |


### Key Derivation
#### Key Derivation

SwiftECC uses the X9.63 Key Derivation Function to derive block cipher keying materiel. Please refer [SEC 1] section 3.6.
Four cases are considered:

#### ChaCha20/Poly1305
KDF generates 44 bytes.

Encryption/decryption key = bytes 0 ..< 32

Nonce = bytes 32 ..< 44

#### AES-128/GCM
KDF generates 28 bytes.

AES encryption/decryption key = bytes 0 ..< 16
* **ChaCha20/Poly1305**

Nonce = bytes 16 ..< 28
KDF generates 44 bytes.
Encryption/decryption key = bytes 0 ..< 32
Nonce = bytes 32 ..< 44

#### AES-192/GCM
KDF generates 36 bytes.
* **AES-128/GCM**

AES encryption/decryption key = bytes 0 ..< 24
KDF generates 28 bytes.
AES encryption/decryption key = bytes 0 ..< 16
Nonce = bytes 16 ..< 28

Nonce = bytes 24 ..< 36
* **AES-192/GCM**

#### AES-256/GCM
KDF generates 44 bytes.
KDF generates 36 bytes.
AES encryption/decryption key = bytes 0 ..< 24
Nonce = bytes 24 ..< 36

AES encryption/decryption key = bytes 0 ..< 32
* **AES-256/GCM**

Nonce = bytes 32 ..< 44
KDF generates 44 bytes.
AES encryption/decryption key = bytes 0 ..< 32
Nonce = bytes 32 ..< 44
4 changes: 3 additions & 1 deletion Sources/SwiftECC/SwiftECC.docc/Articles/Acknowledgement.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Acknowledgement

The AES block cipher implementation is essentially a translation to Swift of the Go Language implementation of AES

##
The AES block cipher implementation is essentially a translation to Swift of the Go Language implementation of AES.

26 changes: 0 additions & 26 deletions Sources/SwiftECC/SwiftECC.docc/Articles/Basics.md

This file was deleted.

14 changes: 11 additions & 3 deletions Sources/SwiftECC/SwiftECC.docc/Articles/CreateDomain.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Create new Domains

You can create your own domains as illustrated by two examples

##
You can create your own domains as illustrated by the two examples below.

### Example 1
#### Example 1

This is example 3.5 from [GUIDE]. It shows how to make your own prime characteristic domain.

```swift
import SwiftECC
import BigInt
Expand All @@ -22,7 +24,9 @@ print("p1 * 2 =", try domain.multiplyPoint(p1, BInt(2)))
// Inspect the domain - please refer [SEC 1] appendix C.2
print(domain.asn1Explicit())
```

giving:

```swift
p1 + p2 = Point(13, 6)
p1 * 2 = Point(14, 6)
Expand All @@ -38,9 +42,11 @@ Sequence (6):
Integer: 37
Integer: 1
```
### Example 2

#### Example 2

This is example 3.6 from [GUIDE]. It shows how to make your own characteristic 2 domain.

```swift
import SwiftECC
import BigInt
Expand All @@ -60,7 +66,9 @@ print("p1 * 2 =", try domain.multiplyPoint(p1, BInt(2)))
// Inspect the domain - please refer [SEC 1] appendix C.2
print(domain.asn1Explicit())
```

giving:

```swift
p1 + p2 = Point(1, 1)
p1 * 2 = Point(11, 2)
Expand Down
23 changes: 0 additions & 23 deletions Sources/SwiftECC/SwiftECC.docc/Articles/CreateKeys.md

This file was deleted.

12 changes: 0 additions & 12 deletions Sources/SwiftECC/SwiftECC.docc/Articles/Dependencies.md

This file was deleted.

4 changes: 3 additions & 1 deletion Sources/SwiftECC/SwiftECC.docc/Articles/ECArithmetic.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Elliptic Curve Arithmetic

SwiftECC implements the common elliptic curve arithmetic operations

##
SwiftECC implements the common elliptic curve arithmetic operations:

* Point doubling
* Point addition
Expand All @@ -12,4 +13,5 @@ SwiftECC implements the common elliptic curve arithmetic operations:

It is also possible to encode curve points in either compressed- or uncompressed format,
as well as to do the reverse decoding.
This is done using the `Domain` methods ``SwiftECC/Domain/encodePoint(_:_:)`` and ``SwiftECC/Domain/decodePoint(_:)``.

Loading

0 comments on commit 0efa7ee

Please sign in to comment.