Skip to content

Commit

Permalink
Merge pull request #21 from Sajjon/tests
Browse files Browse the repository at this point in the history
Remove legacy configurations and plists, add test for GCM
  • Loading branch information
Sajjon committed Apr 7, 2021
2 parents 8727b13 + 8217dc3 commit 7a01b9f
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 90 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public extension ECIES.SealedBox {

static let byteCountOf = ByteCountOf()

/// The combined representation (nonce || ephemeralPublicKeyCompressed || tag || ciphertext)
/// The combined representation `(nonce || ephemeralPublicKeyCompressed || tag || ciphertext)`
var combined: Data {
var combined = Data(nonce)
combined.append(ephemeralPublicKey.data.compressed)
Expand Down
11 changes: 10 additions & 1 deletion Sources/EllipticCurveKit/Cryptography/Encryption/ECIES.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public struct ECIES {
}
}


// MARK: Seal
public extension ECIES {

Expand Down Expand Up @@ -57,6 +56,7 @@ public extension ECIES {
)

let symmetricSealedBox: AES.GCM.SealedBox

do {

symmetricSealedBox = try AES.GCM.seal(
Expand All @@ -66,6 +66,15 @@ public extension ECIES {
authenticating: ephemeralPublicKey.data.compressed
)

print("""
msg: \(Data(message).toHexString()),
nonce: \(Data(nonce).toHexString()),
authenticating: \(ephemeralPublicKey.hex.compressed),
ciphertext: \(symmetricSealedBox.ciphertext.asHex),
tag: \(symmetricSealedBox.tag.toHexString()),
symmetricSealedBox.nonce: \(Data(symmetricSealedBox.nonce).toHexString()),
"""
)
} catch let error as CryptoKitError {
return .failure(.symmetricEncryptionFailed(error))
} catch {
Expand Down

This file was deleted.

19 changes: 0 additions & 19 deletions Sources/EllipticCurveKit/SupportingFiles/EllipticCurveKit.h

This file was deleted.

4 changes: 0 additions & 4 deletions Sources/EllipticCurveKit/SupportingFiles/module.modulemap

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

47 changes: 47 additions & 0 deletions Tests/EllipticCurveKitTests/Crypto/AESGCMTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// File.swift
//
//
// Created by Alexander Cyon on 2021-03-09.
//

import Foundation
import XCTest
@testable import EllipticCurveKit
import CryptoKit

final class AESGCMTests: XCTestCase {
func testAESGCM() throws {


let nonce = try AES.GCM.Nonce(
data: Data(hex: "bf9e592c50183db30afff24d")
)

let ciphertext = Data(hex: "d2d309e9d7c9c5f5ca692b3e51e4f84670e8ee3dfce4d183389e6fcea2f46a707101e38a6aff1754e57c533b6bea0f620d5bac85ec9a2f86352111e2fc2879c839b6ae0d931c30364d5245bcad69")

let authTag = Data(hex: "baa17313cf02d4f34d135c34643426c8")

let sealedBox = try AES.GCM.SealedBox(
nonce: nonce,
ciphertext: ciphertext,
tag: authTag
)

let symmetricKeyData = Data(hex: "fbe8c9f0dcbdbf52ee3038b18ca378255c35583bae12eb50151d7458d43dc3e1")

let additionalAuthData = Data(hex: "03B7F98F3FB16527A8F779C326A7A57261F1341EAC191011F7A916D01D668F4549")

let decrypted = try AES.GCM.open(
sealedBox,
using: .init(data: symmetricKeyData),
authenticating: additionalAuthData
)

let plaintext = String(data: decrypted, encoding: .utf8)!
XCTAssertEqual(plaintext, "Guten tag Joe! My nukes are 100 miles south west of Münich, don't tell anyone")
}


}

27 changes: 27 additions & 0 deletions Tests/EllipticCurveKitTests/Crypto/ECIESTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,35 @@ final class ECIESTests: XCTestCase {

let ecies = ECIES()
let decrypted = try ecies.decrypt(data: encryptedMessage, whitePublicKey: senderPubKey, blackPrivateKey: privateKey)

XCTAssertEqual(decrypted, message)
}

func testLength() throws {
let message = "The Legend of Zelda is a high fantasy action-adventure video game franchise created by Japanese game designers Shigeru Miyamoto and Takashi Tezuka. It is developed and published by Nintendo."
let ecies = ECIES()
let alice = KeyPair()
let bob = KeyPair()
let encryptedMessage = try ecies.encrypt(
message: message,
whitePublicKey: bob.publicKey,
blackPrivateKey: alice.privateKey
)
let encryptedBytes = encryptedMessage.combined
XCTAssertLessThanOrEqual(
encryptedBytes.count,
256
)
let decrypted = try ecies.decrypt(
data: encryptedBytes,
whitePublicKey: alice.publicKey,
blackPrivateKey: bob.privateKey
)
XCTAssertEqual(
decrypted,
message
)
}
}

extension AffinePoint: ExpressibleByStringLiteral {
Expand Down

This file was deleted.

0 comments on commit 7a01b9f

Please sign in to comment.