SPB Git

Repository Public

SHA2Variants.swift 2.8 KB 79 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : QYVORA7// File             : Sources/QyvoraSymmetric/SHA2Variants.swift8// Module           : Qyvora Symmetric9// 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 QyvoraMath4243/// SHA-224 (FIPS 180-4, section 6.3): SHA-256 with its own initial value, truncated to 224 bits.44public struct SHA224: HashFunction {45    public static let blockSize = 6446    public static let digestSize = 284748    var core: SHA2564950    public init() {51        core = SHA256()52        core.h = [53            0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4,54        ]55    }5657    public mutating func update(_ data: Bytes) { core.update(data) }58    public mutating func finalize() -> Bytes { Bytes(core.finalize().prefix(28)) }59}6061/// SHA-384 (FIPS 180-4, section 6.5): SHA-512 with its own initial value, truncated to 384 bits.62public struct SHA384: HashFunction {63    public static let blockSize = 12864    public static let digestSize = 486566    var core: SHA5126768    public init() {69        core = SHA512()70        core.h = [71            0xcbbb9d5dc1059ed8, 0x629a292a367cd507, 0x9159015a3070dd17, 0x152fecd8f70e5939,72            0x67332667ffc00b31, 0x8eb44a8768581511, 0xdb0c2e0d64f98fa7, 0x47b5481dbefa4fa4,73        ]74    }7576    public mutating func update(_ data: Bytes) { core.update(data) }77    public mutating func finalize() -> Bytes { Bytes(core.finalize().prefix(48)) }78}79
Files main
Menu

Theme