-
Notifications
You must be signed in to change notification settings - Fork 1.7k
intent to implement: dart:crypto #50290
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
Comments
As discussed in the presentation done on |
Just out of curiosity here but would there be any consideration towards wrapping something like Tink as a way to surface
AFAIK Tink is actually built on top of BoringSSL itself but brings that added safety and development experience to the problem working with crypto primitives which as they mention in their readme can sometimes leave developers feel like they are juggling chainsaws 😂 |
I don't think we'll end up with a pluggable implementation (though I do remember that being discussed). I think that we'll rely on eventual tree-shaking for libraries using native code via FFI; so, if user code did not end up using the dart:io implementation of SSL (they either weren't using it or had plugged in their own networking stack), and were not using dart:crypto, then BoringSSL could be tree-shaken away. cc @dcharkes |
I think high-level abstractions like tink might be better provided by a package on pub.dev; if we only offered such APIs I think it would limit the compatibility with external/older systems. And such libraries can hopefully be written on top of The proposal here is to offer the primitives available to JS in browsers through The benefit is that we get a single library that works across all platforms (including web and native). |
This brings in a new dependency of boringssl in the VM through |
That would be ideal indeed. Please note that tree-shaking away native code comes in various flavours with various engineering challenges:
If we would be able to get rid of boringssl in the VM and only have it through (2) and (3) are a lot more engineering effort, and require getting alignment on shipping/requiring a native compiler and linker. @mit-mit At least (2) is where I would want to end up with the Dart eco system and native code. I'm not sure yet about (3). I do not know if (3) would make signing harder or easier. cc @sstrickl |
We are generally moving into a world where packages will come with native code and we have to make that use case as easy as possible. If there are hurdles for The one thing that is currently not possible - as mentioned above - is to re-use the boringSSL that may be available in the Dart VM / Flutter engine - so there may be an opportunity to save some size, which bears the question: How much code size are we talking about here? Looking at
=> Blindly adding all of what is in |
@mkustermann, I'm actually not sure why Logic in Of course, it's possible I've measured it wrong, or that we'll want other features / tweaks that increase size; in which case we'll have to weigh the pros / cons. |
As a side note: The following change allows shrinking the 1 MB diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt
index 7c8e79b..9768805 100644
--- a/android/CMakeLists.txt
+++ b/android/CMakeLists.txt
@@ -14,6 +14,10 @@
cmake_minimum_required(VERSION 3.6.0)
+SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -flto")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
+SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto")
+
enable_language(ASM)
# Set as required by android-sources.cmake included below
@@ -40,7 +44,8 @@ add_definitions(-DOPENSSL_SMALL)
if(ANDROID_ABI STREQUAL "armeabi-v7a")
set(crypto_sources_ARCH ${crypto_sources_linux_arm})
elseif ( ANDROID_ABI STREQUAL "arm64-v8a")
- set(crypto_sources_ARCH ${crypto_sources_linux_aarch64})
+ set(crypto_sources_ARCH)
+ add_definitions(-DOPENSSL_NO_ASM)
elseif ( ANDROID_ABI STREQUAL "x86")
set(crypto_sources_ARCH ${crypto_sources_linux_x86})
elseif ( ANDROID_ABI STREQUAL "x86_64") it will produce
=> ~ 400 kb When clearing out all symbols referenced (in src/symbols.generated.c), it will produce
=> ~ 10 kb So with this simple experiment it seems the base overhead is 10 kb plus any C routines that are actually needed for the Dart code (pay as you go). Another orthogonal question: I can imagine there's useful crypto algorithms one would expect in a |
As discussed with @mkustermann offline, @jonasfj we will need to make the symbols visible and bind to them with |
Agreed, this would be lovely. And shipping crypto as a package would work reasonably, it's a bit unfortunate that apps would include parts of BoringSSL twice, but if we treeshake the parts not used it might be fine.
Nice, I didn't get |
hello, we are wondering if you have updates on crypto library for dart? do you plan to add it soon? thank you in advance! |
I think we were unable to reach consensus for a And while shipping packages with native binaries is a bit hard today, work is progressing on support for native assets. In the mean time the API I wanted to propose for a crypto library is available as a Flutter plugin called I'm closing this issue, as I don't think we're going to implement a |
This is an issue to raise awareness that we're considering adding a new library to the Dart SDK -
dart:crypto
. This would be to provide basic cryptographic APIs to Dart. Some details:For a preview of what the Dart API might look like, see https://github.com/google/webcrypto.dart.
Are you certain you'll ship this?
No, but we're actively considering it. We'll keep this issue updated as plans firm up.
What's the timeframe for shipping it?
We don't have a concrete timeframe; it likely wouldn't happen sooner then ~6 months from now.
Have you considered shipping it as a package instead of as a
dart:
library?Yes. Shipping it as a package is currently challenging as we'd need to ship native code with the package, and, we'd need to coordinate the version of BoringSSL used by the package with the version already shipped in the VM. Additionally, crypto is likely a fundamental enough thing to a platform that it's worth having it as a
dart:
library.The text was updated successfully, but these errors were encountered: