SPB Git

Repository Public

Ed25519Wycheproof.swift 3.8 KB 86 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : QYVORA7// File             : security/tests/Tests/WycheproofAuditTests/Ed25519Wycheproof.swift8// Module           : Tests9// Repository       : https://git.spboucher.ai/qyvora10// Project Website  : Not specified11// Created          : 2026-12-0512// Last Modified    : 2026-12-0513//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 AuditSupport42import Foundation43import QyvoraEd2551944import QyvoraMath45import Testing4647// Wycheproof `ed25519_test` (pinned revision, security/vectors/wycheproof): every "valid" signature must48// verify, every "invalid" one must be refused. The file has two kinds of "acceptable" cases, for which the49// strict policy of the engine gives a definite answer:50//   - SmallOrderPublicKey: always refused (rule 3 of the policy);51//   - MixedOrderPublicKey: accepted exactly when the cofactorless equation holds (the verdict of each case is52//     compared with ed25519-dalek `verify_strict` in the differential tests).5354@Suite struct WycheproofEd25519 {55    @Test func verify() throws {56        var tally = Tally()57        var smallOrder = 0, smallOrderRefused = 0, mixedOrder = 0, mixedOrderAccepted = 058        for g in try wycheproofGroups("ed25519_test") {59            let key = try #require(g["publicKey"] as? [String: Any])60            let pk = try #require(key.hex("pk"))61            for t in g.acvpTests {62                guard let msg = t.hex("msg"), let sig = t.hex("sig") else {63                    tally.skip()64                    continue65                }66                let accepted = Ed25519.verify(signature: sig, message: msg, publicKey: pk)67                tally.check(t, accepted: accepted)68                let flags = t["flags"] as? [String] ?? []69                if flags.contains("SmallOrderPublicKey") {70                    smallOrder += 171                    if accepted { tally.fail(t, "signature under a small-order public key accepted") } else { smallOrderRefused += 1 }72                    #expect(Ed25519.isValidPublicKey(pk) == false)73                }74                if flags.contains("MixedOrderPublicKey") {75                    mixedOrder += 176                    if accepted { mixedOrderAccepted += 1 }77                }78            }79        }80        #expect(tally.cases >= 200)81        #expect(smallOrder > 0 && smallOrderRefused == smallOrder)82        tally.extraNote = "small-order public keys: \(smallOrderRefused)/\(smallOrder) refused; mixed-order public keys: \(mixedOrderAccepted)/\(mixedOrder) accepted (cofactorless equation)"83        tally.finish("Ed25519 verification (strict policy)", "ed25519_test")84    }85}86
Files main
Menu

Theme