Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Zig で TLS1.3 を実装している話
Search
Naoki MATSUMOTO
October 07, 2023
Technology
280
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Zig で TLS1.3 を実装している話
Naoki MATSUMOTO
October 07, 2023
More Decks by Naoki MATSUMOTO
See All by Naoki MATSUMOTO
Rootless な環境における eBPF の活用
mt2naoki
4
1k
Mewz on libkrun
mt2naoki
2
1.2k
詳解 bypass4netns: Rootless Containers Network の仕組みと高速化
mt2naoki
2
2k
QUIC の仕組み(Handshake)
mt2naoki
1
1k
bypass4netns: Accelerating TCP/IP Communications in Rootless Containers
mt2naoki
0
340
Rootless コンテナはいいぞ
mt2naoki
4
1.4k
コンテナ技術における最新の研究動向
mt2naoki
15
12k
Efficient Container Image Updating in Low-bandwidth Networks with Delta Encoding
mt2naoki
0
1.9k
TLS 1.3 で学ぶ暗号技術
mt2naoki
0
650
Other Decks in Technology
See All in Technology
Oracle Cloud Infrastructure IaaS 新機能アップデート 2026/6 - 2026/8
oracle4engineer
PRO
0
140
V8コントリビュート超入門
riyaamemiya
0
160
クロスボーダーM&AのValue Upを支えるプロダクト開発。日米チームのハブになったプロダクトエンジニアの実践 / Product Engineering Conference 2026
genda
0
110
2026-09-04 SRE Tech Talk #15 怠惰なTerraform / Lazy Terraform
masasuzu
0
230
幾何アルゴリズムで なめらかなピン操作を / iOSDC Japan 2026 / smoothpin
kazumanagano
0
250
振り返りこそエンジニアの本領
negima
0
360
Multica × 長期記憶:40個のミニプロジェクト管理
eiei114
1
230
【視聴者参加型!】AWSセキュリティアンチパターンクイズ
syoshie
1
490
日経電子版を支えていく Kasane Design System/fec_fukuoka
nikkei_engineer_recruiting
0
610
薬剤師(ドメインエキスパート)と一緒に育てる薬局向けAIアシスタント
kakehashi
PRO
2
140
OpenTelemetryのメトリクスをCloudWatchに送ってPromQLで見てみた
ota1022
0
120
OpenTelemetry eBPF Instrumentationの舞台裏 / Behind the Scenes of OpenTelemetry eBPF Instrumentation
ymotongpoo
3
960
Featured
See All Featured
Un-Boring Meetings
codingconduct
0
410
What's in a price? How to price your products and services
michaelherold
247
13k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Building the Perfect Custom Keyboard
takai
2
870
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
520
WCS-LA-2024
lcolladotor
0
820
A Soul's Torment
seathinner
7
3.6k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Become a Pro
speakerdeck
PRO
31
6.2k
Transcript
Zig で TLS1.3 を 実装している話 京都大学情報学研究科 松本直樹
Zig • シンプル • comptime によるコンパイル時最適化 • マルチプラットフォーム対応 • 組み込みも対象
TLS1.3 • TLS1.2 までの仕様を整理し、新しい TLS として策定(RFC8446) • 1-RTT フルハンドシェイク •
0-RTT Resumption 等
TLS1.3 のフルハンドシェイク • 結構シンプル
実装のポイント1: 鍵導出(Key Schedule) 1. PSKから初期シークレット導出 2. DHでシークレットを共有 3. メッセージのハッシュから ハンドシェイク用の鍵を導出
4. ハンドシェイク完了後、 アプリケーション用の鍵を導出 面倒!
実装のポイント1: 鍵導出(Key Schedule) • TLS1.3 の Test Vector がある(RFC8448) •
Step by Step で鍵導出の実装を検証できる
実装のポイント2: CertificateVerify • 証明書の秘密鍵でハンドシェイクのメッセージを署名 → サーバーが秘密鍵を保持しているか確認 • 実際のステップ 1. 証明書・秘密鍵を読み込む
2. Certificate を送信 3. メッセージのハッシュを生成 4. 署名 5. CertificateVerify を送信 • 簡単そう…?
実装のポイント2: CertificateVerify • Certificate, CertificateVerify に必要な機能 • X.509 証明書を読み込む →
そんなものはない • 秘密鍵を読み込む → そんなものはない • RSA or ECDSA で署名, 検証する • ecdsa_secp256r1_sha256 → ある • rsa_pss_rsae_sha256 → そんなものはない • rsa_pkcs1_sha256 → そんなものはない
いっぱい実装しよう • ASN.1(必要な部分のみ) • X.509(RFC 5280 Section 4.1. Basic Certificate
Fields) • 秘密鍵 • RSA(RFC 8017 Section A.1. RSA Key Representation) • EC(RFC 5915 Section 3. Elliptic Curve Private Key Format) • RSAでの署名,検証(RFC8017, PKCS#1) • RSA自体の実装(モンゴメリ冪乗法 等) • rsa_pss_rsae(Section 8.1. RSASSA-PSS) • MGF1も(Section B.2.1. MGF1) • rsa_pkcs1(Section 8.2. RSASSA-PKCS1-v1_5)
実装した結果 • Client • www.google.com につながった🎉 • Server • chrome
からの接続が可能🎉
GREASE • Chrome で一部のフィールドに無意味なランダムを挿入する → TLS 実装の堅牢化を意図
まとめ • Zig で TLS1.3 を実装した • 既存のWebサイト, ブラウザで接続できた •
TLS, PKI に関する知見が深まった • Zig に対する知見が深まった • たまによく SEGV する • Zig はいいぞ(まだまだ安定してないけど) • https://github.com/shiguredo/tls13-zig