8
8
<li ><a href =" #basic6 " >Encryption and Decryption</a ></li >
9
9
<li ><a href =" #basic7 " >Secret Export</a ></li >
10
10
<li ><a href =" #basic8 " >CryptoKit Compatibility</a ></li >
11
+ <li ><a href =" #basic9 " >Performance</a ></li >
11
12
<li ><a href =" #dep " >Dependencies</a ></li >
12
13
<li ><a href =" #ref " >References</a ></li >
13
14
</ul >
@@ -16,7 +17,7 @@ SwiftHPKE implements the Hybrid Public Key Encryption standard as defined in RFC
16
17
In your project Package.swift file add a dependency like<br />
17
18
18
19
dependencies: [
19
- .package(url: "https://github.com/leif-ibsen/SwiftHPKE", from: "1.3 .0"),
20
+ .package(url: "https://github.com/leif-ibsen/SwiftHPKE", from: "1.4 .0"),
20
21
]
21
22
SwiftHPKE requires Swift 5.0. It also requires that the Int and UInt types be 64 bit types.
22
23
SwiftHPKE uses Apple's CryptoKit framework. Therefore, for macOS the version must be at least 10.15,
@@ -246,33 +247,51 @@ is also possible.
246
247
The SwiftHPKE keys of type .P256, .P384, .P521 and .X25519 are equivalent to
247
248
CryptoKit keys of type P256, P384, P521 and Curve25519. Keys of type .X448 is not supported in CryptoKit.
248
249
249
- To convert CryptoKit P256 keys (similarly for P384 and P521) - say * cc256priv * and * cc256pub * :
250
+ To convert CryptoKit P256 keys (similarly for P384 and P521) - say * ckPriv * and * ckPub * to SwiftHPKE keys :
250
251
251
- let hpke256priv = try PrivateKey(der: Bytes(cc256priv .derRepresentation))
252
- let hpke256pub = try PublicKey(der: Bytes(cc256pub .derRepresentation))
252
+ let hpkePriv = try PrivateKey(der: Bytes(ckPriv .derRepresentation))
253
+ let hpkePub = try PublicKey(der: Bytes(ckPub .derRepresentation))
253
254
254
- To convert CryptoKit Curve25519 keys - say * cc25519priv * and * cc25519pub * :
255
+ To convert CryptoKit Curve25519 keys - say * ckPriv * and * ckPub * to SwiftHPKE keys :
255
256
256
- let hpke25519priv = try PrivateKey(kem: .X25519, bytes: Bytes(cc25519priv .rawRepresentation))
257
- let hpke25519pub = try PublicKey(kem: .X25519, bytes: Bytes(cc25519pub .rawRepresentation))
257
+ let hpkePriv = try PrivateKey(kem: .X25519, bytes: Bytes(ckPriv .rawRepresentation))
258
+ let hpkePub = try PublicKey(kem: .X25519, bytes: Bytes(ckPub .rawRepresentation))
258
259
259
- To convert SwiftHPKE .P256 keys (similarly for .P384 and .P521) - say * hpke256priv * and * hpke256pub * :
260
+ To convert SwiftHPKE .P256 keys (similarly for .P384 and .P521) - say * hpkePriv * and * hpkePub * to CryptoKit keys :
260
261
261
- let cc256priv = try CryptoKit.P256.KeyAgreement.PrivateKey(derRepresentation: hpke256priv .der)
262
- let cc256pub = try CryptoKit.P256.KeyAgreement.PublicKey(derRepresentation: hpke256pub .der)
262
+ let ckPriv = try CryptoKit.P256.KeyAgreement.PrivateKey(derRepresentation: hpkePriv .der)
263
+ let ckPub = try CryptoKit.P256.KeyAgreement.PublicKey(derRepresentation: hpkePub .der)
263
264
264
- To convert SwiftHPKE .X25519 keys - say * hpke25519priv * and * hpke25519pub * :
265
+ To convert SwiftHPKE .X25519 keys - say * hpkePriv * and * hpkePub * to CryptoKit keys :
265
266
266
- let cc25519priv = try CryptoKit.Curve25519.KeyAgreement.PrivateKey(rawRepresentation: hpke25519priv .bytes)
267
- let cc25519pub = try CryptoKit.Curve25519.KeyAgreement.PublicKey(rawRepresentation: hpke25519pub .bytes)
267
+ let ckPriv = try CryptoKit.Curve25519.KeyAgreement.PrivateKey(rawRepresentation: hpkePriv .bytes)
268
+ let ckPub = try CryptoKit.Curve25519.KeyAgreement.PublicKey(rawRepresentation: hpkePub .bytes)
268
269
269
- <h2 id =" dep " ><b >Dependencies</b ></h2 >
270
+ <h2 id =" basic9 " ><b >Performance</b ></h2 >
271
+ SwiftHPKE's encryption and decryption performance was measured on an iMac 2021, Apple M1 chip.
272
+ The time to create a * Sender* and * Recipient* instance in base mode is shown in the table below, depending on the KEM type - units are milliseconds.
273
+ <table width =" 90% " >
274
+ <tr ><th align =" left " width =" 16% " >KEM</th ><th align =" right " width =" 28% " >Sender</th ><th align =" right " width =" 28% " >Recipient</th ></tr >
275
+ <tr ><td >P256</td ><td align =" right " >7 mSec</td ><td align =" right " >6 mSec</td ></tr >
276
+ <tr ><td >P384</td ><td align =" right " >20 mSec</td ><td align =" right " >17 mSec</td ></tr >
277
+ <tr ><td >P521</td ><td align =" right " >46 mSec</td ><td align =" right " >39 mSec</td ></tr >
278
+ <tr ><td >X25519</td ><td align =" right " >0.14 mSec</td ><td align =" right " >0.09 mSec</td ></tr >
279
+ <tr ><td >X448</td ><td align =" right " >1.1 mSec</td ><td align =" right " >0.5 mSec</td ></tr >
280
+ </table >
281
+ The encryption and decryption speed in base mode, once the * Sender* or * Recipient* instance is created, is shown in the table below, depending on the AEAD type - units are MBytes / Sec.
282
+ <table width =" 90% " >
283
+ <tr ><th align =" left " width =" 16% " >AEAD</th ><th align =" right " width =" 28% " >Encryption speed</th ><th align =" right " width =" 28% " >Decryption speed</th ></tr >
284
+ <tr ><td >AESGCM128</td ><td align =" right " >3500 MB/Sec (0.91 cycles / byte)</td ><td align =" right " >3340 MB/Sec (0.96 cycles / byte)</td ></tr >
285
+ <tr ><td >AESGCM256</td ><td align =" right " >3640 MB/Sec (0.88 cycles / byte)</td ><td align =" right " >3630 MB/Sec (0.88 cycles / byte)</td ></tr >
286
+ <tr ><td >CHACHAPOLY</td ><td align =" right " >555 MB/Sec (5.8 cycles / byte)</td ><td align =" right " >557 MB/Sec (5.7 cycles / byte)</td ></tr >
287
+ </table >
270
288
289
+ <h2 id =" dep " ><b >Dependencies</b ></h2 >
271
290
The SwiftHPKE package depends on the ASN1 and BigInt packages
272
291
273
292
dependencies: [
274
293
.package(url: "https://github.com/leif-ibsen/ASN1", from: "2.1.0"),
275
- .package(url: "https://github.com/leif-ibsen/BigInt", from: "1.13 .0"),
294
+ .package(url: "https://github.com/leif-ibsen/BigInt", from: "1.14 .0"),
276
295
],
277
296
278
297
<h2 id =" ref " ><b >References</b ></h2 >
0 commit comments