Skip to content

Commit 9d79415

Browse files
Bind out ed25519 support (#630)
1 parent bc205fa commit 9d79415

File tree

16 files changed

+219
-33
lines changed

16 files changed

+219
-33
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ jobs:
223223
permissions:
224224
id-token: write # This is required for requesting the JWT
225225
steps:
226+
- uses: ilammy/setup-nasm@v1
226227
- name: configure AWS credentials (containers)
227228
uses: aws-actions/configure-aws-credentials@v4
228229
with:
@@ -233,7 +234,6 @@ jobs:
233234
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
234235
python builder.pyz build -p ${{ env.PACKAGE_NAME }} --python "C:\\hostedtoolcache\\windows\\Python\\3.8.10\\${{ matrix.arch }}\\python.exe"
235236
236-
237237
macos:
238238
runs-on: macos-14 # latest
239239
permissions:

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ python3 -m pip install .
3434

3535
To use from your Python application, declare `awscrt` as a dependency.
3636

37-
### OpenSSL and LibCrypto (Unix only)
37+
### OpenSSL and LibCrypto
3838

3939
aws-crt-python does not use OpenSSL for TLS.
4040
On Apple and Windows devices, the OS's default TLS library is used.
@@ -56,8 +56,19 @@ AWS_CRT_BUILD_USE_SYSTEM_LIBCRYPTO=1 python3 -m pip install --no-binary :all: --
5656
```
5757
( `--no-binary :all:` ensures you do not use the precompiled wheel from PyPI)
5858

59-
You can ignore all this on Windows and Apple platforms, where aws-crt-python
60-
uses the OS's default libraries for TLS and cryptography math.
59+
aws-crt-python also exposes a number of cryptographic primitives.
60+
On Unix, those depend on libcrypto as described above.
61+
On Apple and Windows OS level crypto libraries are used whenever possible.
62+
One exception to above statement is that for ED25519 keygen on Windows and Apple,
63+
libcrypto is used as no viable OS level alternative exists. In that case Unix level notes
64+
about libcrypto apply to Apple and Windows as well. Libcrypto usage for ED25519 support is
65+
enabled on Windows and Apple by default and can be disabled by setting environment variable
66+
`AWS_CRT_BUILD_DISABLE_LIBCRYPTO_USE_FOR_ED25519_EVERYWHERE` as follows:
67+
(Note: ED25519 keygen functions will start returning not supported error in this case)
68+
```sh
69+
AWS_CRT_BUILD_DISABLE_LIBCRYPTO_USE_FOR_ED25519_EVERYWHERE=1 python3 -m pip install --no-binary :all: --verbose awscrt
70+
```
71+
( `--no-binary :all:` ensures you do not use the precompiled wheel from PyPI)
6172

6273
### AWS_CRT_BUILD_USE_SYSTEM_LIBS ###
6374

awscrt/crypto.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,42 @@ def verify(self, signature_algorithm: RSASignatureAlgorithm,
171171
Returns True if signature matches and False if not.
172172
"""
173173
return _awscrt.rsa_verify(self._binding, signature_algorithm, digest, signature)
174+
175+
176+
class ED25519ExportFormat(IntEnum):
177+
"""ED25519 Export format"""
178+
179+
RAW = 0
180+
"""
181+
Raw bytes.
182+
"""
183+
184+
OPENSSH_B64 = 1
185+
"""
186+
Base64 encoded OpenSSH format as defined in RFC 8709.
187+
"""
188+
189+
190+
class ED25519(NativeResource):
191+
def __init__(self, binding):
192+
super().__init__()
193+
self._binding = binding
194+
195+
@staticmethod
196+
def new_generate() -> 'ED25519':
197+
"""
198+
Generates a new instance of ED25159 key pair.
199+
"""
200+
return ED25519(binding=_awscrt.ed25519_new_generate())
201+
202+
def export_public_key(self, export_format: ED25519ExportFormat) -> bytes:
203+
"""
204+
Exports public part of the key in specified format.
205+
"""
206+
return _awscrt.ed25519_export_public_key(self._binding, export_format)
207+
208+
def export_private_key(self, export_format: ED25519ExportFormat) -> bytes:
209+
"""
210+
Exports public part of the key in specified format.
211+
"""
212+
return _awscrt.ed25519_export_private_key(self._binding, export_format)

crt/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "")
2626
set(BUILD_TESTING OFF CACHE BOOL "")
2727
include(CTest)
2828

29+
option(AWS_USE_LIBCRYPTO_TO_SUPPORT_ED25519_EVERYWHERE "Set this if you want to use libcrypto to support ed25519 on Window/Apple" ON)
30+
2931
# On Unix we use S2N for TLS and AWS-LC crypto.
3032
# (On Windows and Apple we use the default OS libraries)
31-
if(UNIX AND NOT APPLE)
33+
if ((UNIX AND NOT APPLE) OR AWS_USE_LIBCRYPTO_TO_SUPPORT_ED25519_EVERYWHERE)
3234
option(USE_OPENSSL "Set this if you want to use your system's OpenSSL compatible libcrypto" OFF)
3335
include(AwsPrebuildDependency)
3436

@@ -41,6 +43,14 @@ if(UNIX AND NOT APPLE)
4143
-DBUILD_TESTING=OFF
4244
)
4345

46+
if (APPLE OR WIN32)
47+
# Libcrypto implementations typically have several chunky pregenerated tables that add a lot
48+
# to artifact size. We dont really need them for ed25519 case on win/mac, so favor
49+
# smaller binary over perf here.
50+
# In future if there is more usage of lc on win/mac consider removing this
51+
list(APPEND AWSLC_CMAKE_ARGUMENTS -DOPENSSL_SMALL=1)
52+
endif()
53+
4454
if(CMAKE_C_COMPILER_ID MATCHES "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS "5.0")
4555
# Disable AVX512 on old GCC that not supports it.
4656
list(APPEND AWSLC_CMAKE_ARGUMENTS -DMY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX=ON)
@@ -54,6 +64,10 @@ if(UNIX AND NOT APPLE)
5464
)
5565
endif()
5666

67+
68+
endif()
69+
70+
if(UNIX AND NOT APPLE)
5771
# prebuild s2n-tls.
5872
aws_prebuild_dependency(
5973
DEPENDENCY_NAME S2N

crt/aws-lc

0 commit comments

Comments
 (0)