Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring over the WWDC 2023 CryptoKit API #181

Merged
merged 1 commit into from
Jun 13, 2023
Merged

Conversation

Lukasa
Copy link
Collaborator

@Lukasa Lukasa commented Jun 6, 2023

Motivation

WWDC has arrived! 🎉 As part of the celebration, let's bring Crypto up to speed with the new CryptoKit API surface.

Modifications

Substantial new docstrings
HPKE support

Result

WWDC 2023 support.

@Lukasa Lukasa added the ⚠️ needs-major-version-bump For PRs that when merged cause a bump of the major version, ie. x.0.0 -> (x+1).0.0 label Jun 6, 2023
Copy link
Member

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments inline. A lot of them are around formatting and captilization of method names

Comment on lines +23 to +31
/// An Advanced Encryption Standard cipher in Galois/Counter Mode with a key length of 128 bits.
case AES_GCM_128
/// An Advanced Encryption Standard cipher in Galois/Counter Mode with a key length of 256 bits.
case AES_GCM_256
/// A ChaCha20 stream cipher with the Poly1305 message authentication code.
case chaChaPoly
/// An export-only mode.
///
/// In export-only mode, HPKE negotiates key derivation, but you can't use it to encrypt or decrypt data.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc comments are wrongly indented here

Comment on lines +84 to +86
case .chaChaPoly:
return try ChaChaPoly.seal(message, using: key, nonce: ChaChaPoly.Nonce(data: nonce), authenticating: aad).combined.suffix(from: nonce.count)
default:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use a default here or exhaustively switch to cover new cases added in the future?



extension HPKE {
/// Cipher suites to use in hybrid public key encryption.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Cipher suites to use in hybrid public key encryption.
/// Cipher suites to use in hybrid public key encryption.

/// mechanism (KEM) for sharing the symmetric key. The sender and recipient of encrypted messages need to use the
/// same cipher suite.
public struct Ciphersuite {
/// A cipher suite for HPKE that uses NIST P-256 elliptic curve key agreement, SHA-2 key derivation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// A cipher suite for HPKE that uses NIST P-256 elliptic curve key agreement, SHA-2 key derivation
/// A cipher suite for HPKE that uses NIST P-256 elliptic curve key agreement, SHA-2 key derivation


fileprivate static let ciphersuiteLabel = Data("HPKE".utf8)

/// The key encapsulation mechanism (KEM) for encapsulating the symmetric key.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The key encapsulation mechanism (KEM) for encapsulating the symmetric key.
/// The key encapsulation mechanism (KEM) for encapsulating the symmetric key.

#else
import Foundation

internal func I2OSP(value: Int, outputByteCount: Int) -> Data {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

let key: DHPK

init(_ publicKey: DHPK, kem: HPKE.KEM) throws {
// TODO: Validate Ciphersuite Mismatches
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this TODO?

Comment on lines +73 to +77
return Crypto.KEM.EncapsulationResult(sharedSecret: HPKE.KexUtils.ExtractAndExpand(dh: dh,
enc: enc,
pkRm: selfRepresentation,
kem: kem,
kdf: kem.kdf), encapsulated: enc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting is off here


/// A type that ``HPKE`` uses to encode the public key.
public protocol HPKEPublicKeySerialization {
/// Creates a public key from an encoded representation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments here are also wrongly indented

let key: DHSK

init(_ privateKey: DHSK, kem: HPKE.KEM) throws {
// TODO: Validate Ciphersuite Mismatches
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one

@Lukasa
Copy link
Collaborator Author

Lukasa commented Jun 12, 2023

@FranzBusch Will it be acceptable for you if I apply those proposals in a new PR?

@FranzBusch
Copy link
Member

@FranzBusch Will it be acceptable for you if I apply those proposals in a new PR?

Totally fine by me!

Motivation

WWDC has arrived! 🎉 As part of the celebration, let's
bring Crypto up to speed with the new CryptoKit API surface.

Modifications

Substantial new docstrings
HPKE support

Result

WWDC 2023 support.
@Lukasa Lukasa merged commit c433cd3 into apple:main Jun 13, 2023
7 of 8 checks passed
@Lukasa Lukasa deleted the cb-wwdc23 branch June 13, 2023 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠️ needs-major-version-bump For PRs that when merged cause a bump of the major version, ie. x.0.0 -> (x+1).0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants