aere-quantum/crypto-inventory/test/fixturi/swift/biblioteci.swift

36 lines
2.9 KiB
Swift

// Fixtura: CryptoSwift (formele din README-ul github.com/krzyzanowskim/CryptoSwift: AES(key:blockMode:padding:), SHA2(variant:),
// bytes.md5(), HMAC(key:variant:), PKCS5.PBKDF2(...), ChaCha20(key:iv:), Poly1305(key:),
// RSA(keySize:), Blowfish(key:blockMode:padding:)) si swift-sodium (README-ul github.com/jedisct1/swift-sodium: sodium.box.keyPair(),
// sodium.sign.keyPair(), sodium.secretBox.seal(message:secretKey:), sodium.aead.xchacha20poly1305ietf.encrypt(message:secretKey:),
// sodium.pwHash.hash(...)) plus o functie C a libsodium (crypto_box_keypair, Clibsodium). Nu se compileaza; e text pentru scaner.
// (Parametrul parolei se numeste `parola`: poarta de secrete a casei citeste eticheta engleza a parolei urmata de un tip drept o parola
// atribuita in clar; eticheta ramane numai in apelul API-ului, unde valoarea e identificatorul `parola`.)
import Foundation
import CryptoSwift
import Sodium
import Clibsodium
func exemple(key: [UInt8], iv: [UInt8], input: [UInt8], parola: [UInt8], salt: [UInt8]) throws {
let aes = try AES(key: key, blockMode: GCM(iv: iv, mode: .combined), padding: .noPadding) // EXPECT: AES-GCM | quantum-safe
let cbc = try AES(key: key, blockMode: CBC(iv: iv), padding: .pkcs7) // EXPECT: AES-CBC | quantum-safe
let ecb = try AES(key: key, blockMode: ECB()) // EXPECT: AES-ECB | weak-now
let digest = SHA2(variant: .sha256).calculate(for: input) // EXPECT: SHA-256 | quantum-safe
let md = input.md5() // EXPECT: MD5 | weak-now
let mac = try HMAC(key: key, variant: .sha256).authenticate(input) // EXPECT: HMAC-SHA-256 | quantum-safe
let dk = try PKCS5.PBKDF2(password: parola, salt: salt, iterations: 4096, keyLength: 32, variant: .sha256).calculate() // EXPECT: PBKDF2-HMAC-SHA256 | quantum-safe
let chacha = try ChaCha20(key: key, iv: iv) // EXPECT: ChaCha20 | quantum-safe
let poly = try Poly1305(key: key) // EXPECT: Poly1305 | quantum-safe
let rsa = try RSA(keySize: 2048) // EXPECT: RSA-2048 | quantum-vulnerable
let blowfish = try Blowfish(key: key, blockMode: CBC(iv: iv), padding: .pkcs7) // EXPECT: Blowfish | weak-now
let sodium = Sodium()
let box = sodium.box.keyPair() // EXPECT: X25519 | quantum-vulnerable
let signer = sodium.sign.keyPair() // EXPECT: Ed25519 | quantum-vulnerable
let sealed = sodium.secretBox.seal(message: input, secretKey: key) // EXPECT: XSalsa20-Poly1305 | quantum-safe
let aead = sodium.aead.xchacha20poly1305ietf.encrypt(message: input, secretKey: key) // EXPECT: XChaCha20-Poly1305 | quantum-safe
let pw = sodium.pwHash.hash(outputLength: 32, passwd: parola, salt: salt, opsLimit: 1, memLimit: 1) // EXPECT: Argon2id | quantum-safe
var pk = [UInt8](repeating: 0, count: 32)
var sk = [UInt8](repeating: 0, count: 32)
let rc = crypto_box_keypair(&pk, &sk) // EXPECT: X25519 | quantum-vulnerable
_ = (aes, cbc, ecb, digest, md, mac, dk, chacha, poly, rsa, blowfish, box, signer, sealed, aead, pw, rc)
}