Commit Graph

125 Commits

Author SHA1 Message Date
Cory Benfield c433cd3341
Bring over the WWDC 2023 CryptoKit API (#181)
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.
2023-06-13 18:27:01 +01:00
tomer doron 940a631a68
update code of conduct (#182)
motivation: align CoC across the swift project

changes: change CoC to link to the swift.org version
2023-06-06 10:56:39 -07:00
Joey dcf0815f8f
Documentation - Typos (#179) 2023-04-24 01:50:32 -07:00
Evan Wilde 33a20e650c
Set CRYPTO_IN_SWIFTPM (#177)
Needed to expose SecureEncalve through SwiftCrypto when building for
Swift-Certificates. CRYPTO_IN_SWIFTPM is set all of the time in
package.swift, while CRYPTO_IN_SWIFTPM_FORCE_BUILD_API is only set in
development. Lets enable the one that's on all of the time, and remove
the one that isn't so that we get our declarations.
2023-04-19 06:40:30 +01:00
Brandon 65f8c60ab3
ChaCha20 CTR Encryption (#169)
* OpenSSLChaCha20CTR Implementation. Wraps CCryptoBoringSSL_CRYPTO_chacha_20.

* Insecure extension implementing the ChaCha20 CTR encrypt method.

* Added ChaCha20CTR Tests based on vectors provided in RFC9001 Appendix A.5

* Corrected year in header

* Changed return type to Data. Removed redundant pointer castings. Removed unnecessary array allocations in favor of withUnsafeBytes.

* Introduced a typed ChaCha20CTR Nonce and Counter struct in order to help enforce parameter constraints and type safety.

* Formatting

* Updated tests to use new Nonce and Counter structs. Added additional test checking for invalid parameters.

* Switch to HexStrings for better readability.

* Removed empty line at top of file

* Fixed UInt32.max counter assertion.

* Moved the bindMemory calls out of the function and copied a note from a similar situation elsewhere in the codebase.

* Formatting

* Implemented an _encryptContiguous function that prevents having to use the withContiguousStorageIfAvailable method. If our DataProtocol is contiguous we encrypt directly, otherwise we consolidate before encrypting. Removed inLen param from chacha20CTR call.

* Replaced the chacha20CTR function with a direct call to CCryptoBoringSSL_CRYPTO_chacha_20.

* Counter is now backed by a UInt32 instead of Data. Removed Sequence conformance.

* Formatting

* Formatting

* Replaced unsafe code (unsafeBytes and load) with a more generic and safer UInt32 construction.

* Replaced counterAsUInt32 definitions with integer literals to avoid symmetric bugs in the load.

* Updated _CryptoExtras/CMakeList.txt
2023-04-18 10:06:55 +01:00
Cory Benfield 1863cc9dcf
Drop support for Swift 5.5 (#172)
* Drop support for Swift 5.5

This patch drops support for Swift 5.5.

* Drop LinuxMain.swift
2023-04-13 16:46:47 +01:00
Cory Benfield 6d9c36b4be
Update BoringSSL to abfd5ebc87ddca0fab9fca067c9d7edbc355eae8 (#171)
* Update BoringSSL vendoring scripts for new perlasm

* Update BoringSSL to abfd5ebc87ddca0fab9fca067c9d7edbc355eae8
2023-04-13 13:02:12 +01:00
Yim Lee a56d70a286
Add docker-compose file for Swift 5.8 and 5.9 (#170) 2023-04-13 09:47:52 +01:00
Alexander Cyon 3ea0bdb8fd
Add five new Wycheproof ECDSA test vectors using IEEE P1363 format (#167)
* Add five new ECDSA Wycheproof test vectors with signatures on IEEE P1363 format, remove four unused Wycheproof test vectors.

* Revert unnecessary protocol extension
2023-04-11 09:07:15 +01:00
Alexander Cyon d1047c1c9a
Update Wycheproof ecdsa_secp*_test.json to v1 (#166) 2023-04-06 17:43:59 +01:00
Alexander Cyon 401a7a8ba7
Update Wycheproof ecdh_secp521r1_ecpoint_test.json to v1 (#164)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-04-03 12:46:52 +01:00
Alexander Cyon 944428373d
Update Wycheproof ecdh_secp521r1_test.json to v1 (#163)
* Update ASN1 test helpers to not fatalError but rather fail/throw, needed for some new tests in Wycheproof v1

* Update Wycheproof ecdh_secp521r1_test.json to v1

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-04-03 12:36:32 +01:00
Alexander Cyon 5a1b404183
Update Wycheproof ecdh_secp384r1_test.json to v1 (#162)
* Update ASN1 test helpers to not fatalError but rather fail/throw, needed for some new tests in Wycheproof v1

* Update Wycheproof ecdh_secp384r1_test.json to v1

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-04-03 11:50:32 +01:00
Alexander Cyon 3c4009af05
Update Wycheproof ecdh_secp384r1_ecpoint_test.json to v1 (#161)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-04-03 11:26:19 +01:00
Alexander Cyon 22a06540cc
Update Wycheproof x25519_test.json to v1 (#155)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-04-03 11:14:00 +01:00
Alexander Cyon 7d7419ebba
Update Wycheproof aes_gcm.json to v1 (#156)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-04-03 10:57:35 +01:00
Alexander Cyon f2125b625f
Update Wycheproof chacha20_poly1305 to v1 (#157)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-04-03 10:49:41 +01:00
Alexander Cyon 959c1fe152
Update Wycheproof ecdh_secp256r1_ecpoint_test.json to v1 (#158)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-04-03 10:36:04 +01:00
Alexander Cyon 36d5ec4458
Update eddsa_test.json which has been renamed to ed25519_test.json, so we use the new name. (#159)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2023-04-03 10:27:26 +01:00
Alexander Cyon 6be84be0bd
Update Wycheproof ecdh_secp256r1_test.json to v1 (#160) 2023-04-03 10:14:02 +01:00
Alexander Cyon 25a68d63b7
Fix broken link (#153) 2023-03-24 08:01:55 +00:00
Yim Lee 5d8b14d227
Exclude AES from CMake (#152)
* Exclude AES from CMake

SwiftPM doesn't need it and this would allow removal of CCryptoBoringSSL dependency on non-Darwin platforms, thus reducing SwiftPM size.

* Update update_cmakelists.sh to exclude AES source files
2023-03-16 09:19:55 +00:00
Cory Benfield da0fe44138
Fixup CryptoExtras RSA public key formats (#151)
Motivation

CryptoExtras RSA public keys support being exported in DER and PEM form.
These exports work great, but it turns out they are inconsistent between
the Darwin and non-Darwin implementations. Darwin platforms would export
the public keys in PKCS1 format, while non-Darwin was exporting them as
SPKI. This isn't great!

Modifications

- Make the two consistent. `.derRepresentation` should export SPKI
    formatted public keys, because that's what it does for all the EC
    keys.
- Add `.pkcs1DERRepresentation` and `.pkcs1PEMRepresentation` for those
    users that require the PKCS1 formatted key.

Result

Key export types are now consistent on all platforms.
2023-03-10 11:38:36 +00:00
Saleem Abdulrasool 80a6e3edc1
build: add `ARM64` spelling for Windows (#148)
Windows uses `ARM64` for the `CMAKE_SYSTEM_PROCESSOR` which does not
match the existing spellings.  Add the special case for Darwin while in
the area.
2023-03-02 12:13:00 -08:00
Andrew Barba a1b800581e
Support SwiftWasm (#145)
Co-authored-by: Max Desiatov <m_desiatov@apple.com>
2023-02-09 06:04:16 -08:00
Yim Lee 935c74be2f
Set up CMake build for _CryptoExtras (#144)
* Set up CMake build for _CryptoExtras

* Add CMakeLists.txt to exclude list
2023-01-26 10:51:20 +00:00
Cory Benfield 75ec60b8b4
Update BoringSSL to 45b8d7bbd771cbf7e116db2ba1f1cc7af959497e (#143)
* Update vendoring scripts for new BoringSSL

* Update BoringSSL to 45b8d7bbd771cbf7e116db2ba1f1cc7af959497e

* Minor tweak
2023-01-19 17:30:15 +00:00
Cory Benfield d330d21edf
Add AES block function to CryptoExtras (#142)
In some cases developers have need of AES modes other than what we
support today, or need the ability to implement algorithms that require
access to the core AES permutation function. As a starting point, we can
provide access to the AES block function in CryptoExtras.
2023-01-18 16:07:44 +00:00
Saleem Abdulrasool 9cc89f0170
build: adjust linking for Crypto (#137)
The package DLL `Crypto.dll` was building the BoringSSL wrapper
(`CryptoBoringWrapper`) in the style that the user requested (static or
shared).  However, there is a single user of the library and is not
directly included by the SPM client.  Furthermore, the library was not
setup for installation which makes redistribution of it impossible.
Always build the library in a static mode to allow compaction into the
`Crypto` target.
2023-01-06 09:04:40 +00:00
Yim Lee 92a04c10fc
Link Foundation (#136)
To address error seen in https://ci-external.swift.org/job/swiftpm-PR-windows/581/console:

```
FAILED: bin/CryptoBoringWrapper.dll Sources/CryptoBoringWrapper/CMakeFiles/CryptoBoringWrapper.dir/AEAD/BoringSSLAEAD.swift.obj Sources/CryptoBoringWrapper/CMakeFiles/CryptoBoringWrapper.dir/CryptoKitErrors_boring.swift.obj swift/CryptoBoringWrapper.swiftmodule lib/CryptoBoringWrapper.lib 
cmd.exe /C "cd . && T:\1\bin\swiftc.exe -output-file-map Sources\CryptoBoringWrapper\CMakeFiles\CryptoBoringWrapper.dir\Release\output-file-map.json -incremental -j 36 -emit-library -o bin\CryptoBoringWrapper.dll -module-name CryptoBoringWrapper -module-link-name CryptoBoringWrapper -emit-module -emit-module-path swift\CryptoBoringWrapper.swiftmodule -emit-dependencies -DCryptoBoringWrapper_EXPORTS -O -libc MD -I C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\swift-crypto\Sources\CCryptoBoringSSL\include -I C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\swift-crypto\Sources\CCryptoBoringSSLShims\include -I swift C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\swift-crypto\Sources\CryptoBoringWrapper\AEAD\BoringSSLAEAD.swift C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\swift-crypto\Sources\CryptoBoringWrapper\CryptoKitErrors_boring.swift    -Xlinker -implib:lib\CryptoBoringWrapper.lib -L T:\12\lib  -L T:\12\lib  -L T:\12\lib lib\CCryptoBoringSSL.lib  lib\CCryptoBoringSSLShims.lib  lib\CCryptoBoringSSL.lib && cd ."
C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\swift-crypto\Sources\CryptoBoringWrapper\AEAD\BoringSSLAEAD.swift:17:8: error: no such module 'Foundation'

import Foundation
```
2022-12-05 09:40:28 +00:00
Cory Benfield 71ae6adf89
Add Linux support for PKCS#1 RSA public keys (#135)
Motivation

The init(derRepresentation:) and init(pemRepresentation:) constructors
for RSA public keys support both PKCS#8 and PKCS#1 key formats on
Darwin. This support was missing from Linux, with only PKCS#8 support.
This patch brings the two platforms into parity.

Modifications

Add code to try both versions on Linux.
Add tests.

Results

PKCS#1 keys are supported on Linux too!
2022-11-21 09:45:13 -08:00
Cory Benfield f652300628
Update BoringSSL to 0faffc7a30eeb195248ea43056f4848e2a9b1c6d (#134) 2022-11-14 11:17:06 +00:00
Franz Busch d11194ad26
Provide AES-GCM-SIV in CryptoExtras (#133)
# Motivation
BoringSSL exposes AES-GCM-SIV algorithms which are in general useful to have and provide a nonce-misuse resistant mode of AES-GCM. Since, `CryptoKit` is not exposing AES-GCM-SIV we need to add this to `_CryptoExtras`

# Modification
Exposes `AES-GCM-SIV` through `_CryptoExtras`.

# Result
We can now use `AES-GCM-SIV` through `_CryptoExtras`.
2022-10-14 09:50:36 +01:00
George Barnett 1c59986eaf
Raise minimum supported Swift version from 5.4 to 5.5 (#131)
Motivation:

Old Swift versions are periodically dropped. Now that 5.7 has been
released, 5.4 will be dropped.

Modifications:

- Update tools version
- Remove 5.4 docker-compose
- Update 5.7 docker-compose to use released image and move from focal to
  jammy
- Update docs

Result:

Swift 5.5 is the minimum supported Swift version
2022-09-28 09:25:21 -07:00
George Barnett d89caf3006
Update BoringSSL to cab31f65f1ad6e6daca62e95b25dd6cd805fce0b (#132) 2022-09-28 12:08:04 +01:00
Eric Miotto e5dabe7f3a
build: use cctols ranlib on Darwin (#129)
This complements the change in #105 and allows to build with a CMake
newer than 3.19.6.

Addresses rdar://99435188
2022-09-02 16:57:50 +01:00
Alex Shatberashvili 30eab5ad37
Make BoringSSL wrapper match CryptoKit behaviour when working with x9.63 (#128)
* Make BoringSSL wrapper match CryptoKit behaviour when working with x963 representation

* Revert Package.swift changes

* Fix Signing tests and add test cases for invalid key lengths
2022-08-23 11:47:08 +01:00
Cory Benfield 5fdc8c4daa
Validate missing imports in CI (#127) 2022-08-16 01:28:09 -07:00
Cory Benfield 4832fa0d13
Update Swift Crypto for the Ventura beta API (#123)
* Bring over API files from macOS Ventura

* Implement the new API surface

This patch implements the new API surface, and removes anything that's
no longer compatible with the expected API surface from CryptoKit
2022-06-27 14:12:38 +01:00
Saleem Abdulrasool 126981ae16
Crypto: explicitly type the array slice (#122)
Without the explicit typing, the build fails with recent toolchain
builds expecting the type to conform to an incorrect type.  This
repairs the build.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2022-06-21 08:48:03 -07:00
Cory Benfield 57a0c7dde9
Update BoringSSL to 1f51cfc7d7f54d2bee30bb5793470ef9c36a5083 (#121) 2022-06-20 14:24:03 +01:00
swiftty 9580d7e187
Fix ASN.1 serialization when content greater than or equal to 128 bytes (#120) 2022-06-17 17:09:49 +01:00
Daiki Matsudate 03399ef465
truncating for big contentLength (#119)
When contentLength is greater than 8 bits, i.e., greater than UInt8.max, the original implementation crashes.
To work around this, use UInt8.init(truncatingIfNeeded:) to truncate only the lower 8 bits.
2022-06-16 23:44:20 -07:00
Cory Benfield 30b30ef3a1
Use 5.7 nightlies (#118) 2022-06-13 13:39:40 +01:00
Tim Condon eb2d582c29
Update Python script to Python 3 (#117) 2022-05-17 10:46:02 +01:00
Cory Benfield d9825fa541
Update BoringSSL to f961de5c47ed265c3e758ec70dd15ece20809962 (#115)
This patch also cleans up an include issue. The actual code change is in
`scripts/vendor_boringssl.sh`, the rest is just the update.
2022-04-21 10:39:48 +01:00
Cory Benfield d180057628
Update BoringSSL to 2fc6d38391cb76839c76b2a462619e7d69fd998d (#113) 2022-04-20 03:50:13 -07:00
Cory Benfield 17d95a6782
Avoid unnecessary copies of BoringSSL (#94)
Motivation:

When using only the CryptoKit API on Apple platforms we have always
thunked through to the CryptoKit interface and implementation. However,
we didn't do a thorough job of preventing the BoringSSL target from
getting compiled and linked.

We can do a better job now, which will save compile times and binary
sizes in many cases.

Modifications:

- Change Package.swift to express a target specific dependency in most
  cases.
- Preserve a development mode which overrides that target specific
  dependency.
- Add the missing compile guards.

Results:

Smaller binaries and faster compiles on Apple platforms.
2022-04-20 11:47:19 +01:00
Fabian Fett 12a1784190
Drop support for Swift 5.2 and 5.3 (#111)
As outlined in a [Swift forums post in November ’21](https://forums.swift.org/t/swiftnio-swift-version-support/53232), SwiftNIO will only support the latest non-patch Swift release and the 2 immediately prior non-patch versions.

In this commit we drop support for Swift 5.2 and 5.3. We update CI for Swift 5.4 to run on bionic instead of focal to ensure that we still test bionic.
2022-04-20 08:17:41 +01:00
Fabian Fett ce8d18032f
Use SPM API diff checker (#112) 2022-04-19 17:15:40 +01:00