Skip to content

Commit bd24c20

Browse files
committed
Build 3.6.5 version
1 parent 5e5ee8b commit bd24c20

File tree

5 files changed

+166
-17
lines changed

5 files changed

+166
-17
lines changed

.github/oldver.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"version": 2,
33
"data": {
44
"upstream": {
5-
"version": "4.0.0",
6-
"gitref": "refs/tags/v4.0.0",
7-
"revision": "e90c16439e2158ca5660db36b27648332cddd2cf"
5+
"version": "3.6.5",
6+
"gitref": "refs/tags/v3.6.5",
7+
"revision": "d934b47669d1cc60c72caecae2ae2a45aea70c79"
88
}
99
}
1010
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [mbedtls](https://tls.mbed.org)@v4.0.0 [![Build and test library](https://github.com/zig-devel/mbedtls/actions/workflows/library.yml/badge.svg)](https://github.com/zig-devel/mbedtls/actions/workflows/library.yml)
1+
# [mbedtls](https://tls.mbed.org)@v3.6.5 [![Build and test library](https://github.com/zig-devel/mbedtls/actions/workflows/library.yml/badge.svg)](https://github.com/zig-devel/mbedtls/actions/workflows/library.yml)
22

33
An open source, portable, easy to use, readable and flexible TLS library
44

@@ -7,7 +7,7 @@ An open source, portable, easy to use, readable and flexible TLS library
77
Install library:
88

99
```sh
10-
zig fetch --save zig fetch --save https://github.com/zig-devel/mbedtls/archive/refs/tags/4.0.0-0.tar.gz
10+
zig fetch --save zig fetch --save https://github.com/zig-devel/mbedtls/archive/refs/tags/3.6.5-0.tar.gz
1111
```
1212

1313
Statically link with `mod` module:

build.zig

Lines changed: 151 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,171 @@
11
const std = @import("std");
22

3+
const sources_crypto = [_][]const u8{
4+
"aes.c",
5+
"aesce.c",
6+
"aesni.c",
7+
"aria.c",
8+
"asn1parse.c",
9+
"asn1write.c",
10+
"base64.c",
11+
"bignum.c",
12+
"bignum_core.c",
13+
"bignum_mod.c",
14+
"bignum_mod_raw.c",
15+
"block_cipher.c",
16+
"camellia.c",
17+
"ccm.c",
18+
"chacha20.c",
19+
"chachapoly.c",
20+
"cipher.c",
21+
"cipher_wrap.c",
22+
"cmac.c",
23+
"constant_time.c",
24+
"ctr_drbg.c",
25+
"des.c",
26+
"dhm.c",
27+
"ecdh.c",
28+
"ecdsa.c",
29+
"ecjpake.c",
30+
"ecp.c",
31+
"ecp_curves.c",
32+
"ecp_curves_new.c",
33+
"entropy.c",
34+
"entropy_poll.c",
35+
"error.c",
36+
"gcm.c",
37+
"hkdf.c",
38+
"hmac_drbg.c",
39+
"lmots.c",
40+
"lms.c",
41+
"md.c",
42+
"md5.c",
43+
"memory_buffer_alloc.c",
44+
"nist_kw.c",
45+
"oid.c",
46+
"padlock.c",
47+
"pem.c",
48+
"pk.c",
49+
"pk_ecc.c",
50+
"pk_wrap.c",
51+
"pkcs12.c",
52+
"pkcs5.c",
53+
"pkparse.c",
54+
"pkwrite.c",
55+
"platform.c",
56+
"platform_util.c",
57+
"poly1305.c",
58+
"psa_crypto.c",
59+
"psa_crypto_aead.c",
60+
"psa_crypto_cipher.c",
61+
"psa_crypto_client.c",
62+
"psa_crypto_driver_wrappers_no_static.c",
63+
"psa_crypto_ecp.c",
64+
"psa_crypto_ffdh.c",
65+
"psa_crypto_hash.c",
66+
"psa_crypto_mac.c",
67+
"psa_crypto_pake.c",
68+
"psa_crypto_rsa.c",
69+
"psa_crypto_se.c",
70+
"psa_crypto_slot_management.c",
71+
"psa_crypto_storage.c",
72+
"psa_its_file.c",
73+
"psa_util.c",
74+
"ripemd160.c",
75+
"rsa.c",
76+
"rsa_alt_helpers.c",
77+
"sha1.c",
78+
"sha256.c",
79+
"sha3.c",
80+
"sha512.c",
81+
"threading.c",
82+
"timing.c",
83+
"version.c",
84+
"version_features.c",
85+
};
86+
87+
const sources_x509 = [_][]const u8{
88+
"pkcs7.c",
89+
"x509.c",
90+
"x509_create.c",
91+
"x509_crl.c",
92+
"x509_crt.c",
93+
"x509_csr.c",
94+
"x509write.c",
95+
"x509write_crt.c",
96+
"x509write_csr.c",
97+
};
98+
99+
const sources_tls = [_][]const u8{
100+
"debug.c",
101+
"mps_reader.c",
102+
"mps_trace.c",
103+
"net_sockets.c",
104+
"ssl_cache.c",
105+
"ssl_ciphersuites.c",
106+
"ssl_client.c",
107+
"ssl_cookie.c",
108+
"ssl_debug_helpers_generated.c",
109+
"ssl_msg.c",
110+
"ssl_ticket.c",
111+
"ssl_tls.c",
112+
"ssl_tls12_client.c",
113+
"ssl_tls12_server.c",
114+
"ssl_tls13_client.c",
115+
"ssl_tls13_generic.c",
116+
"ssl_tls13_keys.c",
117+
"ssl_tls13_server.c",
118+
};
119+
3120
pub fn build(b: *std.Build) void {
4121
const target = b.standardTargetOptions(.{});
5122
const optimize = b.standardOptimizeOption(.{});
6123

7124
const upstream = b.dependency("mbedtls", .{});
8125

9-
const mod = b.createModule(.{
10-
.link_libc = true,
11-
.target = target,
12-
.optimize = optimize,
126+
const lib = b.addLibrary(.{
127+
.name = "mbedtls",
128+
.linkage = .static,
129+
.root_module = b.createModule(.{
130+
.link_libc = true,
131+
.target = target,
132+
.optimize = optimize,
133+
}),
13134
});
135+
lib.addIncludePath(upstream.path("include/"));
136+
lib.installHeadersDirectory(upstream.path("include/psa"), "psa", .{});
137+
lib.installHeadersDirectory(upstream.path("include/mbedtls"), "mbedtls", .{});
138+
139+
// The original mbedtls build builds three separate libraries that you can link separately,
140+
// but for the sake of simplicity we're making one.
141+
lib.addCSourceFiles(.{ .root = upstream.path("library"), .files = &sources_crypto });
142+
lib.addCSourceFiles(.{ .root = upstream.path("library"), .files = &sources_x509 });
143+
lib.addCSourceFiles(.{ .root = upstream.path("library"), .files = &sources_tls });
144+
145+
switch (target.result.os.tag) {
146+
.windows => {
147+
lib.root_module.linkSystemLibrary("bcrypt", .{});
148+
},
149+
.freebsd => {
150+
// mbedtls contains a bug: it explicitly defines _POSIX_C_SOURCE
151+
// despite using the explicit_bzero function, which is only defined as a GNU extension.
152+
// On Linux, _GNU_SOURCE explicitly makes it available, while on FreeBSD
153+
// this results in an `implicit-function-declaration` warning, which zig always converts to an error.
154+
// We explicitly expose all BSD* functions to make this available.
155+
lib.root_module.addCMacro("__BSD_VISIBLE", "1");
156+
},
157+
else => {},
158+
}
14159

15-
_ = mod; // stub
16-
_ = upstream; // stub
160+
b.installArtifact(lib);
17161

18162
// Smoke unit test
19163
const test_mod = b.addModule("test", .{
20164
.root_source_file = b.path("tests.zig"),
21165
.target = target,
22166
.optimize = optimize,
23167
});
24-
// TODO: mod.linkLibrary(lib);
168+
test_mod.linkLibrary(lib);
25169

26170
const run_mod_tests = b.addRunArtifact(b.addTest(.{ .root_module = test_mod }));
27171

build.zig.zon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
.{
22
.name = .mbedtls,
3-
.version = "4.0.0-0",
3+
.version = "3.6.5-0",
44
.fingerprint = 0x841b00c2ce89690e, // Changing this has security and trust implications.
55
.minimum_zig_version = "0.15.1",
66
.dependencies = .{
77
.mbedtls = .{
8-
.url = "https://github.com/Mbed-TLS/mbedtls/archive/e90c16439e2158ca5660db36b27648332cddd2cf.tar.gz",
9-
.hash = "N-V-__8AAKIwiADtY89ifMh8C6X0PHvyBULclU19OYMsiDg_",
8+
.url = "https://github.com/Mbed-TLS/mbedtls/archive/e185d7fd85499c8ce5ca2a54f5cf8fe7dbe3f8df.tar.gz",
9+
.hash = "N-V-__8AAIvwlAIZbpoVC3YR52HdYcdnnw0Zzs6aGpR7wA1K",
1010
},
1111
},
1212
.paths = .{

tests.zig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
const std = @import("std");
22

33
const mbedtls = @cImport({
4-
@cInclude("stdio.h");
4+
@cInclude("mbedtls/version.h");
55
});
66

77
// Just a smoke test to make sure the library is linked correctly.
8-
test {}
8+
test {
9+
var buffer: [16:0]u8 = undefined;
10+
mbedtls.mbedtls_version_get_string(&buffer);
11+
12+
try std.testing.expectEqualStrings(std.mem.sliceTo(&buffer, 0), "3.6.5");
13+
}

0 commit comments

Comments
 (0)