sodium / NaCl / tink
sodium
libsodium documentation
rust実装: https://github.com/sodiumoxide/sodiumoxide
js実装: https://github.com/jedisct1/libsodium.js/
box
Key exchange: X25519
Encryption: XSalsa20 stream cipher
Authentication: Poly1305 MAC
nonceのユニーク性は開発者責務
randombytes_buf(): nonceサイズの乱数衝突は無視できると仮定
メッセージの到達・順序保証をしたい場合はincrementでも
https://docs.rs/sodiumoxide/0.2.6/sodiumoxide/crypto/box_/curve25519xsalsa20poly1305/struct.Nonce.html#method.increment_le
状態管理の必要性が出てくる
https://crypto.stackexchange.com/questions/20135/what-is-salsa20-nonce-and-its-requirements
Salsa20は64 bits nonceであるが、XSalsa20は192 bits nonceなので乱数で基本OK
(補足)nonceに関して良い記事:本当は怖いAES-GCMの話
メッセージサイズは8KB以下推奨(大きいメッセージはchunk)
パフォーマンス
public-key authenticated encryption API
box::gen_keypair
box::seal
否認防止は保証しない (repudiability)
receiverは自由にメッセージを変えられるので第三者に特定のメッセージが特定の送り手から送られてきたことは証明できない
box::open
Sealed boxes
https://libsodium.gitbook.io/doc/public-key_cryptography/sealed_boxes
ephemeral鍵ペアで暗号化されるのでメッセージの完全性を保証しつつsenderのidentityは検証不可。送信者も破棄したephemeral鍵で暗号化したメッセージはあとで復号することはできなくなる
ここでのephemeral鍵ペアは前方秘匿性のためというより、ここの暗号文の暗号化に用いる送信者鍵のephemeral化するもの
ephemeral_pk ‖ box(m, recipient_pk, ephemeral_sk, nonce=blake2b(ephemeral_pk ‖ recipient_pk))
box::seal_anonymous
box::open_anonymous
NaCl
https://gyazo.com/f7aca120ae8c6c2231feb2d34545289f
http://nacl.cr.yp.to/box.html
golang: https://godoc.org/golang.org/x/crypto/nacl
tink
実装: https://github.com/google/tink
rust実装: https://github.com/project-oak/tink-rust
RWC'19
slide
https://medium.com/@jryancanty/use-googles-tink-for-asymmetric-encryption-c8957e6b5506
Comparison
wiki
awesome-cryptography
Mitigating Cryptographic Mistakes by Design