apple / swift-crypto

Open-source implementation of a substantial portion of the API of Apple CryptoKit suitable for use on Linux platforms.
https://apple.github.io/swift-crypto
Apache License 2.0
1.47k stars 165 forks source link

Using GCM Nonce pattern for CBC, CFB, and CTR #261

Open maschall opened 2 months ago

maschall commented 2 months ago

Following GCM use of gyb for Nonce generation, I converted IV and Nonce classes of the CBC, CFB, and CTR to allow conformance to ContinuousBytes and Sequence.

Checklist

If you've made changes to gyb files

Motivation:

The project I am working on uses a AES CBC algorithm to send encrypted data to exchange keys between a server and client. This means, that the client and server exchange the IV/Nonce with each other. Currently, we can only use CommonCrypto, because AES._CBC.IV doesn't facilitate an API to get the internal data bytes.

Modifications:

Removed the current IV and Nonce structs from their corresponding files. Made a Nonces.swift.gyb file that will generate the corresponding structs for each algorithm.

Result:

Allows us to integrate Crypto into our repository and fix an issue we have involving padding of our cipher data, when using CCCrypt

I'm happy to add unit tests for this PR, however I don't think they are needed. While the conformance to new Protocols is public, I believe their use is also internal and so they are being exercised by the current set of unit tests.

maschall commented 2 months ago

Yeah, I'll give it a shot

maschall commented 2 months ago

changed from Data back to the Tuple style. I did give them typealiases

maschall commented 1 month ago

Just a friendly bump: @Lukasa in case it gets lost in the shuffle

Lukasa commented 1 month ago

@swift-server-bot add to allowlist