Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : Tests/QyvoraCryptoTests/EngineTests.swift8// Module : Tests9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0412// Last Modified : 2026-12-0413//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import Testing42@testable import QyvoraCrypto4344@Suite struct EngineTests {45 @Test func selfTestPasses() {46 #expect(QyvoraEngine.selfTest())47 }4849 @Test func catalogueMatchesTheStandards() {50 let a = QyvoraEngine.algorithms51 #expect(a.filter { $0.standard == "FIPS 203" }.count == 3)52 #expect(a.filter { $0.standard == "FIPS 204" }.count == 3)53 #expect(a.filter { $0.standard == "FIPS 205" }.count == 12)54 func find(_ n: String) -> QyvoraEngine.Algorithm { a.first { $0.name == n }! }55 #expect(find("ML-KEM-768").publicKeySize == 1184 && find("ML-KEM-768").privateKeySize == 2400 && find("ML-KEM-768").outputSize == 1088)56 #expect(find("ML-KEM-1024").publicKeySize == 1568 && find("ML-KEM-1024").outputSize == 1568)57 #expect(find("ML-DSA-44").publicKeySize == 1312 && find("ML-DSA-44").privateKeySize == 2560 && find("ML-DSA-44").outputSize == 2420)58 #expect(find("ML-DSA-65").outputSize == 3309 && find("ML-DSA-87").outputSize == 4627 && find("ML-DSA-87").privateKeySize == 4896)59 #expect(find("SLH-DSA-SHAKE-256f").outputSize == 49856 && find("SLH-DSA-SHA2-128s").outputSize == 7856)60 #expect(Set(a.map(\.name)).count == a.count)61 }6263 /// Ed25519 is in the catalogue and in the self-test; X25519 is named as the system primitive it is.64 @Test func theCatalogueNamesEd25519AndKeepsSystemPrimitivesApart() throws {65 let ed = try #require(QyvoraEngine.algorithms.first { $0.name == "Ed25519" })66 #expect(ed.standard == "RFC 8032" && ed.kind == .curve && ed.publicKeySize == 32 && ed.privateKeySize == 32 && ed.outputSize == 64)67 #expect(ed.isFromScratch && ed.use.contains("Solana") && ed.use.contains("not quantum-resistant"))68 let x = try #require(QyvoraEngine.algorithms.first { $0.name == "X25519" })69 #expect(!x.isFromScratch && x.use.contains("CryptoKit") && x.use.contains("not part of this engine") && x.use.contains("not quantum-resistant"))70 #expect(!QyvoraEngine.engineAlgorithms.contains { $0.name == "X25519" } && QyvoraEngine.engineAlgorithms.count == QyvoraEngine.algorithms.count - 1)71 // Schnorr is implemented, and the catalogue does not claim it is used to spend72 let schnorr = try #require(QyvoraEngine.algorithms.first { $0.name == "secp256k1 Schnorr" })73 #expect(schnorr.use.contains("not used for spending") && schnorr.isFromScratch)74 let ecdsa = try #require(QyvoraEngine.algorithms.first { $0.name == "secp256k1 ECDSA" })75 #expect(ecdsa.use.contains("TRON") && ecdsa.use.contains("Bitcoin Cash") && !ecdsa.use.contains("Solana"))76 #expect(Set(QyvoraEngine.algorithms.map(\.name)).count == QyvoraEngine.algorithms.count)77 }7879 /// RFC 8032, section 7.1, test vector 1: the known answer the self-test checks.80 @Test func ed25519KnownAnswerOfTheSelfTest() throws {81 let seed = try #require(Hex.decode("9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"))82 let publicKey = try Ed25519.publicKey(seed: seed)83 #expect(publicKey.hex == "d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a")84 let signature = try Ed25519.sign(message: [], seed: seed)85 #expect(signature.hex == "e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e065224901555fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b")86 #expect(Ed25519.verify(signature: signature, message: [], publicKey: publicKey) && !Ed25519.verify(signature: signature, message: [0], publicKey: publicKey))87 #expect(QyvoraEngine.selfTest())88 }89}90