SignalCommonCrypto
public struct SignalCommonCrypto
SignalCommonCrypto struct adopted from the
LibSignalProtocolSwift
project (lightly modified)
-
Create a number of random bytes
Throws
SignalError.noRandomBytesDeclaration
Swift
public static func random(bytes: Int) throws -> DataParameters
bytesThe number of random bytes to create
Return Value
An array of
byteslength with random numbers -
Create a HMAC authentication for a given message
Declaration
Swift
public static func hmacSHA256(for message: Data, with salt: Data) -> DataParameters
messageThe input message to create the HMAC for
saltThe salt for the HMAC
Return Value
The HMAC
-
Create a SHA512 digest for a given message
Throws
SignalError.digestErrorDeclaration
Swift
public static func sha512(for message: Data) throws -> DataParameters
messageThe input message to create the digest for
Return Value
The digest
-
Encrypt a message with AES
Throws
SignalError.encryptionErrorDeclaration
Swift
public static func encrypt(message: Data, with cipher: SignalEncryptionScheme = .AES_CBCwithPKCS5, key: Data, iv: Data) throws -> DataParameters
messageThe input message to encrypt
cipherTHe encryption scheme to use
keyThe key for encryption (
kCCKeySizeAES256bytes)ivThe initialization vector (
kCCBlockSizeAES128bytes)Return Value
The encrypted message
-
Decrypt a message with AES
Throws
SignalError.decryptionErrorDeclaration
Swift
public static func decrypt(message: Data, with cipher: SignalEncryptionScheme = .AES_CBCwithPKCS5, key: Data, iv: Data) throws -> DataParameters
messageThe input message to decrypt
cipherTHe encryption scheme to use
keyThe key for decryption (
kCCKeySizeAES256bytes)ivThe initialization vector (
kCCBlockSizeAES128bytes)Return Value
The decrypted message
-
Verify a message MAC
Declaration
Swift
public static func verifyMAC(data: Data, key: Data, expectedMAC: Data) throws -
RFC 5869 key derivation
Declaration
Swift
public static func deriveSecrets(input: Data, salt: Data = Data(count: 32), info: Data, chunks: Int = 2) throws -> [Data] -
Calculate an ECDH agreement.
Declaration
Swift
public static func calculateAgreement(publicKeyData: Data, privateKeyData: Data) throws -> DataParameters
publicKeyDataThe curve25519 (typically remote party’s) 32-byte public key data
privateKeyDataThe curve25519 (typically your) 32-byte private key data
Return Value
a 32-bit shared secret on success, throwing on failure
-
Generates a Curve25519 keypair.
Declaration
Swift
public static func generateKeyPairFromPrivateKey(privateKeyData: Data) throws -> KeyPairParameters
privateKeyDataThe curve25519 (typically your) 32-byte private key data
Return Value
the full
KeyPair -
Generate a Curve25519 signature.
Declaration
Swift
public static func generateSignature(privateKeyData: Data, message: Data) throws -> Data -
Validate a Curve25519 signature.
Declaration
Swift
public static func verifySignature(signature: Data, publicKeyData: Data, message: Data) throws -> Bool -
Decrypt attachment data
Declaration
Swift
public static func decryptAttachment(data: Data, keys: Data) throws -> Data -
Encrypt attachment data
Declaration
Swift
public static func encryptAttachment(data: Data, keys: Data, iv: Data) throws -> Data
View on GitHub
Install in Dash
SignalCommonCrypto Structure Reference