Compare commits
183 Commits
0741768d29
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
b73fd9e64e
|
|||
|
5ef3b4d3e6
|
|||
|
3dda4e8e5b
|
|||
|
a1024943ff
|
|||
|
9eba818de9
|
|||
|
814b5e9442
|
|||
|
6d7273c6a3
|
|||
|
bd9ea78e53
|
|||
|
73d58350c2
|
|||
|
e45d14498c
|
|||
|
f2fd57c342
|
|||
|
ed54a7e6ef
|
|||
|
7c0865fafd
|
|||
|
|
6e681f0ba1
|
||
|
|
0dcbb75879 | ||
|
|
ad25ed2453 | ||
|
|
0491407e58 | ||
|
564977aad7
|
|||
|
c966ad621d
|
|||
|
|
9982409535 | ||
|
|
9e8cbf557d | ||
|
ada9691adc
|
|||
|
48ad5122f2
|
|||
|
10672a86b1
|
|||
|
744b16af6c
|
|||
|
2ff99a832d
|
|||
|
4f048b3981
|
|||
|
49d91c0dc1
|
|||
|
9d9575843c
|
|||
|
1eb7aeab42
|
|||
|
cc4c793835
|
|||
|
1b59475ab9
|
|||
|
0f85300a74
|
|||
|
e4f4e70951
|
|||
|
ae8747de70
|
|||
|
2a9d6dfaac
|
|||
|
9b2c40d662
|
|||
|
04a58e9f66
|
|||
|
1ae6bb6737
|
|||
|
8717ca7594
|
|||
|
09129b38a1
|
|||
|
7f0e18bbe4
|
|||
|
22344b6d96
|
|||
|
f107f82b7c
|
|||
|
50fa9b5179
|
|||
|
46bbd4859e
|
|||
|
e5a56888ad
|
|||
|
6b752c4a77
|
|||
|
18e7545bcf
|
|||
|
37f94aad3f
|
|||
|
f5a41fdb02
|
|||
|
8adc5a58bc
|
|||
|
31ba44c45e
|
|||
|
a3c45895e1
|
|||
|
051eb5fecc
|
|||
|
930c35abff
|
|||
|
e5748b1e41
|
|||
|
bb36536347
|
|||
|
0d1e08fcd1
|
|||
|
47830618e4
|
|||
|
fe5c16450c
|
|||
|
97baed2e2a
|
|||
|
7ec4c4a526
|
|||
|
526dd4172b
|
|||
|
11278926bf
|
|||
|
d41b499913
|
|||
|
55e5b732f6
|
|||
|
05afe67de7
|
|||
|
a32ef922c7
|
|||
|
11aaa45456
|
|||
|
e8b5167490
|
|||
|
607b78b6b8
|
|||
|
49c352e84c
|
|||
|
a26e3e1ffe
|
|||
|
27ee89dd8a
|
|||
|
45eb023741
|
|||
|
a321aae4d2
|
|||
|
12a91e6103
|
|||
|
8904df2753
|
|||
|
49fefb745c
|
|||
|
38b8fbe37f
|
|||
|
8aba71a72b
|
|||
|
c259d6c102
|
|||
|
2b71b456a3
|
|||
|
04914f33ab
|
|||
|
4fb7c049b5
|
|||
|
00bedd5ce1
|
|||
|
1defe5958f
|
|||
|
e7f03687dc
|
|||
|
f7b23d0943
|
|||
|
12e24652b7
|
|||
|
591154f331
|
|||
|
390a142561
|
|||
|
0f94dae70a
|
|||
|
8e03973dda
|
|||
|
9e06880a81
|
|||
|
9ec922f965
|
|||
|
651c96d658
|
|||
|
88c931bc5c
|
|||
|
c95a566c58
|
|||
|
8803a8500a
|
|||
|
d1b1132cc3
|
|||
|
2e256c32f8
|
|||
|
f73e6ce7f8
|
|||
|
ead7eddf1f
|
|||
|
e44aa7f60c
|
|||
|
137e04eda0
|
|||
|
6e4277a53b
|
|||
|
c173ce8dba
|
|||
|
33cd9b007c
|
|||
|
e6b985a695
|
|||
|
3eefa3cba1
|
|||
|
d514f80f64
|
|||
|
8862192778
|
|||
|
1bc45c72b1
|
|||
|
14d22ef4ef
|
|||
|
3a98d7da3f
|
|||
|
570b578596
|
|||
|
8f6805f3e3
|
|||
|
c8837b21f6
|
|||
|
93a8832b36
|
|||
|
aa50d63aec
|
|||
|
01e8f5a959
|
|||
|
ea815f1c0d
|
|||
|
34c04da05d
|
|||
|
a0359637e2
|
|||
|
2a3d63d1e8
|
|||
|
448f7e42ac
|
|||
|
060c6b2263
|
|||
|
b98542fff3
|
|||
|
1098220058
|
|||
|
78561aec5b
|
|||
|
78db54db6c
|
|||
|
4efe9d4a12
|
|||
|
820417832b
|
|||
|
8979029e29
|
|||
|
3a4d6b2d62
|
|||
|
acb1878e8d
|
|||
|
c18b025ac4
|
|||
|
cb12afd2da
|
|||
|
6873d68129
|
|||
|
a49d639b18
|
|||
|
9ab7685f2d
|
|||
|
e972998e09
|
|||
|
2f4df9395d
|
|||
|
2bb467898e
|
|||
|
fe3f2af4e9
|
|||
|
5337f7f61d
|
|||
|
20cd2d6877
|
|||
|
50a4d71ad8
|
|||
|
dc213c4055
|
|||
|
36e1609002
|
|||
|
338d2720ac
|
|||
|
bce6338c2b
|
|||
|
4c5d44d553
|
|||
|
0b0d4f2f9c
|
|||
|
5d1372905f
|
|||
|
60eb54ca49
|
|||
|
8e29384cb2
|
|||
|
6833f7b86a
|
|||
|
acf61e1520
|
|||
|
3e755b465c
|
|||
|
1eb9b95070
|
|||
|
4b32063d93
|
|||
|
e4af4e6e25
|
|||
|
debc750e2f
|
|||
|
842c5b4579
|
|||
|
b908736c1c
|
|||
|
46b730e235
|
|||
|
c40ac23cf5
|
|||
|
1c9669a4a7
|
|||
|
f0c3aa9df5
|
|||
|
4b4eacf3f4
|
|||
|
7d769d3a0f
|
|||
|
a116b1c2e6
|
|||
|
0415152500
|
|||
|
d90b1e69ea
|
|||
|
ca32d8701c
|
|||
|
b80d8b1859
|
|||
|
05ebf862fd
|
|||
|
1de8f9499a
|
|||
|
9f61cc748a
|
|||
|
30ac42001b
|
115
README.md
115
README.md
@@ -5,41 +5,72 @@ Simple Rust Tests
|
|||||||
Project or files:
|
Project or files:
|
||||||
```
|
```
|
||||||
.
|
.
|
||||||
├── README_2.md
|
├── __alloc
|
||||||
|
│ └── zeroizing-alloc-demo
|
||||||
|
├── __args
|
||||||
|
│ ├── argh-test
|
||||||
|
│ ├── clap-test
|
||||||
|
│ └── clap-test-2
|
||||||
├── __bin
|
├── __bin
|
||||||
│ └── goblin
|
│ ├── goblin
|
||||||
|
│ └── object-demo
|
||||||
|
├── __compress
|
||||||
|
│ └── zstd-demo
|
||||||
├── __concurrent
|
├── __concurrent
|
||||||
│ ├── arc-swap
|
│ ├── arc-swap
|
||||||
│ ├── async_study
|
│ ├── async_study
|
||||||
|
│ ├── async-fn-resumed-after-completion
|
||||||
│ ├── crossbeam_n_parking_lot
|
│ ├── crossbeam_n_parking_lot
|
||||||
│ ├── glommio
|
│ ├── glommio
|
||||||
│ ├── green-threads
|
│ ├── green-threads
|
||||||
│ ├── qcell
|
│ ├── qcell
|
||||||
│ └── rayon
|
│ ├── rayon
|
||||||
|
│ └── waitgroup-demo
|
||||||
├── __cpu
|
├── __cpu
|
||||||
│ └── x86
|
│ └── x86
|
||||||
├── __crypto
|
├── __crypto
|
||||||
|
│ ├── aegis-test
|
||||||
|
│ ├── aes_ctr_test
|
||||||
|
│ ├── aes_gcm_crypto
|
||||||
|
│ ├── asn1-der-test
|
||||||
|
│ ├── bc1-btc-address
|
||||||
│ ├── btc-address
|
│ ├── btc-address
|
||||||
│ ├── crypto
|
│ ├── crypto
|
||||||
|
│ ├── crypto2-demo
|
||||||
│ ├── curve25519
|
│ ├── curve25519
|
||||||
|
│ ├── efficient_sm2
|
||||||
|
│ ├── eth-address
|
||||||
|
│ ├── highwayhash
|
||||||
│ ├── hmac_sha1
|
│ ├── hmac_sha1
|
||||||
|
│ ├── jose-test
|
||||||
│ ├── jsonwebtoken
|
│ ├── jsonwebtoken
|
||||||
|
│ ├── liboqs-rust-demo
|
||||||
|
│ ├── ml-kem-demo
|
||||||
|
│ ├── okta-bcrypt-issue
|
||||||
|
│ ├── orion-demo
|
||||||
|
│ ├── passkey-rs-demo
|
||||||
│ ├── password-hash
|
│ ├── password-hash
|
||||||
│ ├── pkcs8
|
│ ├── pkcs8
|
||||||
│ ├── pwhash
|
│ ├── pwhash
|
||||||
│ ├── random
|
│ ├── random
|
||||||
│ ├── ring
|
│ ├── ring
|
||||||
|
│ ├── rpgp-demo
|
||||||
│ ├── rsa
|
│ ├── rsa
|
||||||
│ ├── secp256k1
|
│ ├── secp256k1
|
||||||
|
│ ├── secretshare
|
||||||
|
│ ├── shamir-demo
|
||||||
│ ├── simple_contract
|
│ ├── simple_contract
|
||||||
│ ├── ssh-keys
|
│ ├── ssh-keys
|
||||||
│ └── totp
|
│ ├── totp
|
||||||
|
│ └── yubikey-rs-demo
|
||||||
├── __database
|
├── __database
|
||||||
│ ├── barrel
|
│ ├── barrel
|
||||||
│ ├── bonsaidb
|
│ ├── bonsaidb
|
||||||
│ ├── diesel
|
│ ├── diesel
|
||||||
|
│ ├── duckdb-demo
|
||||||
│ ├── gluesql
|
│ ├── gluesql
|
||||||
│ ├── mysqlsvr
|
│ ├── mysqlsvr
|
||||||
|
│ ├── native_db-demo
|
||||||
│ ├── persy
|
│ ├── persy
|
||||||
│ ├── rocksdb
|
│ ├── rocksdb
|
||||||
│ ├── rusqlite
|
│ ├── rusqlite
|
||||||
@@ -49,19 +80,22 @@ Project or files:
|
|||||||
│ └── sqlx
|
│ └── sqlx
|
||||||
├── __diff
|
├── __diff
|
||||||
│ ├── diffy
|
│ ├── diffy
|
||||||
│ └── prettydiff
|
│ ├── prettydiff
|
||||||
├── __enclave
|
├── __enclave
|
||||||
│ └── virt_enclave
|
│ └── virt_enclave
|
||||||
├── __err
|
├── __err
|
||||||
│ ├── err_derive
|
│ ├── err_derive
|
||||||
│ ├── quick_error
|
│ ├── quick_error
|
||||||
│ └── thiserror_anyhow
|
│ └── thiserror_anyhow
|
||||||
|
├── __external
|
||||||
|
│ └── vcard-qr
|
||||||
├── __ffi
|
├── __ffi
|
||||||
│ ├── abi_stable_crates
|
│ ├── abi_stable_crates
|
||||||
│ ├── c
|
│ ├── c
|
||||||
│ ├── c2
|
|
||||||
│ ├── c_export
|
│ ├── c_export
|
||||||
│ ├── c_layout
|
│ ├── c_layout
|
||||||
|
│ ├── c2
|
||||||
|
│ ├── calltoc
|
||||||
│ ├── cpp
|
│ ├── cpp
|
||||||
│ ├── dotalib
|
│ ├── dotalib
|
||||||
│ ├── jni
|
│ ├── jni
|
||||||
@@ -69,8 +103,9 @@ Project or files:
|
|||||||
│ ├── robusta_jni
|
│ ├── robusta_jni
|
||||||
│ └── rust_link_a
|
│ └── rust_link_a
|
||||||
├── __fs
|
├── __fs
|
||||||
|
│ ├── crypt4ghfs-rust
|
||||||
│ ├── fuse
|
│ ├── fuse
|
||||||
│ └── fuser
|
│ ├── fuser
|
||||||
├── __gui
|
├── __gui
|
||||||
│ ├── druid
|
│ ├── druid
|
||||||
│ ├── gtk
|
│ ├── gtk
|
||||||
@@ -83,15 +118,20 @@ Project or files:
|
|||||||
├── __image
|
├── __image
|
||||||
│ ├── plotters
|
│ ├── plotters
|
||||||
│ └── svg
|
│ └── svg
|
||||||
|
├── __internal
|
||||||
|
│ └── memory
|
||||||
├── __lang
|
├── __lang
|
||||||
│ ├── boa
|
│ ├── boa
|
||||||
|
│ ├── java
|
||||||
│ ├── monkey-rs
|
│ ├── monkey-rs
|
||||||
│ ├── peg
|
│ ├── peg
|
||||||
│ ├── pest
|
│ ├── pest
|
||||||
│ ├── quickjs
|
│ ├── quickjs
|
||||||
|
│ ├── rusty_jsc
|
||||||
│ └── sana
|
│ └── sana
|
||||||
├── __linux
|
├── __linux
|
||||||
│ ├── ipipe
|
│ ├── ipipe
|
||||||
|
│ ├── nix-demo
|
||||||
│ ├── notify
|
│ ├── notify
|
||||||
│ ├── psutil
|
│ ├── psutil
|
||||||
│ ├── sysinfo
|
│ ├── sysinfo
|
||||||
@@ -104,8 +144,12 @@ Project or files:
|
|||||||
├── __misc
|
├── __misc
|
||||||
│ ├── better_panic
|
│ ├── better_panic
|
||||||
│ ├── bytes
|
│ ├── bytes
|
||||||
|
│ ├── daemonize-demo
|
||||||
|
│ ├── erasure-coding
|
||||||
│ ├── fancy-regex
|
│ ├── fancy-regex
|
||||||
|
│ ├── fastqr
|
||||||
│ ├── human_panic
|
│ ├── human_panic
|
||||||
|
│ ├── icalendar
|
||||||
│ ├── lazy_static
|
│ ├── lazy_static
|
||||||
│ ├── libmacchina
|
│ ├── libmacchina
|
||||||
│ ├── num_cpus
|
│ ├── num_cpus
|
||||||
@@ -118,19 +162,31 @@ Project or files:
|
|||||||
│ └── walkdir
|
│ └── walkdir
|
||||||
├── __network
|
├── __network
|
||||||
│ ├── async-speed-limit
|
│ ├── async-speed-limit
|
||||||
|
│ ├── axum-demo
|
||||||
│ ├── dingo
|
│ ├── dingo
|
||||||
|
│ ├── dns-server-tutorial
|
||||||
|
│ ├── fetch-rs
|
||||||
|
│ ├── fuso-socks5-test
|
||||||
|
│ ├── html-crawl-parse
|
||||||
│ ├── ip
|
│ ├── ip
|
||||||
|
│ ├── ipnet-demo
|
||||||
│ ├── iptables
|
│ ├── iptables
|
||||||
|
│ ├── kcp-test
|
||||||
│ ├── mailsend
|
│ ├── mailsend
|
||||||
│ ├── message_io
|
│ ├── message_io
|
||||||
│ ├── n_pcap
|
│ ├── n_pcap
|
||||||
│ ├── nfqueue
|
│ ├── nfqueue
|
||||||
|
│ ├── ngrok-demo
|
||||||
│ ├── pcap
|
│ ├── pcap
|
||||||
|
│ ├── pingora-demo
|
||||||
│ ├── quinn
|
│ ├── quinn
|
||||||
│ ├── rust_tcp
|
│ ├── rust_tcp
|
||||||
|
│ ├── rust-rawsock-demo
|
||||||
│ ├── s2n_quic
|
│ ├── s2n_quic
|
||||||
│ ├── socket2
|
│ ├── socket2
|
||||||
│ ├── tcp
|
│ ├── tcp
|
||||||
|
│ ├── tcp-connect-reset
|
||||||
|
│ ├── tokio-kcp-demo
|
||||||
│ ├── tuntapmac
|
│ ├── tuntapmac
|
||||||
│ ├── udp_laminar
|
│ ├── udp_laminar
|
||||||
│ └── ureq
|
│ └── ureq
|
||||||
@@ -138,16 +194,27 @@ Project or files:
|
|||||||
│ └── print_perf
|
│ └── print_perf
|
||||||
├── __regex
|
├── __regex
|
||||||
│ └── hyperscan
|
│ └── hyperscan
|
||||||
|
├── __rpc
|
||||||
|
│ └── dubbo-rust
|
||||||
├── __rule
|
├── __rule
|
||||||
│ └── json-rules-engine
|
│ └── json-rules-engine
|
||||||
├── __search
|
├── __search
|
||||||
│ ├── simsearch
|
│ ├── simsearch
|
||||||
│ └── tantivy
|
│ └── tantivy
|
||||||
|
├── __security
|
||||||
|
│ ├── keychain-services
|
||||||
|
│ ├── keyring-demo
|
||||||
|
│ ├── seckey
|
||||||
|
│ ├── secmem-proc
|
||||||
|
│ ├── secrets
|
||||||
|
│ ├── security-framework
|
||||||
|
│ └── sensitive
|
||||||
├── __serialization
|
├── __serialization
|
||||||
│ ├── bytes
|
│ ├── bytes
|
||||||
│ ├── cbor
|
│ ├── cbor
|
||||||
│ ├── configrs
|
│ ├── configrs
|
||||||
│ ├── csv
|
│ ├── csv
|
||||||
|
│ ├── der_parser_test
|
||||||
│ ├── encoding
|
│ ├── encoding
|
||||||
│ ├── flatbuffers
|
│ ├── flatbuffers
|
||||||
│ ├── gob
|
│ ├── gob
|
||||||
@@ -157,28 +224,39 @@ Project or files:
|
|||||||
│ └── serde_json
|
│ └── serde_json
|
||||||
├── __shell
|
├── __shell
|
||||||
│ ├── ssh2
|
│ ├── ssh2
|
||||||
|
│ ├── sshrs
|
||||||
│ └── xshell
|
│ └── xshell
|
||||||
|
├── __shuttle
|
||||||
|
│ ├── hatter-test
|
||||||
├── __std
|
├── __std
|
||||||
│ ├── async_await
|
│ ├── async_await
|
||||||
|
│ ├── async-fn
|
||||||
│ ├── into
|
│ ├── into
|
||||||
│ ├── iter
|
│ ├── iter
|
||||||
|
│ ├── misc
|
||||||
│ ├── ops
|
│ ├── ops
|
||||||
│ └── thread
|
│ ├── pi
|
||||||
|
│ ├── thread
|
||||||
|
│ └── tokio-cpu-affinity
|
||||||
├── __template
|
├── __template
|
||||||
│ ├── askama
|
│ ├── askama
|
||||||
│ └── handlebars-rust
|
│ └── handlebars-rust
|
||||||
├── __term
|
├── __term
|
||||||
│ ├── bunt
|
│ ├── bunt
|
||||||
│ ├── colored_msg
|
│ ├── colored_msg
|
||||||
│ ├── confy_table
|
│ ├── comfy_table
|
||||||
|
│ ├── cursive-demo
|
||||||
|
│ ├── dialoguer-demo
|
||||||
│ ├── indicatif
|
│ ├── indicatif
|
||||||
│ ├── prettyprint
|
│ ├── prettyprint
|
||||||
│ ├── rustyline
|
│ ├── rustyline
|
||||||
│ ├── structopt
|
│ ├── structopt
|
||||||
│ ├── tabled
|
│ ├── tabled
|
||||||
│ └── term
|
│ ├── term
|
||||||
|
│ └── tui-markup-demo
|
||||||
├── __time
|
├── __time
|
||||||
│ ├── chrono
|
│ ├── chrono
|
||||||
|
│ ├── humantime-demo
|
||||||
│ └── iron
|
│ └── iron
|
||||||
├── __translate
|
├── __translate
|
||||||
│ └── retranslate
|
│ └── retranslate
|
||||||
@@ -186,12 +264,17 @@ Project or files:
|
|||||||
│ ├── deno_rust_wasm_import_functions
|
│ ├── deno_rust_wasm_import_functions
|
||||||
│ ├── deno_rust_wasm_js_sandbox
|
│ ├── deno_rust_wasm_js_sandbox
|
||||||
│ ├── deno_rust_wasm_qr_decode
|
│ ├── deno_rust_wasm_qr_decode
|
||||||
|
│ ├── extism
|
||||||
|
│ ├── js-wasm
|
||||||
|
│ ├── rust-wasm-plugins-examples
|
||||||
│ ├── wasi
|
│ ├── wasi
|
||||||
│ ├── wasm
|
│ ├── wasm
|
||||||
│ └── wasmtime
|
│ ├── wasmtime
|
||||||
|
│ ├── wasmtime-serde-demo
|
||||||
|
│ └── wit-bindgen-sample
|
||||||
├── __web
|
├── __web
|
||||||
│ ├── actix-web
|
|
||||||
│ ├── actix_rustls
|
│ ├── actix_rustls
|
||||||
|
│ ├── actix-web
|
||||||
│ ├── alibabacloundfn
|
│ ├── alibabacloundfn
|
||||||
│ ├── hyper_rustls
|
│ ├── hyper_rustls
|
||||||
│ ├── hyperrs
|
│ ├── hyperrs
|
||||||
@@ -204,10 +287,11 @@ Project or files:
|
|||||||
│ ├── sincere
|
│ ├── sincere
|
||||||
│ ├── tide
|
│ ├── tide
|
||||||
│ └── warp
|
│ └── warp
|
||||||
|
├── build_readme.rs -> scripts/build_readme_rs/src/main.rs
|
||||||
|
├── README_2.md
|
||||||
├── scripts
|
├── scripts
|
||||||
│ └── commit-msg.crs
|
│ ├── build_readme_rs
|
||||||
└── single_file_tests
|
└── single_file_tests
|
||||||
├── 99.htm
|
|
||||||
├── 99.rs
|
├── 99.rs
|
||||||
├── chain.rs
|
├── chain.rs
|
||||||
├── closure.rs
|
├── closure.rs
|
||||||
@@ -230,7 +314,6 @@ Project or files:
|
|||||||
├── vec.rs
|
├── vec.rs
|
||||||
└── while.rs
|
└── while.rs
|
||||||
|
|
||||||
200 directories, 33 files
|
286 directories, 38 files
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -7,5 +7,3 @@ Projects:
|
|||||||
* https://github.com/tafia/hyper-proxy
|
* https://github.com/tafia/hyper-proxy
|
||||||
* https://github.com/rusticata/x509-parser
|
* https://github.com/rusticata/x509-parser
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
16
__alloc/zeroizing-alloc-demo/Cargo.lock
generated
Normal file
16
__alloc/zeroizing-alloc-demo/Cargo.lock
generated
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zeroizing-alloc"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ebff5e6b81c1c7dca2d0bd333b2006da48cb37dbcae5a8da888f31fcb3c19934"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zeroizing-alloc-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"zeroizing-alloc",
|
||||||
|
]
|
||||||
7
__alloc/zeroizing-alloc-demo/Cargo.toml
Normal file
7
__alloc/zeroizing-alloc-demo/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "zeroizing-alloc-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
zeroizing-alloc = "0.1.0"
|
||||||
8
__alloc/zeroizing-alloc-demo/src/main.rs
Normal file
8
__alloc/zeroizing-alloc-demo/src/main.rs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
use zeroizing_alloc::ZeroAlloc;
|
||||||
|
|
||||||
|
#[global_allocator]
|
||||||
|
static ALLOC: ZeroAlloc<std::alloc::System> = ZeroAlloc(std::alloc::System);
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
||||||
103
__args/argh-test/Cargo.lock
generated
Normal file
103
__args/argh-test/Cargo.lock
generated
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "argh"
|
||||||
|
version = "0.1.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34ff18325c8a36b82f992e533ece1ec9f9a9db446bd1c14d4f936bac88fcd240"
|
||||||
|
dependencies = [
|
||||||
|
"argh_derive",
|
||||||
|
"argh_shared",
|
||||||
|
"rust-fuzzy-search",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "argh-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"argh",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "argh_derive"
|
||||||
|
version = "0.1.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "adb7b2b83a50d329d5d8ccc620f5c7064028828538bdf5646acd60dc1f767803"
|
||||||
|
dependencies = [
|
||||||
|
"argh_shared",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "argh_shared"
|
||||||
|
version = "0.1.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a464143cc82dedcdc3928737445362466b7674b5db4e2eb8e869846d6d84f4f6"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.92"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.38"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rust-fuzzy-search"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a157657054ffe556d8858504af8a672a054a6e0bd9e8ee531059100c0fa11bb2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.217"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.217"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.93"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c786062daee0d6db1132800e623df74274a0a87322d8e183338e01b3d98d058"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||||
7
__args/argh-test/Cargo.toml
Normal file
7
__args/argh-test/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "argh-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
argh = "0.1.13"
|
||||||
22
__args/argh-test/src/main.rs
Normal file
22
__args/argh-test/src/main.rs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
use argh::FromArgs;
|
||||||
|
|
||||||
|
#[derive(Debug, FromArgs)]
|
||||||
|
/// Reach new heights.
|
||||||
|
struct GoUp {
|
||||||
|
/// whether or not to jump
|
||||||
|
#[argh(switch, short = 'j')]
|
||||||
|
jump: bool,
|
||||||
|
|
||||||
|
/// how high to go
|
||||||
|
#[argh(option)]
|
||||||
|
height: usize,
|
||||||
|
|
||||||
|
/// an optional nickname for the pilot
|
||||||
|
#[argh(option)]
|
||||||
|
pilot_nickname: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let up: GoUp = argh::from_env();
|
||||||
|
println!("{:#?}", up);
|
||||||
|
}
|
||||||
261
__args/clap-test-2/Cargo.lock
generated
Normal file
261
__args/clap-test-2/Cargo.lock
generated
Normal file
@@ -0,0 +1,261 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstream"
|
||||||
|
version = "0.6.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"anstyle-parse",
|
||||||
|
"anstyle-query",
|
||||||
|
"anstyle-wincon",
|
||||||
|
"colorchoice",
|
||||||
|
"is_terminal_polyfill",
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle"
|
||||||
|
version = "1.0.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-parse"
|
||||||
|
version = "0.2.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
|
||||||
|
dependencies = [
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-query"
|
||||||
|
version = "1.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-wincon"
|
||||||
|
version = "3.0.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"once_cell_polyfill",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "4.5.42"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed87a9d530bb41a67537289bafcac159cb3ee28460e0a4571123d2a778a6a882"
|
||||||
|
dependencies = [
|
||||||
|
"clap_builder",
|
||||||
|
"clap_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap-test-2"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
"clap-verbosity-flag",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap-verbosity-flag"
|
||||||
|
version = "3.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eeab6a5cdfc795a05538422012f20a5496f050223c91be4e5420bfd13c641fb1"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_builder"
|
||||||
|
version = "4.5.42"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "64f4f3f3c77c94aff3c7e9aac9a2ca1974a5adf392a8bb751e827d6d127ab966"
|
||||||
|
dependencies = [
|
||||||
|
"anstream",
|
||||||
|
"anstyle",
|
||||||
|
"clap_lex",
|
||||||
|
"strsim",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_derive"
|
||||||
|
version = "4.5.41"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491"
|
||||||
|
dependencies = [
|
||||||
|
"heck",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_lex"
|
||||||
|
version = "0.7.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorchoice"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "is_terminal_polyfill"
|
||||||
|
version = "1.70.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell_polyfill"
|
||||||
|
version = "1.70.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.95"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.104"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8parse"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.59.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm",
|
||||||
|
"windows_aarch64_msvc",
|
||||||
|
"windows_i686_gnu",
|
||||||
|
"windows_i686_gnullvm",
|
||||||
|
"windows_i686_msvc",
|
||||||
|
"windows_x86_64_gnu",
|
||||||
|
"windows_x86_64_gnullvm",
|
||||||
|
"windows_x86_64_msvc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnullvm"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||||
8
__args/clap-test-2/Cargo.toml
Normal file
8
__args/clap-test-2/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "clap-test-2"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
clap = { version = "4.5.42", features = ["derive", "env"] }
|
||||||
|
clap-verbosity-flag = "3"
|
||||||
158
__args/clap-test-2/src/main.rs
Normal file
158
__args/clap-test-2/src/main.rs
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
// https://github.com/fastn-stack/kulfi/blob/main/malai/src/main.rs
|
||||||
|
fn main() {
|
||||||
|
let cli = Cli::parse();
|
||||||
|
println!("{:?}", cli);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(clap::Parser, Debug)]
|
||||||
|
#[command(version, about, long_about = None)]
|
||||||
|
pub struct Cli {
|
||||||
|
#[command(flatten)]
|
||||||
|
verbose: clap_verbosity_flag::Verbosity,
|
||||||
|
|
||||||
|
#[command(subcommand)]
|
||||||
|
pub command: Option<Command>,
|
||||||
|
|
||||||
|
// adding these two because when we run `cargo tauri dev,` it automatically passes these
|
||||||
|
// arguments. need to figure out why and how to disable that, till then this is a workaround
|
||||||
|
#[arg(default_value = "true", long, hide = true)]
|
||||||
|
no_default_features: bool,
|
||||||
|
#[arg(default_value = "auto", long, hide = true)]
|
||||||
|
color: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(clap::Subcommand, Debug)]
|
||||||
|
pub enum Command {
|
||||||
|
// TODO: add this to the docs when we have ACL
|
||||||
|
// By default it allows any peer to connect to the HTTP(s) service. You can pass --what-to-do
|
||||||
|
// argument to specify a What To Do service that can be used to add access control."
|
||||||
|
#[clap(about = "Expose HTTP Service on kulfi, connect using kulfi or browser")]
|
||||||
|
Http {
|
||||||
|
port: u16,
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
default_value = "127.0.0.1",
|
||||||
|
help = "Host serving the http service."
|
||||||
|
)]
|
||||||
|
host: String,
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
default_value = "kulfi.site",
|
||||||
|
help = "Use this for the HTTP bridge. To run an HTTP bridge, use `malai http-bridge`",
|
||||||
|
env = "MALAI_HTTP_BRIDGE"
|
||||||
|
)]
|
||||||
|
bridge: String,
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
help = "Make the exposed service public. Anyone will be able to access."
|
||||||
|
)]
|
||||||
|
public: bool,
|
||||||
|
// #[arg(
|
||||||
|
// long,
|
||||||
|
// default_value_t = false,
|
||||||
|
// help = "Use this if the service is HTTPS"
|
||||||
|
// )]
|
||||||
|
// secure: bool,
|
||||||
|
// #[arg(
|
||||||
|
// long,
|
||||||
|
// help = "The What To Do Service that can be used to add access control."
|
||||||
|
// )]
|
||||||
|
// this will be the id52 of the identity server that should be consulted
|
||||||
|
// what_to_do: Option<String>,
|
||||||
|
},
|
||||||
|
#[clap(about = "Browse a kulfi site.")]
|
||||||
|
Browse {
|
||||||
|
#[arg(help = "The Kulfi URL to browse. Should look like kulfi://<id52>/<path>")]
|
||||||
|
url: String,
|
||||||
|
},
|
||||||
|
#[clap(about = "Expose TCP Service on kulfi.")]
|
||||||
|
Tcp {
|
||||||
|
port: u16,
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
default_value = "127.0.0.1",
|
||||||
|
help = "Host serving the TCP service."
|
||||||
|
)]
|
||||||
|
host: String,
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
help = "Make the exposed service public. Anyone will be able to access."
|
||||||
|
)]
|
||||||
|
public: bool,
|
||||||
|
},
|
||||||
|
#[clap(
|
||||||
|
about = "Run an http server that forwards requests to the given id52 taken from the HOST header"
|
||||||
|
)]
|
||||||
|
HttpBridge {
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
short('t'),
|
||||||
|
help = "The id52 to which this bridge will forward incoming HTTP request. By default it forwards to every id52."
|
||||||
|
)]
|
||||||
|
proxy_target: Option<String>,
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
short('p'),
|
||||||
|
help = "The port on which this bridge will listen for incoming HTTP requests. If you pass 0, it will bind to a random port.",
|
||||||
|
default_value = "0"
|
||||||
|
)]
|
||||||
|
port: u16,
|
||||||
|
},
|
||||||
|
#[clap(about = "Run a TCP server that forwards incoming requests to the given id52.")]
|
||||||
|
TcpBridge {
|
||||||
|
#[arg(help = "The id52 to which this bridge will forward incoming TCP request.")]
|
||||||
|
proxy_target: String,
|
||||||
|
#[arg(
|
||||||
|
help = "The port on which this bridge will listen for incoming TCP requests. If you pass 0, it will bind to a random port.",
|
||||||
|
default_value = "0"
|
||||||
|
)]
|
||||||
|
port: u16,
|
||||||
|
},
|
||||||
|
#[clap(about = "Expose a folder to kulfi network")]
|
||||||
|
Folder {
|
||||||
|
#[arg(help = "The folder to expose.")]
|
||||||
|
path: String,
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
default_value = "kulfi.site",
|
||||||
|
help = "Use this for the HTTP bridge. To run an HTTP bridge, use `malai http-bridge`",
|
||||||
|
env = "MALAI_HTTP_BRIDGE"
|
||||||
|
)]
|
||||||
|
bridge: String,
|
||||||
|
#[arg(long, help = "Make the folder public. Anyone will be able to access.")]
|
||||||
|
public: bool,
|
||||||
|
},
|
||||||
|
#[clap(about = "Run all the services")]
|
||||||
|
Run {
|
||||||
|
#[arg(long, help = "Malai Home", env = "MALAI_HOME")]
|
||||||
|
home: Option<String>,
|
||||||
|
},
|
||||||
|
#[clap(about = "Run an iroh remote server that handles requests from http-proxy.")]
|
||||||
|
HttpProxyRemote {
|
||||||
|
#[arg(long, help = "Make the proxy public. Anyone will be able to access.")]
|
||||||
|
public: bool,
|
||||||
|
},
|
||||||
|
#[clap(about = "Run a http proxy server that forwards incoming requests to http-proxy-remote.")]
|
||||||
|
HttpProxy {
|
||||||
|
#[arg(help = "The id52 of remote to which this http proxy will forward request to.")]
|
||||||
|
remote: String,
|
||||||
|
#[arg(
|
||||||
|
help = "The port on which this proxy will listen for incoming TCP requests. If you pass 0, it will bind to a random port.",
|
||||||
|
default_value = "0"
|
||||||
|
)]
|
||||||
|
port: u16,
|
||||||
|
},
|
||||||
|
#[clap(about = "Generate a new identity.")]
|
||||||
|
Keygen {
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
short,
|
||||||
|
num_args=0..=1,
|
||||||
|
//default_missing_value=kulfi_utils::SECRET_KEY_FILE,
|
||||||
|
help = "The file where the private key of the identity will be stored. If not provided, the private key will be printed to stdout."
|
||||||
|
)]
|
||||||
|
file: Option<String>,
|
||||||
|
},
|
||||||
|
}
|
||||||
237
__args/clap-test/Cargo.lock
generated
Normal file
237
__args/clap-test/Cargo.lock
generated
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstream"
|
||||||
|
version = "0.6.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"anstyle-parse",
|
||||||
|
"anstyle-query",
|
||||||
|
"anstyle-wincon",
|
||||||
|
"colorchoice",
|
||||||
|
"is_terminal_polyfill",
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle"
|
||||||
|
version = "1.0.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-parse"
|
||||||
|
version = "0.2.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
|
||||||
|
dependencies = [
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-query"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-wincon"
|
||||||
|
version = "3.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "4.5.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84"
|
||||||
|
dependencies = [
|
||||||
|
"clap_builder",
|
||||||
|
"clap_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_builder"
|
||||||
|
version = "4.5.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838"
|
||||||
|
dependencies = [
|
||||||
|
"anstream",
|
||||||
|
"anstyle",
|
||||||
|
"clap_lex",
|
||||||
|
"strsim",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_derive"
|
||||||
|
version = "4.5.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab"
|
||||||
|
dependencies = [
|
||||||
|
"heck",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_lex"
|
||||||
|
version = "0.7.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorchoice"
|
||||||
|
version = "1.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "is_terminal_polyfill"
|
||||||
|
version = "1.70.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.92"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.38"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.93"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c786062daee0d6db1132800e623df74274a0a87322d8e183338e01b3d98d058"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8parse"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.59.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm",
|
||||||
|
"windows_aarch64_msvc",
|
||||||
|
"windows_i686_gnu",
|
||||||
|
"windows_i686_gnullvm",
|
||||||
|
"windows_i686_msvc",
|
||||||
|
"windows_x86_64_gnu",
|
||||||
|
"windows_x86_64_gnullvm",
|
||||||
|
"windows_x86_64_msvc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnullvm"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.52.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||||
7
__args/clap-test/Cargo.toml
Normal file
7
__args/clap-test/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "clap-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
clap = { version = "4.5.23", features = ["derive"] }
|
||||||
165
__args/clap-test/src/main.rs
Normal file
165
__args/clap-test/src/main.rs
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
use std::ffi::OsStr;
|
||||||
|
use std::ffi::OsString;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use clap::{Args, Parser, Subcommand, ValueEnum};
|
||||||
|
|
||||||
|
/// A fictional versioning CLI
|
||||||
|
#[derive(Debug, Parser)] // requires `derive` feature
|
||||||
|
#[command(name = "git")]
|
||||||
|
#[command(about = "A fictional versioning CLI", long_about = None)]
|
||||||
|
struct Cli {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: Commands,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Subcommand)]
|
||||||
|
enum Commands {
|
||||||
|
/// Clones repos
|
||||||
|
#[command(arg_required_else_help = true)]
|
||||||
|
Clone {
|
||||||
|
/// The remote to clone
|
||||||
|
remote: String,
|
||||||
|
},
|
||||||
|
/// Compare two commits
|
||||||
|
Diff {
|
||||||
|
#[arg(value_name = "COMMIT")]
|
||||||
|
base: Option<OsString>,
|
||||||
|
#[arg(value_name = "COMMIT")]
|
||||||
|
head: Option<OsString>,
|
||||||
|
#[arg(last = true)]
|
||||||
|
path: Option<OsString>,
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
require_equals = true,
|
||||||
|
value_name = "WHEN",
|
||||||
|
num_args = 0..=1,
|
||||||
|
default_value_t = ColorWhen::Auto,
|
||||||
|
default_missing_value = "always",
|
||||||
|
value_enum
|
||||||
|
)]
|
||||||
|
color: ColorWhen,
|
||||||
|
},
|
||||||
|
/// pushes things
|
||||||
|
#[command(arg_required_else_help = true)]
|
||||||
|
Push {
|
||||||
|
/// The remote to target
|
||||||
|
remote: String,
|
||||||
|
},
|
||||||
|
/// adds things
|
||||||
|
#[command(arg_required_else_help = true)]
|
||||||
|
Add {
|
||||||
|
/// Stuff to add
|
||||||
|
#[arg(required = true)]
|
||||||
|
path: Vec<PathBuf>,
|
||||||
|
},
|
||||||
|
Stash(StashArgs),
|
||||||
|
#[command(external_subcommand)]
|
||||||
|
External(Vec<OsString>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(ValueEnum, Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
|
enum ColorWhen {
|
||||||
|
Always,
|
||||||
|
Auto,
|
||||||
|
Never,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for ColorWhen {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
self.to_possible_value()
|
||||||
|
.expect("no values are skipped")
|
||||||
|
.get_name()
|
||||||
|
.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Args)]
|
||||||
|
#[command(args_conflicts_with_subcommands = true)]
|
||||||
|
#[command(flatten_help = true)]
|
||||||
|
struct StashArgs {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: Option<StashCommands>,
|
||||||
|
|
||||||
|
#[command(flatten)]
|
||||||
|
push: StashPushArgs,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Subcommand)]
|
||||||
|
enum StashCommands {
|
||||||
|
Push(StashPushArgs),
|
||||||
|
Pop { stash: Option<String> },
|
||||||
|
Apply { stash: Option<String> },
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Args)]
|
||||||
|
struct StashPushArgs {
|
||||||
|
#[arg(short, long)]
|
||||||
|
message: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args = Cli::parse();
|
||||||
|
|
||||||
|
match args.command {
|
||||||
|
Commands::Clone { remote } => {
|
||||||
|
println!("Cloning {remote}");
|
||||||
|
}
|
||||||
|
Commands::Diff {
|
||||||
|
mut base,
|
||||||
|
mut head,
|
||||||
|
mut path,
|
||||||
|
color,
|
||||||
|
} => {
|
||||||
|
if path.is_none() {
|
||||||
|
path = head;
|
||||||
|
head = None;
|
||||||
|
if path.is_none() {
|
||||||
|
path = base;
|
||||||
|
base = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let base = base
|
||||||
|
.as_deref()
|
||||||
|
.map(|s| s.to_str().unwrap())
|
||||||
|
.unwrap_or("stage");
|
||||||
|
let head = head
|
||||||
|
.as_deref()
|
||||||
|
.map(|s| s.to_str().unwrap())
|
||||||
|
.unwrap_or("worktree");
|
||||||
|
let path = path.as_deref().unwrap_or_else(|| OsStr::new(""));
|
||||||
|
println!(
|
||||||
|
"Diffing {}..{} {} (color={})",
|
||||||
|
base,
|
||||||
|
head,
|
||||||
|
path.to_string_lossy(),
|
||||||
|
color
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Commands::Push { remote } => {
|
||||||
|
println!("Pushing to {remote}");
|
||||||
|
}
|
||||||
|
Commands::Add { path } => {
|
||||||
|
println!("Adding {path:?}");
|
||||||
|
}
|
||||||
|
Commands::Stash(stash) => {
|
||||||
|
let stash_cmd = stash.command.unwrap_or(StashCommands::Push(stash.push));
|
||||||
|
match stash_cmd {
|
||||||
|
StashCommands::Push(push) => {
|
||||||
|
println!("Pushing {push:?}");
|
||||||
|
}
|
||||||
|
StashCommands::Pop { stash } => {
|
||||||
|
println!("Popping {stash:?}");
|
||||||
|
}
|
||||||
|
StashCommands::Apply { stash } => {
|
||||||
|
println!("Applying {stash:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Commands::External(args) => {
|
||||||
|
println!("Calling out to {:?} with {:?}", &args[0], &args[1..]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Continued program logic goes here...
|
||||||
|
}
|
||||||
82
__bin/object-demo/Cargo.lock
generated
Normal file
82
__bin/object-demo/Cargo.lock
generated
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "adler"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crc32fast"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "flate2"
|
||||||
|
version = "1.0.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841"
|
||||||
|
dependencies = [
|
||||||
|
"crc32fast",
|
||||||
|
"miniz_oxide",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.140"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memmap2"
|
||||||
|
version = "0.5.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "miniz_oxide"
|
||||||
|
version = "0.6.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa"
|
||||||
|
dependencies = [
|
||||||
|
"adler",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "object"
|
||||||
|
version = "0.30.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439"
|
||||||
|
dependencies = [
|
||||||
|
"flate2",
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "object-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"memmap2",
|
||||||
|
"object",
|
||||||
|
]
|
||||||
10
__bin/object-demo/Cargo.toml
Normal file
10
__bin/object-demo/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "object-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
memmap2 = "0.5.10"
|
||||||
|
object = "0.30.3"
|
||||||
323
__bin/object-demo/src/main.rs
Normal file
323
__bin/object-demo/src/main.rs
Normal file
@@ -0,0 +1,323 @@
|
|||||||
|
use std::io::{Result, Write};
|
||||||
|
|
||||||
|
use object::{Endianness, Object, ObjectComdat, ObjectSection, ObjectSymbol};
|
||||||
|
use object::read::archive::ArchiveFile;
|
||||||
|
use object::read::macho::{DyldCache, FatArch, FatHeader};
|
||||||
|
|
||||||
|
use std::{env, fs, io, process};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut args = env::args();
|
||||||
|
let cmd = args.next().unwrap();
|
||||||
|
if args.len() == 0 {
|
||||||
|
eprintln!("Usage: {} <file> [<member>...]", cmd);
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
let file_path = args.next().unwrap();
|
||||||
|
let member_names: Vec<_> = args.collect();
|
||||||
|
|
||||||
|
let file = match fs::File::open(&file_path) {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Failed to open file '{}': {}", file_path, err,);
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let extra_files = open_subcaches_if_exist(&file_path);
|
||||||
|
let file = match unsafe { memmap2::Mmap::map(&file) } {
|
||||||
|
Ok(mmap) => mmap,
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Failed to map file '{}': {}", file_path, err,);
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let extra_files: Vec<_> = extra_files
|
||||||
|
.into_iter()
|
||||||
|
.map(
|
||||||
|
|subcache_file| match unsafe { memmap2::Mmap::map(&subcache_file) } {
|
||||||
|
Ok(mmap) => mmap,
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Failed to map file '{}': {}", file_path, err,);
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.collect();
|
||||||
|
let extra_file_data: Vec<&[u8]> = extra_files.iter().map(|f| &**f).collect();
|
||||||
|
|
||||||
|
let stdout = io::stdout();
|
||||||
|
let stderr = io::stderr();
|
||||||
|
print(
|
||||||
|
&mut stdout.lock(),
|
||||||
|
&mut stderr.lock(),
|
||||||
|
&*file,
|
||||||
|
&extra_file_data,
|
||||||
|
member_names,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the file is a dyld shared cache, and we're on macOS 12 or later,
|
||||||
|
// then there will be one or more "subcache" files next to this file,
|
||||||
|
// with the names filename.1, filename.2 etc.
|
||||||
|
// Read those files now, if they exist, even if we don't know that
|
||||||
|
// we're dealing with a dyld shared cache. By the time we know what
|
||||||
|
// we're dealing with, it's too late to read more files.
|
||||||
|
fn open_subcaches_if_exist(path: &str) -> Vec<fs::File> {
|
||||||
|
let mut files = Vec::new();
|
||||||
|
for i in 1.. {
|
||||||
|
let subcache_path = format!("{}.{}", path, i);
|
||||||
|
match fs::File::open(&subcache_path) {
|
||||||
|
Ok(subcache_file) => files.push(subcache_file),
|
||||||
|
Err(_) => break,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let symbols_subcache_path = format!("{}.symbols", path);
|
||||||
|
if let Ok(subcache_file) = fs::File::open(&symbols_subcache_path) {
|
||||||
|
files.push(subcache_file);
|
||||||
|
};
|
||||||
|
files
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print<W: Write, E: Write>(
|
||||||
|
w: &mut W,
|
||||||
|
e: &mut E,
|
||||||
|
file: &[u8],
|
||||||
|
extra_files: &[&[u8]],
|
||||||
|
member_names: Vec<String>,
|
||||||
|
) -> Result<()> {
|
||||||
|
let mut member_names: Vec<_> = member_names.into_iter().map(|name| (name, false)).collect();
|
||||||
|
|
||||||
|
if let Ok(archive) = ArchiveFile::parse(file) {
|
||||||
|
writeln!(w, "Format: Archive (kind: {:?})", archive.kind())?;
|
||||||
|
for member in archive.members() {
|
||||||
|
match member {
|
||||||
|
Ok(member) => {
|
||||||
|
if find_member(&mut member_names, member.name()) {
|
||||||
|
writeln!(w)?;
|
||||||
|
writeln!(w, "{}:", String::from_utf8_lossy(member.name()))?;
|
||||||
|
if let Ok(data) = member.data(file) {
|
||||||
|
dump_object(w, e, data)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => writeln!(e, "Failed to parse archive member: {}", err)?,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if let Ok(arches) = FatHeader::parse_arch32(file) {
|
||||||
|
writeln!(w, "Format: Mach-O Fat 32")?;
|
||||||
|
for arch in arches {
|
||||||
|
writeln!(w)?;
|
||||||
|
writeln!(w, "Fat Arch: {:?}", arch.architecture())?;
|
||||||
|
match arch.data(file) {
|
||||||
|
Ok(data) => dump_object(w, e, data)?,
|
||||||
|
Err(err) => writeln!(e, "Failed to parse Fat 32 data: {}", err)?,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if let Ok(arches) = FatHeader::parse_arch64(file) {
|
||||||
|
writeln!(w, "Format: Mach-O Fat 64")?;
|
||||||
|
for arch in arches {
|
||||||
|
writeln!(w)?;
|
||||||
|
writeln!(w, "Fat Arch: {:?}", arch.architecture())?;
|
||||||
|
match arch.data(file) {
|
||||||
|
Ok(data) => dump_object(w, e, data)?,
|
||||||
|
Err(err) => writeln!(e, "Failed to parse Fat 64 data: {}", err)?,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if let Ok(cache) = DyldCache::<Endianness>::parse(file, extra_files) {
|
||||||
|
writeln!(w, "Format: dyld cache {:?}-endian", cache.endianness())?;
|
||||||
|
writeln!(w, "Architecture: {:?}", cache.architecture())?;
|
||||||
|
for image in cache.images() {
|
||||||
|
let path = match image.path() {
|
||||||
|
Ok(path) => path,
|
||||||
|
Err(err) => {
|
||||||
|
writeln!(e, "Failed to parse dydld image name: {}", err)?;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if !find_member(&mut member_names, path.as_bytes()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
writeln!(w)?;
|
||||||
|
writeln!(w, "{}:", path)?;
|
||||||
|
let file = match image.parse_object() {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(err) => {
|
||||||
|
writeln!(e, "Failed to parse file: {}", err)?;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
dump_parsed_object(w, e, &file)?;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dump_object(w, e, file)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (name, found) in member_names {
|
||||||
|
if !found {
|
||||||
|
writeln!(e, "Failed to find member '{}", name)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_member(member_names: &mut [(String, bool)], name: &[u8]) -> bool {
|
||||||
|
if member_names.is_empty() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
match member_names.iter().position(|x| x.0.as_bytes() == name) {
|
||||||
|
Some(i) => {
|
||||||
|
member_names[i].1 = true;
|
||||||
|
true
|
||||||
|
}
|
||||||
|
None => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dump_object<W: Write, E: Write>(w: &mut W, e: &mut E, data: &[u8]) -> Result<()> {
|
||||||
|
match object::File::parse(data) {
|
||||||
|
Ok(file) => {
|
||||||
|
dump_parsed_object(w, e, &file)?;
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
writeln!(e, "Failed to parse file: {}", err)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dump_parsed_object<W: Write, E: Write>(w: &mut W, e: &mut E, file: &object::File) -> Result<()> {
|
||||||
|
writeln!(
|
||||||
|
w,
|
||||||
|
"Format: {:?} {:?}-endian {}-bit",
|
||||||
|
file.format(),
|
||||||
|
file.endianness(),
|
||||||
|
if file.is_64() { "64" } else { "32" }
|
||||||
|
)?;
|
||||||
|
writeln!(w, "Kind: {:?}", file.kind())?;
|
||||||
|
writeln!(w, "Architecture: {:?}", file.architecture())?;
|
||||||
|
writeln!(w, "Flags: {:x?}", file.flags())?;
|
||||||
|
writeln!(
|
||||||
|
w,
|
||||||
|
"Relative Address Base: {:x?}",
|
||||||
|
file.relative_address_base()
|
||||||
|
)?;
|
||||||
|
writeln!(w, "Entry Address: {:x?}", file.entry())?;
|
||||||
|
|
||||||
|
match file.mach_uuid() {
|
||||||
|
Ok(Some(uuid)) => writeln!(w, "Mach UUID: {:x?}", uuid)?,
|
||||||
|
Ok(None) => {}
|
||||||
|
Err(err) => writeln!(e, "Failed to parse Mach UUID: {}", err)?,
|
||||||
|
}
|
||||||
|
match file.build_id() {
|
||||||
|
Ok(Some(build_id)) => writeln!(w, "Build ID: {:x?}", build_id)?,
|
||||||
|
Ok(None) => {}
|
||||||
|
Err(err) => writeln!(e, "Failed to parse build ID: {}", err)?,
|
||||||
|
}
|
||||||
|
match file.gnu_debuglink() {
|
||||||
|
Ok(Some((filename, crc))) => writeln!(
|
||||||
|
w,
|
||||||
|
"GNU debug link: {} CRC: {:08x}",
|
||||||
|
String::from_utf8_lossy(filename),
|
||||||
|
crc,
|
||||||
|
)?,
|
||||||
|
Ok(None) => {}
|
||||||
|
Err(err) => writeln!(e, "Failed to parse GNU debug link: {}", err)?,
|
||||||
|
}
|
||||||
|
match file.gnu_debugaltlink() {
|
||||||
|
Ok(Some((filename, build_id))) => writeln!(
|
||||||
|
w,
|
||||||
|
"GNU debug alt link: {}, build ID: {:x?}",
|
||||||
|
String::from_utf8_lossy(filename),
|
||||||
|
build_id,
|
||||||
|
)?,
|
||||||
|
Ok(None) => {}
|
||||||
|
Err(err) => writeln!(e, "Failed to parse GNU debug alt link: {}", err)?,
|
||||||
|
}
|
||||||
|
match file.pdb_info() {
|
||||||
|
Ok(Some(info)) => writeln!(
|
||||||
|
w,
|
||||||
|
"PDB file: {}, GUID: {:x?}, Age: {}",
|
||||||
|
String::from_utf8_lossy(info.path()),
|
||||||
|
info.guid(),
|
||||||
|
info.age()
|
||||||
|
)?,
|
||||||
|
Ok(None) => {}
|
||||||
|
Err(err) => writeln!(e, "Failed to parse PE CodeView info: {}", err)?,
|
||||||
|
}
|
||||||
|
|
||||||
|
for segment in file.segments() {
|
||||||
|
writeln!(w, "{:x?}", segment)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
for section in file.sections() {
|
||||||
|
writeln!(w, "{}: {:x?}", section.index().0, section)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
for comdat in file.comdats() {
|
||||||
|
write!(w, "{:?} Sections:", comdat)?;
|
||||||
|
for section in comdat.sections() {
|
||||||
|
write!(w, " {}", section.0)?;
|
||||||
|
}
|
||||||
|
writeln!(w)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
writeln!(w)?;
|
||||||
|
writeln!(w, "Symbols")?;
|
||||||
|
for symbol in file.symbols() {
|
||||||
|
writeln!(w, "{}: {:x?}", symbol.index().0, symbol)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
for section in file.sections() {
|
||||||
|
if section.relocations().next().is_some() {
|
||||||
|
writeln!(
|
||||||
|
w,
|
||||||
|
"\n{} relocations",
|
||||||
|
section.name().unwrap_or("<invalid name>")
|
||||||
|
)?;
|
||||||
|
for relocation in section.relocations() {
|
||||||
|
writeln!(w, "{:x?}", relocation)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
writeln!(w)?;
|
||||||
|
writeln!(w, "Dynamic symbols")?;
|
||||||
|
for symbol in file.dynamic_symbols() {
|
||||||
|
writeln!(w, "{}: {:x?}", symbol.index().0, symbol)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(relocations) = file.dynamic_relocations() {
|
||||||
|
writeln!(w)?;
|
||||||
|
writeln!(w, "Dynamic relocations")?;
|
||||||
|
for relocation in relocations {
|
||||||
|
writeln!(w, "{:x?}", relocation)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match file.imports() {
|
||||||
|
Ok(imports) => {
|
||||||
|
if !imports.is_empty() {
|
||||||
|
writeln!(w)?;
|
||||||
|
for import in imports {
|
||||||
|
writeln!(w, "{:x?}", import)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => writeln!(e, "Failed to parse imports: {}", err)?,
|
||||||
|
}
|
||||||
|
|
||||||
|
match file.exports() {
|
||||||
|
Ok(exports) => {
|
||||||
|
if !exports.is_empty() {
|
||||||
|
writeln!(w)?;
|
||||||
|
for export in exports {
|
||||||
|
writeln!(w, "{:x?}", export)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => writeln!(e, "Failed to parse exports: {}", err)?,
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
70
__compress/zstd-demo/Cargo.lock
generated
Normal file
70
__compress/zstd-demo/Cargo.lock
generated
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.0.79"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
|
||||||
|
dependencies = [
|
||||||
|
"jobserver",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jobserver"
|
||||||
|
version = "0.1.25"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.139"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkg-config"
|
||||||
|
version = "0.3.26"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zstd"
|
||||||
|
version = "0.12.3+zstd.1.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "76eea132fb024e0e13fd9c2f5d5d595d8a967aa72382ac2f9d39fcc95afd0806"
|
||||||
|
dependencies = [
|
||||||
|
"zstd-safe",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zstd-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"zstd",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zstd-safe"
|
||||||
|
version = "6.0.4+zstd.1.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7afb4b54b8910cf5447638cb54bf4e8a65cbedd783af98b98c62ffe91f185543"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"zstd-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zstd-sys"
|
||||||
|
version = "2.0.7+zstd.1.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"pkg-config",
|
||||||
|
]
|
||||||
9
__compress/zstd-demo/Cargo.toml
Normal file
9
__compress/zstd-demo/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "zstd-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
zstd = "0.12.3"
|
||||||
29
__compress/zstd-demo/src/main.rs
Normal file
29
__compress/zstd-demo/src/main.rs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
use std::collections::VecDeque;
|
||||||
|
use std::io;
|
||||||
|
use zstd::Encoder;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let inputs = "hello world".repeat(100);
|
||||||
|
let outputs = compress_manually(1, inputs.as_bytes().to_vec().into());
|
||||||
|
|
||||||
|
println!("Inputs len: {}", inputs.len());
|
||||||
|
println!("Outputs len: {}", outputs.len());
|
||||||
|
println!("{:x?}", outputs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// fn compress(level: i32) {
|
||||||
|
// zstd::stream::copy_encode(io::stdin(), io::stdout(), level).unwrap();
|
||||||
|
// }
|
||||||
|
// fn decompress() {
|
||||||
|
// zstd::stream::copy_decode(io::stdin(), io::stdout()).unwrap();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// This function does the same thing, directly using an `Encoder`:
|
||||||
|
fn compress_manually(level: i32, mut input: VecDeque<u8>) -> Vec<u8> {
|
||||||
|
let mut output: Vec<u8> = vec![];
|
||||||
|
let mut encoder = Encoder::new(&mut output, level).unwrap();
|
||||||
|
io::copy(&mut input, &mut encoder).unwrap();
|
||||||
|
encoder.finish().unwrap();
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
421
__concurrent/async-fn-resumed-after-completion/Cargo.lock
generated
Normal file
421
__concurrent/async-fn-resumed-after-completion/Cargo.lock
generated
Normal file
@@ -0,0 +1,421 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "addr2line"
|
||||||
|
version = "0.21.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
|
||||||
|
dependencies = [
|
||||||
|
"gimli",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "adler"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "async-fn-resumed-after-completion"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "backtrace"
|
||||||
|
version = "0.3.69"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
|
||||||
|
dependencies = [
|
||||||
|
"addr2line",
|
||||||
|
"cc",
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"miniz_oxide",
|
||||||
|
"object",
|
||||||
|
"rustc-demangle",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.3.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytes"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.0.90"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gimli"
|
||||||
|
version = "0.28.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hermit-abi"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.153"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lock_api"
|
||||||
|
version = "0.4.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"scopeguard",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "miniz_oxide"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7"
|
||||||
|
dependencies = [
|
||||||
|
"adler",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mio"
|
||||||
|
version = "0.8.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num_cpus"
|
||||||
|
version = "1.16.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "object"
|
||||||
|
version = "0.32.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot"
|
||||||
|
version = "0.12.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
|
||||||
|
dependencies = [
|
||||||
|
"lock_api",
|
||||||
|
"parking_lot_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot_core"
|
||||||
|
version = "0.9.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"redox_syscall",
|
||||||
|
"smallvec",
|
||||||
|
"windows-targets 0.48.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-project-lite"
|
||||||
|
version = "0.2.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.78"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.35"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_syscall"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-demangle"
|
||||||
|
version = "0.1.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scopeguard"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "signal-hook-registry"
|
||||||
|
version = "1.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "smallvec"
|
||||||
|
version = "1.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "socket2"
|
||||||
|
version = "0.5.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.52"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio"
|
||||||
|
version = "1.36.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931"
|
||||||
|
dependencies = [
|
||||||
|
"backtrace",
|
||||||
|
"bytes",
|
||||||
|
"libc",
|
||||||
|
"mio",
|
||||||
|
"num_cpus",
|
||||||
|
"parking_lot",
|
||||||
|
"pin-project-lite",
|
||||||
|
"signal-hook-registry",
|
||||||
|
"socket2",
|
||||||
|
"tokio-macros",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-macros"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.48.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.52.4",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm 0.48.5",
|
||||||
|
"windows_aarch64_msvc 0.48.5",
|
||||||
|
"windows_i686_gnu 0.48.5",
|
||||||
|
"windows_i686_msvc 0.48.5",
|
||||||
|
"windows_x86_64_gnu 0.48.5",
|
||||||
|
"windows_x86_64_gnullvm 0.48.5",
|
||||||
|
"windows_x86_64_msvc 0.48.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm 0.52.4",
|
||||||
|
"windows_aarch64_msvc 0.52.4",
|
||||||
|
"windows_i686_gnu 0.52.4",
|
||||||
|
"windows_i686_msvc 0.52.4",
|
||||||
|
"windows_x86_64_gnu 0.52.4",
|
||||||
|
"windows_x86_64_gnullvm 0.52.4",
|
||||||
|
"windows_x86_64_msvc 0.52.4",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "async-fn-resumed-after-completion"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
tokio = { version = "1.36.0", features = ["full"] }
|
||||||
48
__concurrent/async-fn-resumed-after-completion/src/main.rs
Normal file
48
__concurrent/async-fn-resumed-after-completion/src/main.rs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
async fn action(input: Option<i32>) -> Option<String> {
|
||||||
|
// 若 input(输入)是None,则返回 None
|
||||||
|
// 事实上也可以这么写: `let i = input?;`
|
||||||
|
let _i = match input {
|
||||||
|
Some(input) => input,
|
||||||
|
None => return None,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 这里定义一些逻辑
|
||||||
|
Some("test".into())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let (tx, mut rx) = tokio::sync::mpsc::channel(128);
|
||||||
|
|
||||||
|
let mut done = false;
|
||||||
|
let operation = action(None);
|
||||||
|
tokio::pin!(operation);
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let _ = tx.send(1).await;
|
||||||
|
let _ = tx.send(3).await;
|
||||||
|
let _ = tx.send(2).await;
|
||||||
|
});
|
||||||
|
|
||||||
|
loop {
|
||||||
|
tokio::select! {
|
||||||
|
res = &mut operation, if !done => {
|
||||||
|
println!("res = &mut operation, done={}", done);
|
||||||
|
done = true;
|
||||||
|
|
||||||
|
if let Some(v) = res {
|
||||||
|
println!("GOT = {}", v);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(v) = rx.recv() => {
|
||||||
|
println!("Some(v={}) = rx.recv()", v);
|
||||||
|
if v % 2 == 0 {
|
||||||
|
// `.set` 是 `Pin` 上定义的方法
|
||||||
|
operation.set(action(Some(v)));
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
444
__concurrent/waitgroup-demo/Cargo.lock
generated
Normal file
444
__concurrent/waitgroup-demo/Cargo.lock
generated
Normal file
@@ -0,0 +1,444 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "addr2line"
|
||||||
|
version = "0.21.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
|
||||||
|
dependencies = [
|
||||||
|
"gimli",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "adler"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "atomic-waker"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "backtrace"
|
||||||
|
version = "0.3.71"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d"
|
||||||
|
dependencies = [
|
||||||
|
"addr2line",
|
||||||
|
"cc",
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"miniz_oxide",
|
||||||
|
"object",
|
||||||
|
"rustc-demangle",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytes"
|
||||||
|
version = "1.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.0.96"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gimli"
|
||||||
|
version = "0.28.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hermit-abi"
|
||||||
|
version = "0.3.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.154"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lock_api"
|
||||||
|
version = "0.4.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"scopeguard",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "miniz_oxide"
|
||||||
|
version = "0.7.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7"
|
||||||
|
dependencies = [
|
||||||
|
"adler",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mio"
|
||||||
|
version = "0.8.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num_cpus"
|
||||||
|
version = "1.16.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "object"
|
||||||
|
version = "0.32.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot"
|
||||||
|
version = "0.12.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb"
|
||||||
|
dependencies = [
|
||||||
|
"lock_api",
|
||||||
|
"parking_lot_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot_core"
|
||||||
|
version = "0.9.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"redox_syscall",
|
||||||
|
"smallvec",
|
||||||
|
"windows-targets 0.52.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-project-lite"
|
||||||
|
version = "0.2.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.81"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.36"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_syscall"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-demangle"
|
||||||
|
version = "0.1.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scopeguard"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "signal-hook-registry"
|
||||||
|
version = "1.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "smallvec"
|
||||||
|
version = "1.13.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "socket2"
|
||||||
|
version = "0.5.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.60"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio"
|
||||||
|
version = "1.37.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787"
|
||||||
|
dependencies = [
|
||||||
|
"backtrace",
|
||||||
|
"bytes",
|
||||||
|
"libc",
|
||||||
|
"mio",
|
||||||
|
"num_cpus",
|
||||||
|
"parking_lot",
|
||||||
|
"pin-project-lite",
|
||||||
|
"signal-hook-registry",
|
||||||
|
"socket2",
|
||||||
|
"tokio-macros",
|
||||||
|
"windows-sys 0.48.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio-macros"
|
||||||
|
version = "2.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "waitgroup"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d1f50000a783467e6c0200f9d10642f4bc424e39efc1b770203e88b488f79292"
|
||||||
|
dependencies = [
|
||||||
|
"atomic-waker",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "waitgroup-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"tokio",
|
||||||
|
"waitgroup",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.48.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.52.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm 0.48.5",
|
||||||
|
"windows_aarch64_msvc 0.48.5",
|
||||||
|
"windows_i686_gnu 0.48.5",
|
||||||
|
"windows_i686_msvc 0.48.5",
|
||||||
|
"windows_x86_64_gnu 0.48.5",
|
||||||
|
"windows_x86_64_gnullvm 0.48.5",
|
||||||
|
"windows_x86_64_msvc 0.48.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.52.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm 0.52.5",
|
||||||
|
"windows_aarch64_msvc 0.52.5",
|
||||||
|
"windows_i686_gnu 0.52.5",
|
||||||
|
"windows_i686_gnullvm",
|
||||||
|
"windows_i686_msvc 0.52.5",
|
||||||
|
"windows_x86_64_gnu 0.52.5",
|
||||||
|
"windows_x86_64_gnullvm 0.52.5",
|
||||||
|
"windows_x86_64_msvc 0.52.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.52.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.52.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.52.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnullvm"
|
||||||
|
version = "0.52.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.52.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.52.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.52.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.52.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
|
||||||
10
__concurrent/waitgroup-demo/Cargo.toml
Normal file
10
__concurrent/waitgroup-demo/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "waitgroup-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
tokio = { version = "1.37.0", features = ["full"] }
|
||||||
|
waitgroup = "0.1.2"
|
||||||
26
__concurrent/waitgroup-demo/src/main.rs
Normal file
26
__concurrent/waitgroup-demo/src/main.rs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use tokio::task::yield_now;
|
||||||
|
use tokio::time;
|
||||||
|
use tokio::time::Instant;
|
||||||
|
use waitgroup::WaitGroup;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let wg = WaitGroup::new();
|
||||||
|
for i in 80..100 {
|
||||||
|
let w = wg.worker();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
println!("Start work #{}", i);
|
||||||
|
time::sleep(Duration::from_millis(i * 100)).await;
|
||||||
|
println!("Finish work #{}", i);
|
||||||
|
drop(w);
|
||||||
|
});
|
||||||
|
yield_now().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
let instant = Instant::now();
|
||||||
|
println!("Start waiting...");
|
||||||
|
wg.wait().await;
|
||||||
|
println!("Finish wait, elapsed: {}ms", instant.elapsed().as_millis());
|
||||||
|
}
|
||||||
4
__crypto/README.md
Normal file
4
__crypto/README.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
Cryptography:
|
||||||
|
https://cryptography.rs/
|
||||||
|
|
||||||
|
|
||||||
454
__crypto/aegis-test/Cargo.lock
generated
Normal file
454
__crypto/aegis-test/Cargo.lock
generated
Normal file
@@ -0,0 +1,454 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aead"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0"
|
||||||
|
dependencies = [
|
||||||
|
"crypto-common",
|
||||||
|
"generic-array",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aegis"
|
||||||
|
version = "0.4.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f5bfadafb4f9094ee03767a64997e6645cf29243d6d4c04158212b8663f9d6d"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"softaes",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aegis-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"aegis",
|
||||||
|
"aes-gcm",
|
||||||
|
"ascon-aead",
|
||||||
|
"benchmark-simple",
|
||||||
|
"chacha20poly1305",
|
||||||
|
"rocca",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aes"
|
||||||
|
version = "0.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"cipher",
|
||||||
|
"cpufeatures",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aes-gcm"
|
||||||
|
version = "0.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "209b47e8954a928e1d72e86eca7000ebb6655fe1436d33eefc2201cad027e237"
|
||||||
|
dependencies = [
|
||||||
|
"aead",
|
||||||
|
"aes",
|
||||||
|
"cipher",
|
||||||
|
"ctr",
|
||||||
|
"ghash",
|
||||||
|
"subtle",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ascon"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9fe9a0cff241855e9166670d259192aacf1e9a81b865dc9905afbbab31a9d2c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ascon-aead"
|
||||||
|
version = "0.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cf081c54f55de655350e71e01dd36e093012f11447a3d575b907b84425887fa3"
|
||||||
|
dependencies = [
|
||||||
|
"aead",
|
||||||
|
"ascon",
|
||||||
|
"subtle",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "benchmark-simple"
|
||||||
|
version = "0.1.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f87ada40e82bfa2716c35e99c1969299d3a17ce8ec05d58145d4056da16ea2c4"
|
||||||
|
dependencies = [
|
||||||
|
"precision",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bumpalo"
|
||||||
|
version = "3.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.0.82"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chacha20"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"cipher",
|
||||||
|
"cpufeatures",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "chacha20poly1305"
|
||||||
|
version = "0.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35"
|
||||||
|
dependencies = [
|
||||||
|
"aead",
|
||||||
|
"chacha20",
|
||||||
|
"cipher",
|
||||||
|
"poly1305",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cipher"
|
||||||
|
version = "0.4.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
|
||||||
|
dependencies = [
|
||||||
|
"crypto-common",
|
||||||
|
"inout",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cpufeatures"
|
||||||
|
version = "0.2.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-common"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
"rand_core",
|
||||||
|
"typenum",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ctr"
|
||||||
|
version = "0.9.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835"
|
||||||
|
dependencies = [
|
||||||
|
"cipher",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "generic-array"
|
||||||
|
version = "0.14.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||||
|
dependencies = [
|
||||||
|
"typenum",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.2.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ghash"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d930750de5717d2dd0b8c0d42c076c0e884c81a73e6cab859bbd2339c71e3e40"
|
||||||
|
dependencies = [
|
||||||
|
"opaque-debug",
|
||||||
|
"polyval",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "inout"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.147"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.18.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "opaque-debug"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "poly1305"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf"
|
||||||
|
dependencies = [
|
||||||
|
"cpufeatures",
|
||||||
|
"opaque-debug",
|
||||||
|
"universal-hash",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "polyval"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d52cff9d1d4dee5fe6d03729099f4a310a41179e0a10dbf542039873f2e826fb"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"cpufeatures",
|
||||||
|
"opaque-debug",
|
||||||
|
"universal-hash",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "precision"
|
||||||
|
version = "0.1.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "78ae7cc38dee6656eeb0eee56a8aef8aa40d5128acd9c4b8bdfb80ae08ee1993"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
"rustc_version",
|
||||||
|
"wasi",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.66"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.33"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rocca"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b52de49d9fde07d1241f2156a8958b65c71ce615f2ff8256ae5106513eb1713e"
|
||||||
|
dependencies = [
|
||||||
|
"aes",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc_version"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
|
||||||
|
dependencies = [
|
||||||
|
"semver",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver"
|
||||||
|
version = "1.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "softaes"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ff744c5d37b8ff11721ef14e92d1ec8743b5419d81513b3df22346cbee3d9d3e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "subtle"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.29"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typenum"
|
||||||
|
version = "1.16.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "universal-hash"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"
|
||||||
|
dependencies = [
|
||||||
|
"crypto-common",
|
||||||
|
"subtle",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen"
|
||||||
|
version = "0.2.87"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"wasm-bindgen-macro",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-backend"
|
||||||
|
version = "0.2.87"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
|
||||||
|
dependencies = [
|
||||||
|
"bumpalo",
|
||||||
|
"log",
|
||||||
|
"once_cell",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-macro"
|
||||||
|
version = "0.2.87"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"wasm-bindgen-macro-support",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-macro-support"
|
||||||
|
version = "0.2.87"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"wasm-bindgen-backend",
|
||||||
|
"wasm-bindgen-shared",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-bindgen-shared"
|
||||||
|
version = "0.2.87"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zeroize"
|
||||||
|
version = "1.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9"
|
||||||
|
dependencies = [
|
||||||
|
"zeroize_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zeroize_derive"
|
||||||
|
version = "1.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
14
__crypto/aegis-test/Cargo.toml
Normal file
14
__crypto/aegis-test/Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
[package]
|
||||||
|
name = "aegis-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
aegis = "0.4.4"
|
||||||
|
aes-gcm = "0.10.2"
|
||||||
|
ascon-aead = "0.4.2"
|
||||||
|
benchmark-simple = "0.1.8"
|
||||||
|
chacha20poly1305 = "0.10.1"
|
||||||
|
rocca = "0.3.0"
|
||||||
62
__crypto/aegis-test/README.md
Normal file
62
__crypto/aegis-test/README.md
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
Benchmark:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ cargo r --release
|
||||||
|
aegis128l : 10.63 G/s
|
||||||
|
aes256-gcm : 546.31 M/s
|
||||||
|
aes128-gcm : 597.56 M/s
|
||||||
|
chacha20-poly1305 : 1.03 G/s
|
||||||
|
ascon128a : 330.85 M/s
|
||||||
|
rocca : 307.84 M/s
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ RUSTFLAGS="-C target-cpu=native" cargo r --release
|
||||||
|
aegis128l : 10.66 G/s
|
||||||
|
aes256-gcm : 701.21 M/s
|
||||||
|
aes128-gcm : 794.85 M/s
|
||||||
|
chacha20-poly1305 : 1.18 G/s
|
||||||
|
ascon128a : 347.18 M/s
|
||||||
|
rocca : 4.35 G/s
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ RUSTFLAGS="-Ctarget-feature=+aes,+sse4.1" cargo r --release
|
||||||
|
aegis128l : 10.68 G/s
|
||||||
|
aes256-gcm : 554.68 M/s
|
||||||
|
aes128-gcm : 608.58 M/s
|
||||||
|
chacha20-poly1305 : 1.04 G/s
|
||||||
|
ascon128a : 337.74 M/s
|
||||||
|
rocca : 2.75 G/s
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ RUSTFLAGS="-Ctarget-feature=+aes,+sse4.2" cargo r --release
|
||||||
|
aegis128l : 10.74 G/s
|
||||||
|
aes256-gcm : 706.54 M/s
|
||||||
|
aes128-gcm : 797.11 M/s
|
||||||
|
chacha20-poly1305 : 1.04 G/s
|
||||||
|
ascon128a : 338.19 M/s
|
||||||
|
rocca : 6.05 G/s
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ RUSTFLAGS="-C target-cpu=native -Ctarget-feature=+aes,+pclmulqdq,+sse4.1" cargo r --release
|
||||||
|
aegis128l : 10.62 G/s
|
||||||
|
aes256-gcm : 695.29 M/s
|
||||||
|
aes128-gcm : 778.97 M/s
|
||||||
|
chacha20-poly1305 : 1.17 G/s
|
||||||
|
ascon128a : 345.49 M/s
|
||||||
|
rocca : 4.28 G/s
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ RUSTFLAGS="-C target-cpu=native -Ctarget-feature=+aes,+pclmulqdq,+sse4.2" cargo r --release
|
||||||
|
aegis128l : 10.60 G/s
|
||||||
|
aes256-gcm : 692.76 M/s
|
||||||
|
aes128-gcm : 760.85 M/s
|
||||||
|
chacha20-poly1305 : 1.18 G/s
|
||||||
|
ascon128a : 344.81 M/s
|
||||||
|
rocca : 4.28 G/s
|
||||||
|
```
|
||||||
84
__crypto/aegis-test/src/main.rs
Normal file
84
__crypto/aegis-test/src/main.rs
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
use aegis::aegis128l::Aegis128L;
|
||||||
|
use aes_gcm::{
|
||||||
|
aead::{AeadInPlace as _, KeyInit as _},
|
||||||
|
Aes128Gcm, Aes256Gcm,
|
||||||
|
};
|
||||||
|
use benchmark_simple::*;
|
||||||
|
use chacha20poly1305::ChaCha20Poly1305;
|
||||||
|
use rocca::Rocca;
|
||||||
|
|
||||||
|
fn test_aes256gcm(m: &mut [u8]) {
|
||||||
|
let key = aes_gcm::Key::<Aes256Gcm>::from_slice(&[0u8; 32]);
|
||||||
|
let nonce = aes_gcm::Nonce::from_slice(&[0u8; 12]);
|
||||||
|
let state = Aes256Gcm::new(key);
|
||||||
|
state.encrypt_in_place_detached(nonce, &[], m).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_aes128gcm(m: &mut [u8]) {
|
||||||
|
let key = aes_gcm::Key::<Aes128Gcm>::from_slice(&[0u8; 16]);
|
||||||
|
let nonce = aes_gcm::Nonce::from_slice(&[0u8; 12]);
|
||||||
|
let state = Aes128Gcm::new(key);
|
||||||
|
state.encrypt_in_place_detached(nonce, &[], m).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_chacha20poly1305(m: &mut [u8]) {
|
||||||
|
let key = chacha20poly1305::Key::from_slice(&[0u8; 32]);
|
||||||
|
let nonce = chacha20poly1305::Nonce::from_slice(&[0u8; 12]);
|
||||||
|
let state = ChaCha20Poly1305::new(key);
|
||||||
|
state.encrypt_in_place_detached(nonce, &[], m).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_ascon128a(m: &mut [u8]) {
|
||||||
|
let key = [0u8; 16];
|
||||||
|
let nonce = [0u8; 16];
|
||||||
|
let state = ascon_aead::Ascon128a::new(key.as_slice().into());
|
||||||
|
state
|
||||||
|
.encrypt_in_place_detached(nonce.as_slice().into(), &[], m)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_aegis128l(m: &mut [u8]) {
|
||||||
|
let key = [0u8; 16];
|
||||||
|
let nonce = [0u8; 16];
|
||||||
|
let state = Aegis128L::<16>::new(&nonce, &key);
|
||||||
|
state.encrypt_in_place(m, &[]);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_rocca(m: &mut [u8]) {
|
||||||
|
let key = [0u8; 32];
|
||||||
|
let nonce = [0u8; 16];
|
||||||
|
let state = Rocca::new(&nonce, &key);
|
||||||
|
state.encrypt_in_place(m, &[]);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let bench = Bench::new();
|
||||||
|
let mut m = vec![0xd0u8; 16384];
|
||||||
|
|
||||||
|
let options = &Options {
|
||||||
|
iterations: 10_000, // 100_000 -> 10_000 -> 1_000
|
||||||
|
warmup_iterations: 1_000,
|
||||||
|
min_samples: 5,
|
||||||
|
max_samples: 10,
|
||||||
|
max_rsd: 1.0,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let res = bench.run(options, || test_aegis128l(&mut m));
|
||||||
|
println!("aegis128l : {}", res.throughput(m.len() as _));
|
||||||
|
|
||||||
|
let res = bench.run(options, || test_aes256gcm(&mut m));
|
||||||
|
println!("aes256-gcm : {}", res.throughput(m.len() as _));
|
||||||
|
|
||||||
|
let res = bench.run(options, || test_aes128gcm(&mut m));
|
||||||
|
println!("aes128-gcm : {}", res.throughput(m.len() as _));
|
||||||
|
|
||||||
|
let res = bench.run(options, || test_chacha20poly1305(&mut m));
|
||||||
|
println!("chacha20-poly1305 : {}", res.throughput(m.len() as _));
|
||||||
|
|
||||||
|
let res = bench.run(options, || test_ascon128a(&mut m));
|
||||||
|
println!("ascon128a : {}", res.throughput(m.len() as _));
|
||||||
|
|
||||||
|
let res = bench.run(options, || test_rocca(&mut m));
|
||||||
|
println!("rocca : {}", res.throughput(m.len() as _));
|
||||||
|
}
|
||||||
100
__crypto/aes_ctr_test/Cargo.lock
generated
Normal file
100
__crypto/aes_ctr_test/Cargo.lock
generated
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aes"
|
||||||
|
version = "0.8.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"cipher",
|
||||||
|
"cpufeatures",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aes_ctr_test"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"aes",
|
||||||
|
"hex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cipher"
|
||||||
|
version = "0.4.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
|
||||||
|
dependencies = [
|
||||||
|
"crypto-common",
|
||||||
|
"inout",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cpufeatures"
|
||||||
|
version = "0.2.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-common"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
"typenum",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "generic-array"
|
||||||
|
version = "0.14.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||||
|
dependencies = [
|
||||||
|
"typenum",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hex"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "inout"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.158"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typenum"
|
||||||
|
version = "1.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||||
8
__crypto/aes_ctr_test/Cargo.toml
Normal file
8
__crypto/aes_ctr_test/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "aes_ctr_test"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
aes = "0.8.4"
|
||||||
|
hex = "0.4.3"
|
||||||
42
__crypto/aes_ctr_test/README.md
Normal file
42
__crypto/aes_ctr_test/README.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
|
||||||
|
Test Java codes:
|
||||||
|
```java
|
||||||
|
public class AesCtrTest {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
final byte[] key = new byte[]{
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
|
||||||
|
};
|
||||||
|
final byte[] iv = new byte[]{
|
||||||
|
1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
|
};
|
||||||
|
final SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
|
||||||
|
|
||||||
|
final Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, keySpec, new IvParameterSpec(iv));
|
||||||
|
System.out.println(Bytes.from(cipher.doFinal("hello world".getBytes())).asHex());
|
||||||
|
System.out.println(Bytes.from(cipher.doFinal(
|
||||||
|
"hello world.hello world.hello world.hello world.hello world.hello world.".getBytes())).asHex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Outputs:
|
||||||
|
```
|
||||||
|
84ad8d80732490c061177a
|
||||||
|
84ad8d80732490c061177a58bd26d032d6fcff2e66f9afe3cf95717485d3a4485d4a2a7bd835df3d0756b8192e3bf5a287ad8dd81942c43bc812c82d666ebbb34df4e2a5069467d9
|
||||||
|
```
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
Java `nonce` counter:
|
||||||
|
|
||||||
|
`com.sun.crypto.provider.CounterMode`
|
||||||
|
|
||||||
|
```java
|
||||||
|
private static void increment(byte[] nonce) {
|
||||||
|
for(int index = nonce.length - 1; index >= 0 && ++nonce[index] == 0; --index) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
109
__crypto/aes_ctr_test/src/main.rs
Normal file
109
__crypto/aes_ctr_test/src/main.rs
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
use aes::cipher::generic_array::GenericArray;
|
||||||
|
use aes::cipher::{Block, BlockEncryptMut, KeyInit};
|
||||||
|
use aes::Aes128;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let key = [0_u8; 16];
|
||||||
|
let iv = [0_u8; 16];
|
||||||
|
|
||||||
|
let plaintext = b"hello world";
|
||||||
|
let ciphertext = encrypt_ctr(&key, &iv, plaintext);
|
||||||
|
assert_eq!("0e8c27b880aa5b54fa209e", hex::encode(&ciphertext));
|
||||||
|
|
||||||
|
let plaintext = b"hello world.hello world.hello world.hello world.hello world.hello world.";
|
||||||
|
let ciphertext = encrypt_ctr(&key, &iv, plaintext);
|
||||||
|
assert_eq!("0e8c27b880aa5b54fa209e77a251474237c28ba18812544f5e1a713bcbc7323571e4bee008d3cf\
|
||||||
|
fe9c08b5d603de9a569ff0c6c7266b2e4c8591edd1fceead8c4f22664e3c1ff0f4", hex::encode(&ciphertext));
|
||||||
|
|
||||||
|
let key = [1_u8; 16];
|
||||||
|
let mut iv = [0_u8; 16];
|
||||||
|
for i in 0..8 {
|
||||||
|
iv[i] = i as u8 + 1;
|
||||||
|
}
|
||||||
|
let plaintext = b"hello world.hello world.hello world.hello world.hello world.hello world.";
|
||||||
|
let ciphertext = encrypt_ctr(&key, &iv, plaintext);
|
||||||
|
assert_eq!("84ad8d80732490c061177a58bd26d032d6fcff2e66f9afe3cf95717485d3a4485d4a2a7bd835df\
|
||||||
|
3d0756b8192e3bf5a287ad8dd81942c43bc812c82d666ebbb34df4e2a5069467d9", hex::encode(&ciphertext));
|
||||||
|
|
||||||
|
let key = [1_u8; 16];
|
||||||
|
let iv = [1, 2, 3, 4, 5, 6, 7, 0, 1, 1, 2, 2, 3, 3, 4, 4];
|
||||||
|
let plaintext = b"hello world.hello world.hello world.hello world.hello world.hello world.";
|
||||||
|
let ciphertext = encrypt_ctr(&key, &iv, plaintext);
|
||||||
|
assert_eq!("d373d6b3491c7b8940996f9efefc98d0f564d066a557cf0aa29935a638f99d077a85338e574ee6\
|
||||||
|
7f69da41b8a87569c324b4d421f1350e11d6be30721605b9dd6401bc3780da3452", hex::encode(&ciphertext));
|
||||||
|
|
||||||
|
let key = [1_u8; 16];
|
||||||
|
let iv = [1, 2, 3, 4, 5, 6, 7, 0, 1, 1, 2, 2, 3, 3, 4, 4];
|
||||||
|
let plaintext = b"hello world.hello world.hello world.hello world.hello world.h\
|
||||||
|
ello world.hello world.hello world.hello world.hello world.hello world.hello world.hello w\
|
||||||
|
orld.hello world.hello world.hello world.hello world.hello world.hello world.hello world.h\
|
||||||
|
ello world.hello world.hello world.hello world.hello world.hello world.hello world.hello w\
|
||||||
|
orld.hello world.hello world.hello world.hello world.hello world.hello world.hello world.h\
|
||||||
|
ello world.hello world.hello world.hello world.hello world.hello world.hello world.hello w\
|
||||||
|
orld.hello world.hello world.hello world.hello world.hello world.hello world.hello world.h\
|
||||||
|
ello world.hello world.hello world.hello world.hello world.hello world.hello world.hello w\
|
||||||
|
orld.hello world.hello world.hello world.hello world.hello world.hello world.hello world.h\
|
||||||
|
ello world.hello world.hello world.hello world.hello world.hello world.hello world.hello w\
|
||||||
|
orld.hello world.hello world.hello world.hello world.hello world.hello world.hello world.h\
|
||||||
|
ello world.hello world.hello world.hello world.";
|
||||||
|
let ciphertext = encrypt_ctr(&key, &iv, plaintext);
|
||||||
|
assert_eq!("d373d6b3491c7b8940996f9efefc98d0f564d066a557cf0aa29935a638f99d077a85338e574ee6\
|
||||||
|
7f69da41b8a87569c324b4d421f1350e11d6be30721605b9dd6401bc3780da3452033164403472b0ea84a7894b\
|
||||||
|
500100959ccc2cfbe2b6792691f1a1b047755c1961a730c7bcd941ab50b4ece7501d624d5af457875370dbc7e6\
|
||||||
|
0e73fd6ab10b5033fb3b3e2caed7489cc02bf174a3e7f04bd1e5c81c811314689b2bb7f6f0f0333d9b3bf637ff\
|
||||||
|
7ac34b32bc4905638204dbd97d4cefd1a823b5d49364c72d987807991eb703e47d56631f9f1a62c9f691bd3641\
|
||||||
|
509884144fc6e1b63e8177c8e1247ccc0769cb59cd973869f2ac3dd6cb90534ee42f69995e4af48de870936d21\
|
||||||
|
cf1b4ccd52e4bd0eafaff46dd6f34c91072ffd61f73050580b790deba9dc30d9557c4142a0dfa52b70e050a563\
|
||||||
|
abd69e87150da9325751a58bb3e162ea3a69347684e50710ea2bd25f6c285903d7b200a56a7eb042639410da17\
|
||||||
|
471c93e2b26b13091cc22ec81c3912a7121a1337a560d9733d904b6c6752993b2943861d3b770693281d3519fb\
|
||||||
|
69158df2353913aebe1e6c16787b8d2ff363c1c31bb8b491cec0214bd3ef61357569c8ecf9487087e22eca48b2\
|
||||||
|
d1c2c718ad7d3984eb7d0ca27b96653d90847ed138b581f8a01c0bea33c435e7f124f4009de059c46c006431fa\
|
||||||
|
5cf41ad9f16e6457389f928216ebd4efd048840a4dbc80da170c666a5293209866e9371f47005a12d6dc76f7fd\
|
||||||
|
57fc5b265cc38f4aef6e5496836d1c4c6d96b2c807997b3f61fd45f0acf505f3512ea04a0ad89cc35b344bdc3f\
|
||||||
|
2126b24bee40406ff00a733555316b8ccb57d661326d6b2d48a7a7fe33fbec23d69890b9368f6321d60b231cf2\
|
||||||
|
5680bcf7e8f43e443c19150b72394b5a9617fb8cc9666d43968fecdb56c22db6421ffbe3351fe479d9e7841288\
|
||||||
|
15fbeb7f1b5f9dc1f8b3d772741f7ef9884b5ca81d972d8537ea4c12cbf29c7e362ccd14ed83781db312da5d83\
|
||||||
|
8e11b20b050b6be472d8133f8f6525649dc9b967d40f430feb4cb3408a623a12658959f8cd8a115d8f63dd6e8b\
|
||||||
|
b8449937620b1cf783a0761fcbd4f48dcb572c1463a7c756bf9dd77d45f92cfe9a04dfb4d007a448d9b1a8c936\
|
||||||
|
9bcd35db598e7cdec566d075ff4c8d445e94ef49c0d0a78bb45921bf4c6e6b750a4d0f3310fc9a767a368ced10\
|
||||||
|
293987bf88026c69dcd805aea561d9b207c2710e6e90658ec5e0f8560449889ba8af852ea36b272aebb73ef59e\
|
||||||
|
74d1c0fe963ecbf1049743263681f5733cdf3b0b89b52667f63f65e4e7327ca45a2c1bd385f7c5fbf74b82e4f8\
|
||||||
|
0425c237813f2d39c4d7a06b49eec49b26dd234323747cf41eb4c2a7647b8548dcd72d59a4f0da2b1120759cfc\
|
||||||
|
dae5df80c55a9015fc48f985bda3d416f7301d72a4348953", hex::encode(&ciphertext));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encrypt_ctr(key: &[u8; 16], iv: &[u8; 16], plaintext: &[u8]) -> Vec<u8> {
|
||||||
|
let mut aes128 = Aes128::new_from_slice(key).unwrap();
|
||||||
|
let plaintext_len = plaintext.len();
|
||||||
|
let blocks_count = (plaintext_len / 16) + if plaintext_len % 16 == 0 { 0 } else { 1 };
|
||||||
|
let iv_u128 = u128::from_be_bytes(iv.clone());
|
||||||
|
|
||||||
|
let mut cipher_text = vec![0_u8; plaintext_len];
|
||||||
|
for i in 0..blocks_count {
|
||||||
|
let enc_iv_u128 = iv_u128 + i as u128;
|
||||||
|
let mut block: Block<Aes128> = GenericArray::from(enc_iv_u128.to_be_bytes()).clone();
|
||||||
|
aes128.encrypt_block_mut(&mut block);
|
||||||
|
|
||||||
|
let block_slice = block.as_slice();
|
||||||
|
for j in 0..block_slice.len() {
|
||||||
|
let oi = i * 16 + j;
|
||||||
|
if oi < plaintext_len {
|
||||||
|
cipher_text[oi] = block_slice[j] ^ plaintext[oi];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cipher_text
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_aes() {
|
||||||
|
let mut aes128 = Aes128::new_from_slice(
|
||||||
|
&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
let mut a: Block<Aes128> = GenericArray::from_slice(&[0_u8; 16]).clone();
|
||||||
|
aes128.encrypt_block_mut(&mut a);
|
||||||
|
println!("{}", hex::encode(a.as_slice()));
|
||||||
|
|
||||||
|
assert_eq!("66e94bd4ef8a2c3b884cfa59ca342b2e", hex::encode(a.as_slice()));
|
||||||
|
}
|
||||||
107
__crypto/aes_gcm_crypto/Cargo.lock
generated
Normal file
107
__crypto/aes_gcm_crypto/Cargo.lock
generated
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aes"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "433cfd6710c9986c576a25ca913c39d66a6474107b406f34f91d4a8923395241"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"cipher",
|
||||||
|
"cpufeatures",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aes_gcm_crypto"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"aes",
|
||||||
|
"hex",
|
||||||
|
"hex-literal",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cipher"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d1873270f8f7942c191139cb8a40fd228da6c3fd2fc376d7e92d47aa14aeb59e"
|
||||||
|
dependencies = [
|
||||||
|
"crypto-common",
|
||||||
|
"inout",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cpufeatures"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-common"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
"typenum",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "generic-array"
|
||||||
|
version = "0.14.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
|
||||||
|
dependencies = [
|
||||||
|
"typenum",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hex"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hex-literal"
|
||||||
|
version = "0.3.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "inout"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.139"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typenum"
|
||||||
|
version = "1.16.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
11
__crypto/aes_gcm_crypto/Cargo.toml
Normal file
11
__crypto/aes_gcm_crypto/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
name = "aes_gcm_crypto"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
aes = "0.8.2"
|
||||||
|
hex = "0.4.3"
|
||||||
|
hex-literal = "0.3.4"
|
||||||
162
__crypto/aes_gcm_crypto/src/main.rs
Normal file
162
__crypto/aes_gcm_crypto/src/main.rs
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
use aes::Aes256;
|
||||||
|
use aes::cipher::{BlockEncrypt, Key, KeyInit};
|
||||||
|
use aes::cipher::generic_array::GenericArray;
|
||||||
|
use hex_literal::hex;
|
||||||
|
|
||||||
|
pub struct GCM {
|
||||||
|
aes: Aes256,
|
||||||
|
}
|
||||||
|
|
||||||
|
// R = 11100001 || 0(120)
|
||||||
|
const R: u128 = 0b11100001 << 120;
|
||||||
|
|
||||||
|
fn gmul_128(x: u128, y: u128) -> u128 {
|
||||||
|
let mut z = 0u128;
|
||||||
|
let mut v = y;
|
||||||
|
for i in (0..128).rev() {
|
||||||
|
let xi = (x >> i) & 1;
|
||||||
|
if xi != 0 {
|
||||||
|
z ^= v;
|
||||||
|
}
|
||||||
|
v = match v & 1 == 0 {
|
||||||
|
true => { v >> 1 }
|
||||||
|
false => { (v >> 1) ^ R }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
z
|
||||||
|
}
|
||||||
|
|
||||||
|
fn u8to128(bytes: &[u8]) -> u128 {
|
||||||
|
let result = bytes.iter().rev().enumerate().fold(0, |acc, (i, &byte)| {
|
||||||
|
acc | (byte as u128) << (i * 8)
|
||||||
|
});
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
fn msb_s(s: usize, bytes: &[u8]) -> Vec<u8> {
|
||||||
|
let mut result = vec![];
|
||||||
|
let n = s / 8;
|
||||||
|
let remain = s % 8;
|
||||||
|
for i in 0..n {
|
||||||
|
result.push(bytes[i]);
|
||||||
|
}
|
||||||
|
if remain > 0 {
|
||||||
|
result.push(bytes[n] >> (8 - remain));
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
// incs(X)=MSBlen(X)-s(X) || [int(LSBs(X))+1 mod 2^s]s
|
||||||
|
fn inc_32(bits: u128) -> u128 {
|
||||||
|
let msb = bits >> 32;
|
||||||
|
let mut lsb = (bits & 0xffffffff) as u32;
|
||||||
|
lsb = lsb.wrapping_add(1);
|
||||||
|
msb << 32 | lsb as u128
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ghash(key: u128, messages: &[u128]) -> u128 {
|
||||||
|
let mut y = 0u128;
|
||||||
|
for i in 0..messages.len() {
|
||||||
|
let yi = gmul_128(y ^ messages[i], key);
|
||||||
|
y = yi;
|
||||||
|
}
|
||||||
|
y
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GCM {
|
||||||
|
pub fn new(key: [u8; 32]) -> Self {
|
||||||
|
let key = Key::<Aes256>::from_slice(&key);
|
||||||
|
let aes = Aes256::new(&key);
|
||||||
|
Self {
|
||||||
|
aes,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encrypt_block(&mut self, block: &[u8; 16]) -> Vec<u8> {
|
||||||
|
let mut block = GenericArray::from(block.clone());
|
||||||
|
self.aes.encrypt_block(&mut block);
|
||||||
|
block.to_vec()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ghash_key(&mut self) -> u128 {
|
||||||
|
u8to128(&self.encrypt_block(&[0u8; 16]))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn gctr(&mut self, iv: u128, message: &[u8]) -> Vec<u8> {
|
||||||
|
// 如果X是空串, 则直接返回
|
||||||
|
if message.len() == 0 {
|
||||||
|
return vec![];
|
||||||
|
}
|
||||||
|
let mut output = vec![];
|
||||||
|
let mut cb = iv;
|
||||||
|
for chunk in message.chunks(16) {
|
||||||
|
if chunk.len() < 16 {
|
||||||
|
let msb = msb_s(chunk.len() * 8, &self.encrypt_block(&cb.to_be_bytes()));
|
||||||
|
let y = u8to128(chunk) ^ u8to128(&msb);
|
||||||
|
output.extend_from_slice(&y.to_be_bytes()[16 - chunk.len()..16]);
|
||||||
|
} else {
|
||||||
|
let y = u8to128(chunk) ^ u8to128(&self.encrypt_block(&cb.to_be_bytes()));
|
||||||
|
output.extend_from_slice(&y.to_be_bytes());
|
||||||
|
}
|
||||||
|
// counter + 1
|
||||||
|
cb = inc_32(cb);
|
||||||
|
}
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ae(&mut self, iv_bytes: &[u8], adata: &[u8], message: &[u8]) -> (Vec<u8>, Vec<u8>) {
|
||||||
|
let ghash_key = self.ghash_key();
|
||||||
|
let mut iv_padding = vec![];
|
||||||
|
let iv = u8to128(iv_bytes);
|
||||||
|
let j0 = match iv_bytes.len() == 12 {
|
||||||
|
true => {
|
||||||
|
iv << 32 | 0x00000001
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
// s = 128[len(iv) / 128] - len(iv)
|
||||||
|
let s = 128 * (((iv_bytes.len() * 8) + 128 - 1) / 128) - (iv_bytes.len() * 8);
|
||||||
|
iv_padding.push(iv << s);
|
||||||
|
iv_padding.push((iv_bytes.len() * 8) as u128);
|
||||||
|
ghash(ghash_key, &iv_padding)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let message_len = message.len() * 8;
|
||||||
|
let adata_len = adata.len() * 8;
|
||||||
|
let u = 128 * ((message_len + 128 - 1) / 128) - message_len;
|
||||||
|
let v = 128 * ((adata_len + 128 - 1) / 128) - adata_len;
|
||||||
|
// println!("u, v: {}, {}", u, v);
|
||||||
|
// println!("j0 = {:02x?}", j0);
|
||||||
|
let enc = self.gctr(inc_32(j0), &message);
|
||||||
|
let mut bit_string = Vec::<u8>::new();
|
||||||
|
bit_string.extend_from_slice(adata);
|
||||||
|
bit_string.extend_from_slice(&vec![0x00; v / 8]);
|
||||||
|
// 这里认证的是密文
|
||||||
|
bit_string.extend_from_slice(&enc);
|
||||||
|
bit_string.extend_from_slice(&vec![0x00; u / 8]);
|
||||||
|
bit_string.extend_from_slice(&(adata_len as u64).to_be_bytes());
|
||||||
|
bit_string.extend_from_slice(&(message_len as u64).to_be_bytes());
|
||||||
|
// println!("len = {}, bit_string[u8] = {:02x?}", bit_string.len(), bit_string);
|
||||||
|
let bit_string: Vec<u128> = bit_string.chunks(16).map(|it| u8to128(it)).collect();
|
||||||
|
// println!("bit_string[u128] = {:02x?}", bit_string);
|
||||||
|
let s = ghash(ghash_key, &bit_string).to_be_bytes();
|
||||||
|
// println!("{:02x?}", s);
|
||||||
|
let tag = self.gctr(j0, &s);
|
||||||
|
// println!("tag = {:02x?}", tag);
|
||||||
|
// println!("enc = {:02x?}", enc);
|
||||||
|
(tag, enc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://developer.aliyun.com/article/952809
|
||||||
|
fn main() {
|
||||||
|
let key: [u8; 32] = hex!("0001020304050607080910111213141516171819202122232425262728293031");
|
||||||
|
let p: Vec<u8> = "Hello world!".as_bytes().to_vec();
|
||||||
|
let iv = hex!("000102030405060708091011");
|
||||||
|
let mut gcm = GCM::new(key);
|
||||||
|
// let h = gcm.ghash_key();
|
||||||
|
// assert_eq!(h, u8to128(&hex!("66e94bd4ef8a2c3b884cfa59ca342b2e")));
|
||||||
|
|
||||||
|
let (tag, enc) = gcm.ae(&iv, &[], &p);
|
||||||
|
println!("{}{}", hex::encode(&enc), hex::encode(tag));
|
||||||
|
println!("dce9511866417cff5123fa08c9e92cf156c5fc8bf6108ff28816fb58");
|
||||||
|
}
|
||||||
185
__crypto/asn1-der-test/Cargo.lock
generated
Normal file
185
__crypto/asn1-der-test/Cargo.lock
generated
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "asn1-der-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"asn1-rs",
|
||||||
|
"base64",
|
||||||
|
"hex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "asn1-rs"
|
||||||
|
version = "0.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "22ad1373757efa0f70ec53939aabc7152e1591cb485208052993070ac8d2429d"
|
||||||
|
dependencies = [
|
||||||
|
"asn1-rs-derive",
|
||||||
|
"asn1-rs-impl",
|
||||||
|
"displaydoc",
|
||||||
|
"nom",
|
||||||
|
"num-traits",
|
||||||
|
"rusticata-macros",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "asn1-rs-derive"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7378575ff571966e99a744addeff0bff98b8ada0dedf1956d59e634db95eaac1"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"synstructure",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "asn1-rs-impl"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.22.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "displaydoc"
|
||||||
|
version = "0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hex"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "minimal-lexical"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nom"
|
||||||
|
version = "7.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
"minimal-lexical",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.79"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.35"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rusticata-macros"
|
||||||
|
version = "4.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632"
|
||||||
|
dependencies = [
|
||||||
|
"nom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.55"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "synstructure"
|
||||||
|
version = "0.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "1.0.58"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "1.0.58"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
11
__crypto/asn1-der-test/Cargo.toml
Normal file
11
__crypto/asn1-der-test/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
name = "asn1-der-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
asn1-rs = "0.6.1"
|
||||||
|
base64 = "0.22.0"
|
||||||
|
hex = "0.4.3"
|
||||||
91
__crypto/asn1-der-test/src/bin/test1.rs
Normal file
91
__crypto/asn1-der-test/src/bin/test1.rs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use asn1_rs::{
|
||||||
|
BitString, Class, Error, Explicit, Integer,
|
||||||
|
OctetString, Oid, Sequence, TaggedValue, ToDer,
|
||||||
|
};
|
||||||
|
use base64::{Engine, engine::GeneralPurpose};
|
||||||
|
|
||||||
|
const BASE64: GeneralPurpose = base64::engine::general_purpose::STANDARD;
|
||||||
|
|
||||||
|
// -----BEGIN PRIVATE KEY-----
|
||||||
|
// MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDB0n4af3g3zaB67WD+/
|
||||||
|
// Xe+FNOkwvuoDd/YUPh0y5ZfoBlkqG1WGNkZN2/d4EYqrNrahZANiAAR2vgKLjiAd
|
||||||
|
// I6l4EAyxGKwGBJ6pAdYZvNlBi8X9kKlCj6aYi5kSKqUfAMaQAX9+0WPoQ6Cy/gzi
|
||||||
|
// bPPmlPRMa4SdTKgZvvw5nuyNXZQU/wN69Opz/hCqxZHKYx5zSznj4/g=
|
||||||
|
// -----END PRIVATE KEY-----
|
||||||
|
// 0 182: SEQUENCE {
|
||||||
|
// 3 1: INTEGER 0
|
||||||
|
// 6 16: SEQUENCE {
|
||||||
|
// 8 7: OBJECT IDENTIFIER ecPublicKey (1 2 840 10045 2 1)
|
||||||
|
// 17 5: OBJECT IDENTIFIER secp384r1 (1 3 132 0 34)
|
||||||
|
// : }
|
||||||
|
// 24 158: OCTET STRING, encapsulates {
|
||||||
|
// 27 155: SEQUENCE {
|
||||||
|
// 30 1: INTEGER 1
|
||||||
|
// 33 48: OCTET STRING
|
||||||
|
// : 74 9F 86 9F DE 0D F3 68 1E BB 58 3F BF 5D EF 85
|
||||||
|
// : 34 E9 30 BE EA 03 77 F6 14 3E 1D 32 E5 97 E8 06
|
||||||
|
// : 59 2A 1B 55 86 36 46 4D DB F7 78 11 8A AB 36 B6
|
||||||
|
// 83 100: [1] {
|
||||||
|
// 85 98: BIT STRING
|
||||||
|
// : 04 76 BE 02 8B 8E 20 1D 23 A9 78 10 0C B1 18 AC
|
||||||
|
// : 06 04 9E A9 01 D6 19 BC D9 41 8B C5 FD 90 A9 42
|
||||||
|
// : 8F A6 98 8B 99 12 2A A5 1F 00 C6 90 01 7F 7E D1
|
||||||
|
// : 63 E8 43 A0 B2 FE 0C E2 6C F3 E6 94 F4 4C 6B 84
|
||||||
|
// : 9D 4C A8 19 BE FC 39 9E EC 8D 5D 94 14 FF 03 7A
|
||||||
|
// : F4 EA 73 FE 10 AA C5 91 CA 63 1E 73 4B 39 E3 E3
|
||||||
|
// : F8
|
||||||
|
// : }
|
||||||
|
// : }
|
||||||
|
// : }
|
||||||
|
// : }
|
||||||
|
|
||||||
|
const PRIVATE_KEY: &str = "749F869FDE0DF3681EBB583FBF5DEF8534E930BEEA0377F6143E1D32E597E806592A1B558636464DDBF778118AAB36B6";
|
||||||
|
const PUBLIC_KEY: &str = "0476BE028B8E201D23A978100CB118AC06049EA901D619BCD9418BC5FD90A9428FA6988B99122AA51F00C690017F7ED16\
|
||||||
|
3E843A0B2FE0CE26CF3E694F44C6B849D4CA819BEFC399EEC8D5D9414FF037AF4EA73FE10AAC591CA631E734B39E3E3F8";
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let ec_public_key = Oid::from_str("1.2.840.10045.2.1").unwrap();
|
||||||
|
let secp_384_r1 = Oid::from_str("1.3.132.0.34").unwrap();
|
||||||
|
|
||||||
|
let private_key_oid_seq = {
|
||||||
|
let mut private_key_oid = Vec::new();
|
||||||
|
ec_public_key.write_der(&mut private_key_oid).unwrap();
|
||||||
|
secp_384_r1.write_der(&mut private_key_oid).unwrap();
|
||||||
|
Sequence::new(private_key_oid.into())
|
||||||
|
};
|
||||||
|
|
||||||
|
let private_body_seq = {
|
||||||
|
let private_key = hex::decode(PRIVATE_KEY).unwrap();
|
||||||
|
let public_key = hex::decode(PUBLIC_KEY).unwrap();
|
||||||
|
|
||||||
|
let integer_1 = Integer::from_i8(1);
|
||||||
|
let private_key_oct = OctetString::new(&private_key);
|
||||||
|
|
||||||
|
let mut private_body = Vec::new();
|
||||||
|
integer_1.write_der(&mut private_body).unwrap();
|
||||||
|
private_key_oct.write_der(&mut private_body).unwrap();
|
||||||
|
|
||||||
|
type TaggedValueContextSpecific<'a> = TaggedValue<BitString<'a>, Error, Explicit, { Class::CONTEXT_SPECIFIC }, 1>;
|
||||||
|
let public_key_bit = BitString::new(0, &public_key);
|
||||||
|
let public_key_tag = TaggedValueContextSpecific::explicit(public_key_bit);
|
||||||
|
public_key_tag.write_der(&mut private_body).unwrap();
|
||||||
|
|
||||||
|
Sequence::new(private_body.into())
|
||||||
|
};
|
||||||
|
let private_body = private_body_seq.to_der_vec().unwrap();
|
||||||
|
let private_body_oct = OctetString::new(&private_body);
|
||||||
|
|
||||||
|
let private_key_info_seq = {
|
||||||
|
let mut private_key_info = Vec::new();
|
||||||
|
let integer_0 = Integer::from_i8(0);
|
||||||
|
integer_0.write_der(&mut private_key_info).unwrap();
|
||||||
|
private_key_oid_seq.write_der(&mut private_key_info).unwrap();
|
||||||
|
private_body_oct.write_der(&mut private_key_info).unwrap();
|
||||||
|
Sequence::new(private_key_info.into())
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("BASED64:\n{}", BASE64.encode(private_key_info_seq.to_der_vec().unwrap()));
|
||||||
|
println!("HEX:\n{}", hex::encode(private_key_info_seq.to_der_vec().unwrap()));
|
||||||
|
}
|
||||||
52
__crypto/asn1-der-test/src/bin/test2.rs
Normal file
52
__crypto/asn1-der-test/src/bin/test2.rs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
use asn1_rs::{BitString, Class, Error, Explicit, Integer, OctetString, Oid, ParseResult, Sequence, TaggedValue};
|
||||||
|
use asn1_rs::FromDer;
|
||||||
|
use base64::Engine;
|
||||||
|
use base64::engine::GeneralPurpose;
|
||||||
|
|
||||||
|
const BASE64: GeneralPurpose = base64::engine::general_purpose::STANDARD;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let private_key = "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgakRmuDPA8pr1kqmY\
|
||||||
|
PxjoMJSJzMeWllw0qbKWzrbEfzehRANCAAQs2XCluo7NF7Y0tL6Pp2GWz2fw5llF\
|
||||||
|
dRvIpq0j8kVQjNOIYZqlBG6OOMQql3U95HsJJY0YzkoXEcdcJmoIV0zn";
|
||||||
|
|
||||||
|
let private_key_der = BASE64.decode(private_key).unwrap();
|
||||||
|
|
||||||
|
let r: ParseResult<()> = Sequence::from_der_and_then(&private_key_der, |i| {
|
||||||
|
let (i, i0) = Integer::from_der(i)?;
|
||||||
|
println!("INTEGER0: {}", i0.as_i8().unwrap());
|
||||||
|
let r: ParseResult<()> = Sequence::from_der_and_then(i, |i| {
|
||||||
|
let (i, oid1) = Oid::from_der(i)?;
|
||||||
|
let (i, oid2) = Oid::from_der(i)?;
|
||||||
|
|
||||||
|
println!("OID1: {}", oid1);
|
||||||
|
println!("OID2: {}", oid2);
|
||||||
|
Ok((i, ()))
|
||||||
|
});
|
||||||
|
|
||||||
|
let (i, _) = r.unwrap();
|
||||||
|
|
||||||
|
let (i, octet) = OctetString::from_der(i).unwrap();
|
||||||
|
let octet = octet.as_ref();
|
||||||
|
|
||||||
|
let r: ParseResult<()> = Sequence::from_der_and_then(octet, |i| {
|
||||||
|
let (i, i1) = Integer::from_der(i).unwrap();
|
||||||
|
println!("INTEGER1: {}", i1.as_i8().unwrap());
|
||||||
|
let (i, oct) = OctetString::from_der(i)?;
|
||||||
|
println!("PRIVATE KEY: {}", hex::encode(oct.as_ref()));
|
||||||
|
|
||||||
|
type TaggedValueContextSpecific<'a> = TaggedValue<BitString<'a>, Error, Explicit, { Class::CONTEXT_SPECIFIC }, 1>;
|
||||||
|
let tagged_value = TaggedValueContextSpecific::from_der(i);
|
||||||
|
let _ = tagged_value.map(|(_i, tagged_value)| {
|
||||||
|
println!("Tagged value [{}]", tagged_value.tag().0);
|
||||||
|
let tagged_value_inner = tagged_value.into_inner();
|
||||||
|
println!("Tagged value: {}, unused: {}", hex::encode(tagged_value_inner.as_ref()), tagged_value_inner.unused_bits);
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok((i, ()))
|
||||||
|
});
|
||||||
|
r.unwrap();
|
||||||
|
Ok((i, ()))
|
||||||
|
});
|
||||||
|
r.unwrap();
|
||||||
|
}
|
||||||
284
__crypto/bc1-btc-address/Cargo.lock
generated
Normal file
284
__crypto/bc1-btc-address/Cargo.lock
generated
Normal file
@@ -0,0 +1,284 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayvec"
|
||||||
|
version = "0.7.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base58ck"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f"
|
||||||
|
dependencies = [
|
||||||
|
"bitcoin-internals",
|
||||||
|
"bitcoin_hashes",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bc1-btc-address"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"bitcoin",
|
||||||
|
"hex",
|
||||||
|
"rand",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bech32"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitcoin"
|
||||||
|
version = "0.32.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ad8929a18b8e33ea6b3c09297b687baaa71fb1b97353243a3f1029fad5c59c5b"
|
||||||
|
dependencies = [
|
||||||
|
"base58ck",
|
||||||
|
"bech32",
|
||||||
|
"bitcoin-internals",
|
||||||
|
"bitcoin-io",
|
||||||
|
"bitcoin-units",
|
||||||
|
"bitcoin_hashes",
|
||||||
|
"hex-conservative",
|
||||||
|
"hex_lit",
|
||||||
|
"secp256k1",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitcoin-internals"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitcoin-io"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b47c4ab7a93edb0c7198c5535ed9b52b63095f4e9b45279c6736cec4b856baf"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitcoin-units"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2"
|
||||||
|
dependencies = [
|
||||||
|
"bitcoin-internals",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitcoin_hashes"
|
||||||
|
version = "0.14.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16"
|
||||||
|
dependencies = [
|
||||||
|
"bitcoin-io",
|
||||||
|
"hex-conservative",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.2.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc"
|
||||||
|
dependencies = [
|
||||||
|
"shlex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"r-efi",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hex"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hex-conservative"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd"
|
||||||
|
dependencies = [
|
||||||
|
"arrayvec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hex_lit"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.174"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.95"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "r-efi"
|
||||||
|
version = "5.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
|
||||||
|
dependencies = [
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "secp256k1"
|
||||||
|
version = "0.29.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113"
|
||||||
|
dependencies = [
|
||||||
|
"bitcoin_hashes",
|
||||||
|
"secp256k1-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "secp256k1-sys"
|
||||||
|
version = "0.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d4387882333d3aa8cb20530a17c69a3752e97837832f34f6dccc760e715001d9"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shlex"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.104"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.14.2+wasi-0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
|
||||||
|
dependencies = [
|
||||||
|
"wit-bindgen-rt",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen-rt"
|
||||||
|
version = "0.39.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy"
|
||||||
|
version = "0.8.26"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy-derive"
|
||||||
|
version = "0.8.26"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
9
__crypto/bc1-btc-address/Cargo.toml
Normal file
9
__crypto/bc1-btc-address/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "bc1-btc-address"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bitcoin = "0.32.6"
|
||||||
|
hex = "0.4.3"
|
||||||
|
rand = "0.9.1"
|
||||||
29
__crypto/bc1-btc-address/src/main.rs
Normal file
29
__crypto/bc1-btc-address/src/main.rs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
use bitcoin::key::Secp256k1;
|
||||||
|
use bitcoin::{Address, CompressedPublicKey, Network, PrivateKey};
|
||||||
|
use rand::RngCore;
|
||||||
|
|
||||||
|
// generate btc address:
|
||||||
|
// https://coinb.in/#newSegWit
|
||||||
|
fn main() {
|
||||||
|
let secp = Secp256k1::new();
|
||||||
|
let mut sk_bytes = [0u8; 32];
|
||||||
|
rand::rng().fill_bytes(&mut sk_bytes);
|
||||||
|
let secret_key = PrivateKey::from_slice(&sk_bytes, Network::Bitcoin).unwrap();
|
||||||
|
|
||||||
|
// let secret_key = PrivateKey::from_wif("L2HajtedHgDT16o3Er8L8tyRrPNbXkeBK69vhGi7K9eK4Yg3dJuj").unwrap();
|
||||||
|
|
||||||
|
let public_key = secret_key.public_key(&secp);
|
||||||
|
let compress_public_key = CompressedPublicKey::try_from(public_key).unwrap();
|
||||||
|
|
||||||
|
// 构造 P2WPKH 地址 (bc1 开头)
|
||||||
|
let address = Address::p2wpkh(&compress_public_key, Network::Bitcoin);
|
||||||
|
let address = address.to_string();
|
||||||
|
|
||||||
|
println!("Private Key (WIF): {}", secret_key.to_wif());
|
||||||
|
println!("Public Key: {}", public_key);
|
||||||
|
println!(
|
||||||
|
"Public Key: {}",
|
||||||
|
hex::encode(&public_key.inner.serialize_uncompressed())
|
||||||
|
);
|
||||||
|
println!("SegWit Address (bc1): {}", address);
|
||||||
|
}
|
||||||
31
__crypto/crypto2-demo/Cargo.lock
generated
Normal file
31
__crypto/crypto2-demo/Cargo.lock
generated
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto2"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "git+https://github.com/shadowsocks/crypto2#dbfd3bb4751abd9945370dee25350765039d050a"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto2-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"crypto2",
|
||||||
|
"hex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hex"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
10
__crypto/crypto2-demo/Cargo.toml
Normal file
10
__crypto/crypto2-demo/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "crypto2-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
crypto2 = { version = "0.2.0", git = "https://github.com/shadowsocks/crypto2" }
|
||||||
|
hex = "0.4.3"
|
||||||
24
__crypto/crypto2-demo/src/main.rs
Normal file
24
__crypto/crypto2-demo/src/main.rs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
use crypto2::blockcipher::Aes128;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let key = [
|
||||||
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
|
||||||
|
0x0f,
|
||||||
|
];
|
||||||
|
let plaintext = [
|
||||||
|
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
|
||||||
|
0xff,
|
||||||
|
];
|
||||||
|
|
||||||
|
let cipher = Aes128::new(&key);
|
||||||
|
|
||||||
|
let mut ciphertext = plaintext.clone();
|
||||||
|
cipher.encrypt(&mut ciphertext);
|
||||||
|
|
||||||
|
let mut cleartext = ciphertext.clone();
|
||||||
|
cipher.decrypt(&mut cleartext);
|
||||||
|
|
||||||
|
println!("plaintext : {:?}", &plaintext[..]);
|
||||||
|
println!("ciphertext: {:?}", &ciphertext[..]);
|
||||||
|
println!("cleartext : {:?}", &cleartext[..]);
|
||||||
|
}
|
||||||
9
__crypto/curve25519/Cargo.lock
generated
9
__crypto/curve25519/Cargo.lock
generated
@@ -1,5 +1,13 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bech32"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "block-buffer"
|
name = "block-buffer"
|
||||||
version = "0.9.0"
|
version = "0.9.0"
|
||||||
@@ -37,6 +45,7 @@ checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634"
|
|||||||
name = "curve25519"
|
name = "curve25519"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bech32",
|
||||||
"curve25519-dalek",
|
"curve25519-dalek",
|
||||||
"ed25519-dalek",
|
"ed25519-dalek",
|
||||||
"hex",
|
"hex",
|
||||||
|
|||||||
@@ -12,3 +12,4 @@ rand = "0.7.3"
|
|||||||
x25519-dalek = "1.1.0"
|
x25519-dalek = "1.1.0"
|
||||||
ed25519-dalek = "1.0.1"
|
ed25519-dalek = "1.0.1"
|
||||||
curve25519-dalek = "3.0.0"
|
curve25519-dalek = "3.0.0"
|
||||||
|
bech32 = "0.9.1"
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
|
use std::convert::TryInto;
|
||||||
|
|
||||||
|
use bech32::{ToBase32, Variant};
|
||||||
|
use ed25519_dalek::{Keypair, PublicKey as EdPublicKey, Signature, Signer, Verifier};
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use ed25519_dalek::{ Keypair, Signer, Verifier };
|
|
||||||
use x25519_dalek::{EphemeralSecret, PublicKey};
|
use x25519_dalek::{EphemeralSecret, PublicKey};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -15,6 +18,7 @@ fn main() {
|
|||||||
println!("Verify result: {:?}", public_key.verify(message, &signature));
|
println!("Verify result: {:?}", public_key.verify(message, &signature));
|
||||||
|
|
||||||
// key exchange
|
// key exchange
|
||||||
|
println!("{}", "-".repeat(88));
|
||||||
let alice_secret = EphemeralSecret::new(OsRng);
|
let alice_secret = EphemeralSecret::new(OsRng);
|
||||||
let alice_public = PublicKey::from(&alice_secret);
|
let alice_public = PublicKey::from(&alice_secret);
|
||||||
let bob_secret = EphemeralSecret::new(OsRng);
|
let bob_secret = EphemeralSecret::new(OsRng);
|
||||||
@@ -23,6 +27,40 @@ fn main() {
|
|||||||
let alice_shared_secret = alice_secret.diffie_hellman(&bob_public);
|
let alice_shared_secret = alice_secret.diffie_hellman(&bob_public);
|
||||||
let bob_shared_secret = bob_secret.diffie_hellman(&alice_public);
|
let bob_shared_secret = bob_secret.diffie_hellman(&alice_public);
|
||||||
|
|
||||||
|
println!("Alice public key : {}", hex::encode(alice_public.as_bytes()));
|
||||||
|
println!("Bob public key : {}", hex::encode(bob_public.as_bytes()));
|
||||||
|
|
||||||
println!("Alice shared secret: {}", hex::encode(alice_shared_secret.as_bytes()));
|
println!("Alice shared secret: {}", hex::encode(alice_shared_secret.as_bytes()));
|
||||||
println!("Bob shared secret: {}", hex::encode(bob_shared_secret.as_bytes()));
|
println!("Bob shared secret: {}", hex::encode(bob_shared_secret.as_bytes()));
|
||||||
|
|
||||||
|
println!("{}", "-".repeat(88));
|
||||||
|
let public_key_bytes = hex::decode("7FEBAAB0D80CED24730B613F3D86924560EBCF13A838DEBC065F63C69C24C61E").unwrap();
|
||||||
|
let public_key_bytes: [u8; 32] = public_key_bytes.try_into().unwrap();
|
||||||
|
let public_key_card = PublicKey::from(public_key_bytes);
|
||||||
|
println!("Public key card: {}", hex::encode(public_key_card.as_bytes()));
|
||||||
|
let age_addr = bech32::encode(
|
||||||
|
"age",
|
||||||
|
public_key_card.as_bytes().to_base32(),
|
||||||
|
Variant::Bech32,
|
||||||
|
).unwrap();
|
||||||
|
println!("Public key card as age address: {}", age_addr);
|
||||||
|
|
||||||
|
let new_secret = EphemeralSecret::new(OsRng);
|
||||||
|
let new_public = PublicKey::from(&new_secret);
|
||||||
|
println!("New public key: {}", hex::encode(new_public.as_bytes()));
|
||||||
|
let new_card_shared_secret = new_secret.diffie_hellman(&public_key_card);
|
||||||
|
println!("New&card shared secret: {}", hex::encode(new_card_shared_secret.as_bytes()));
|
||||||
|
|
||||||
|
println!("{}", "-".repeat(88));
|
||||||
|
// $ cargo r -- pgp-card-sign -2 1dc91001cb69b0dbfab0347d684d7551227484f57a5ac414680414b855051159 --algo eddsa
|
||||||
|
// [OK ] User sign pin verify success!
|
||||||
|
// [OK ] SHA256 signature HEX: 4b2355918b92ca8e5490a30775aa4603a76efe344e3eecfd888b10018a5cb86d3d7095c298b34b39c4e1d46841098dd2514101a9eba5b7a271cf9b5c9d078306
|
||||||
|
let public_key_bytes = hex::decode("d57a081448c6d3d6076b1cca0216f319e45cc2ad986541caf0d3d62f5b318263").unwrap();
|
||||||
|
let public_key_card = EdPublicKey::from_bytes(&public_key_bytes).unwrap();
|
||||||
|
let message = hex::decode("1dc91001cb69b0dbfab0347d684d7551227484f57a5ac414680414b855051159").unwrap();
|
||||||
|
let signature = hex::decode("4b2355918b92ca8e5490a30775aa4603a76efe344e3eecfd888b10018a5cb86d3d7095c298b34b39c4e1d46841098dd2514101a9eba5b7a271cf9b5c9d078306").unwrap();
|
||||||
|
let signature_bytes: [u8; 64] = signature.try_into().unwrap();
|
||||||
|
let signature = Signature::new(signature_bytes);
|
||||||
|
let verify_result = public_key_card.verify(&message, &signature);
|
||||||
|
println!("Verify result: {:?}", verify_result);
|
||||||
}
|
}
|
||||||
|
|||||||
158
__crypto/efficient_sm2/Cargo.lock
generated
Normal file
158
__crypto/efficient_sm2/Cargo.lock
generated
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "efficient-sm2"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1eb543143510430fc814e04178d42bbbfaee821d6546196a87a527bd7ccd6bd6"
|
||||||
|
dependencies = [
|
||||||
|
"libsm",
|
||||||
|
"rand",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "efficient_sm2"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"efficient-sm2",
|
||||||
|
"rand",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.2.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lazy_static"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.137"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libsm"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "47aefac398c4d7ed78ea6b74bc692ebe27d3da99ca6deffa76cabf05d5864c4a"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
"lazy_static",
|
||||||
|
"num-bigint",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
"rand",
|
||||||
|
"yasna",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-bigint"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"num-integer",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-integer"
|
||||||
|
version = "0.1.45"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yasna"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e262a29d0e61ccf2b6190d7050d4b237535fc76ce4c1210d9caa316f71dffa75"
|
||||||
|
dependencies = [
|
||||||
|
"num-bigint",
|
||||||
|
]
|
||||||
11
__crypto/efficient_sm2/Cargo.toml
Normal file
11
__crypto/efficient_sm2/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
name = "efficient_sm2"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rand = "0.8.5"
|
||||||
|
efficient-sm2 = "0.1.5"
|
||||||
|
|
||||||
17
__crypto/efficient_sm2/src/main.rs
Normal file
17
__crypto/efficient_sm2/src/main.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
use rand::RngCore;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let test_word = b"hello world";
|
||||||
|
|
||||||
|
let mut private_key = [0; 32];
|
||||||
|
rand::thread_rng().fill_bytes(&mut private_key);
|
||||||
|
|
||||||
|
let key_pair = efficient_sm2::KeyPair::new(&private_key).unwrap();
|
||||||
|
|
||||||
|
// signing in sm2
|
||||||
|
let sig = key_pair.sign(test_word).unwrap();
|
||||||
|
|
||||||
|
// verification sm2 signature
|
||||||
|
sig.verify(&key_pair.public_key(), test_word).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
317
__crypto/eth-address/Cargo.lock
generated
Normal file
317
__crypto/eth-address/Cargo.lock
generated
Normal file
@@ -0,0 +1,317 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayvec"
|
||||||
|
version = "0.7.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitcoin-io"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b47c4ab7a93edb0c7198c5535ed9b52b63095f4e9b45279c6736cec4b856baf"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitcoin_hashes"
|
||||||
|
version = "0.14.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16"
|
||||||
|
dependencies = [
|
||||||
|
"bitcoin-io",
|
||||||
|
"hex-conservative",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.2.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc"
|
||||||
|
dependencies = [
|
||||||
|
"shlex",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crunchy"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "eth-address"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"hex",
|
||||||
|
"keccak-hash",
|
||||||
|
"num_cpus",
|
||||||
|
"rand",
|
||||||
|
"secp256k1",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fixed-hash"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534"
|
||||||
|
dependencies = [
|
||||||
|
"static_assertions",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"r-efi",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hermit-abi"
|
||||||
|
version = "0.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hex"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hex-conservative"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd"
|
||||||
|
dependencies = [
|
||||||
|
"arrayvec",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "keccak-hash"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3e1b8590eb6148af2ea2d75f38e7d29f5ca970d5a4df456b3ef19b8b415d0264"
|
||||||
|
dependencies = [
|
||||||
|
"primitive-types",
|
||||||
|
"tiny-keccak",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.174"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num_cpus"
|
||||||
|
version = "1.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b"
|
||||||
|
dependencies = [
|
||||||
|
"hermit-abi",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "primitive-types"
|
||||||
|
version = "0.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d15600a7d856470b7d278b3fe0e311fe28c2526348549f8ef2ff7db3299c87f5"
|
||||||
|
dependencies = [
|
||||||
|
"fixed-hash",
|
||||||
|
"uint",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.95"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "r-efi"
|
||||||
|
version = "5.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
|
||||||
|
dependencies = [
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "secp256k1"
|
||||||
|
version = "0.31.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2c3c81b43dc2d8877c216a3fccf76677ee1ebccd429566d3e67447290d0c42b2"
|
||||||
|
dependencies = [
|
||||||
|
"bitcoin_hashes",
|
||||||
|
"rand",
|
||||||
|
"secp256k1-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "secp256k1-sys"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dcb913707158fadaf0d8702c2db0e857de66eb003ccfdda5924b5f5ac98efb38"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shlex"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "static_assertions"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.104"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tiny-keccak"
|
||||||
|
version = "2.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
|
||||||
|
dependencies = [
|
||||||
|
"crunchy",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uint"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "909988d098b2f738727b161a106cfc7cab00c539c2687a8836f8e565976fb53e"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
"crunchy",
|
||||||
|
"hex",
|
||||||
|
"static_assertions",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.14.2+wasi-0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
|
||||||
|
dependencies = [
|
||||||
|
"wit-bindgen-rt",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen-rt"
|
||||||
|
version = "0.39.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy"
|
||||||
|
version = "0.8.26"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy-derive"
|
||||||
|
version = "0.8.26"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
11
__crypto/eth-address/Cargo.toml
Normal file
11
__crypto/eth-address/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
name = "eth-address"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
hex = "0.4.3"
|
||||||
|
keccak-hash = "0.11.0"
|
||||||
|
num_cpus = "1.17.0"
|
||||||
|
rand = "0.9.1"
|
||||||
|
secp256k1 = { version = "0.31.1", features = ["rand"] }
|
||||||
157
__crypto/eth-address/src/main.rs
Normal file
157
__crypto/eth-address/src/main.rs
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
use keccak_hash::keccak_256;
|
||||||
|
use secp256k1::{PublicKey, Secp256k1};
|
||||||
|
use std::{
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
thread,
|
||||||
|
};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args = std::env::args();
|
||||||
|
if args.len() <= 1 {
|
||||||
|
println!("[ERROR] Need at least one argument, e.g. 0xff 0xffff ...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let continue_on_found = std::env::var("CONTINUE_ON_FOUND")
|
||||||
|
.map(|c| c.to_lowercase())
|
||||||
|
.map(|c| c == "1" || c == "true" || c == "yes" || c == "on")
|
||||||
|
.unwrap_or_else(|_| false);
|
||||||
|
|
||||||
|
let prefixes: Vec<String> = args.skip(1).collect();
|
||||||
|
println!("Prefixes: {:?}", prefixes);
|
||||||
|
if continue_on_found {
|
||||||
|
println!("CONTINUE_ON_FOUND is ON");
|
||||||
|
} else {
|
||||||
|
println!("CONTINUE_ON_FOUND is OFF");
|
||||||
|
}
|
||||||
|
let loop_count = std::env::var("LOOP_COUNT")
|
||||||
|
.map(|c| c.parse::<u64>())
|
||||||
|
.unwrap_or_else(|_| Ok(10_000_000_u64))
|
||||||
|
.unwrap_or_else(|_| 10_000_000_u64);
|
||||||
|
println!("LOOP_COUNT={}", loop_count);
|
||||||
|
|
||||||
|
let num_of_vcpus = num_cpus::get();
|
||||||
|
let num_of_phycpus = num_cpus::get_physical();
|
||||||
|
println!(
|
||||||
|
"You have {} vCPUs, from {} phyCPUs",
|
||||||
|
num_of_vcpus, num_of_phycpus
|
||||||
|
);
|
||||||
|
let concurrent_count = std::env::var("CONCURRENT_COUNT")
|
||||||
|
.map(|c| c.parse::<u64>())
|
||||||
|
.unwrap_or_else(|_| Ok(num_of_phycpus as u64))
|
||||||
|
.unwrap_or_else(|_| 1_u64);
|
||||||
|
println!("CONCURRENT_COUNT={}", concurrent_count);
|
||||||
|
|
||||||
|
let stop_flag = Arc::new(Mutex::new(false));
|
||||||
|
let mut handles = vec![];
|
||||||
|
for ind in 0..concurrent_count {
|
||||||
|
println!("- Running task {} of {}", ind, concurrent_count);
|
||||||
|
let the_stop_flag = Arc::clone(&stop_flag);
|
||||||
|
let prefixes = prefixes.clone();
|
||||||
|
let child = thread::spawn(move || {
|
||||||
|
run_one_task(prefixes, continue_on_found, loop_count, ind, the_stop_flag);
|
||||||
|
});
|
||||||
|
handles.push(child);
|
||||||
|
}
|
||||||
|
while let Some(h) = handles.pop() {
|
||||||
|
h.join().unwrap();
|
||||||
|
}
|
||||||
|
println!("Finished!");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_one_task(
|
||||||
|
prefixes: Vec<String>,
|
||||||
|
continue_on_found: bool,
|
||||||
|
loop_count: u64,
|
||||||
|
ind: u64,
|
||||||
|
the_stop_flag: Arc<Mutex<bool>>,
|
||||||
|
) {
|
||||||
|
let secp = Secp256k1::new();
|
||||||
|
|
||||||
|
for i in 0..loop_count {
|
||||||
|
let (secret_key, public_key) = secp.generate_keypair(&mut rand::rng());
|
||||||
|
|
||||||
|
let s = make_eth_address(&public_key);
|
||||||
|
|
||||||
|
if i % 1_000 == 0 {
|
||||||
|
if *the_stop_flag.lock().unwrap() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if i > 0 && i % 100_000 == 0 {
|
||||||
|
println!("> {} - {}", ind, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let lower_s = s.to_ascii_lowercase();
|
||||||
|
if prefixes.iter().any(|p| lower_s.starts_with(p)) {
|
||||||
|
println!(">> {}\n{}", s, hex::encode(secret_key.as_ref()));
|
||||||
|
|
||||||
|
if !continue_on_found {
|
||||||
|
*the_stop_flag.lock().unwrap() = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// reference: https://eips.ethereum.org/EIPS/eip-55
|
||||||
|
fn make_eth_address(public_key: &PublicKey) -> String {
|
||||||
|
let public_key_bytes = public_key.serialize_uncompressed().to_vec();
|
||||||
|
|
||||||
|
let mut output = [0_u8; 32];
|
||||||
|
keccak_256(&public_key_bytes[1..], &mut output);
|
||||||
|
|
||||||
|
let addr_without_prefix_0x = hex::encode(&output[32 - 20..]);
|
||||||
|
let mut addr_keccak_256_output = [0_u8; 32];
|
||||||
|
keccak_256(
|
||||||
|
addr_without_prefix_0x.as_bytes(),
|
||||||
|
&mut addr_keccak_256_output,
|
||||||
|
);
|
||||||
|
let addr_keccak_256_hex = hex::encode(&addr_keccak_256_output);
|
||||||
|
|
||||||
|
let mut addr = String::with_capacity(42);
|
||||||
|
addr.push_str("0x");
|
||||||
|
let addr_keccak_256_chars = addr_keccak_256_hex.chars().collect::<Vec<_>>();
|
||||||
|
let addr_chars = addr_without_prefix_0x.chars().collect::<Vec<_>>();
|
||||||
|
for i in 0..addr_chars.len() {
|
||||||
|
if addr_keccak_256_chars[i] >= '8' {
|
||||||
|
addr.push(addr_chars[i].to_ascii_uppercase());
|
||||||
|
} else {
|
||||||
|
addr.push(addr_chars[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addr
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_make_eth_address() {
|
||||||
|
use secp256k1::{SecretKey};
|
||||||
|
|
||||||
|
for (private_key, eth_address) in [
|
||||||
|
(
|
||||||
|
"961fc1985ceca1e23b169103e041ecfa642ff8690a6ecc59d91f2dba648ab02b",
|
||||||
|
"0x0005119dEE1fD8763fE6ADBbc801484a3728F0db",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"2fa0db47c5939d7d4831d05dcdb329f6e7f7d5ca2c7247a666729aa513ea26bf",
|
||||||
|
"0x23aEf078e0997434Eb47E6d0B3C7770010473456",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"e6a8f02f9d308eca44b8437d6dc1d08101449ecef5851dfe5093bcf0bc21fa5b",
|
||||||
|
"0xef87E9712c412ef7B90804EbaB763FAe24E10123",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"3d541861865959e1e1c303d5c2a90084192415b61ead3fdb778047278011170b",
|
||||||
|
"0x1451449D05A3C232a543A995C2A38c07095f6666",
|
||||||
|
),
|
||||||
|
] {
|
||||||
|
let temp_key = hex::decode(private_key).unwrap();
|
||||||
|
let mut key_32_bytes = [0_u8; 32];
|
||||||
|
for i in 0..32 {
|
||||||
|
key_32_bytes[i] = temp_key[i];
|
||||||
|
}
|
||||||
|
let secp = Secp256k1::new();
|
||||||
|
let secret_key =
|
||||||
|
SecretKey::from_byte_array(key_32_bytes).expect("32 bytes, within curve order");
|
||||||
|
let public_key = PublicKey::from_secret_key(&secp, &secret_key);
|
||||||
|
assert_eq!(eth_address, make_eth_address(&public_key));
|
||||||
|
}
|
||||||
|
}
|
||||||
16
__crypto/highwayhash/Cargo.lock
generated
Normal file
16
__crypto/highwayhash/Cargo.lock
generated
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "highway"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3688f13e7735ae5ca93edc490f6c5885b77d473255bc1fed92b9c805f972bf94"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "highwayhash"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"highway",
|
||||||
|
]
|
||||||
10
__crypto/highwayhash/Cargo.toml
Normal file
10
__crypto/highwayhash/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "highwayhash"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
highway = "0.8.0"
|
||||||
|
|
||||||
5
__crypto/highwayhash/README.md
Normal file
5
__crypto/highwayhash/README.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
|
* https://github.com/nickbabcock/highway-rs
|
||||||
|
* https://github.com/rurban/smhasher
|
||||||
|
|
||||||
12
__crypto/highwayhash/src/main.rs
Normal file
12
__crypto/highwayhash/src/main.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use highway::{HighwayHash, HighwayHasher, Key};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let res = HighwayHasher::default().hash256("hello world".as_bytes());
|
||||||
|
println!("{:x?}", res);
|
||||||
|
let res = HighwayHasher::default().hash256(&[0xff]);
|
||||||
|
println!("{:x?}", res);
|
||||||
|
let mut hasher256 = HighwayHasher::new(Key([1, 2, 3, 4]));
|
||||||
|
hasher256.append(&[0xff]);
|
||||||
|
let res: [u64; 4] = hasher256.finalize256();
|
||||||
|
println!("{:x?}", res);
|
||||||
|
}
|
||||||
1357
__crypto/jose-test/Cargo.lock
generated
Normal file
1357
__crypto/jose-test/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
__crypto/jose-test/Cargo.toml
Normal file
20
__crypto/jose-test/Cargo.toml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
[package]
|
||||||
|
name = "jose-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
aes-gcm-stream = "0.2.3"
|
||||||
|
aes-kw = { version = "0.2.1", features = ["alloc"] }
|
||||||
|
base64 = "0.22.1"
|
||||||
|
biscuit = "0.7.0"
|
||||||
|
#jose-jwe = "0.0.0"
|
||||||
|
jose-jwk = { version = "0.1.2", features = ["rsa"] }
|
||||||
|
josekit = "0.10.0"
|
||||||
|
rand = { version = "0.8.5", features = [] }
|
||||||
|
rsa = "0.9.6"
|
||||||
|
rust_util = "0.6.47"
|
||||||
|
serde = "1.0.214"
|
||||||
|
serde_json = "1.0.132"
|
||||||
|
sha1 = "0.10.6"
|
||||||
|
sha2 = "0.10.8"
|
||||||
241
__crypto/jose-test/src/jose.rs
Normal file
241
__crypto/jose-test/src/jose.rs
Normal file
@@ -0,0 +1,241 @@
|
|||||||
|
use aes_gcm_stream::{Aes256GcmStreamDecryptor, Aes256GcmStreamEncryptor};
|
||||||
|
use aes_kw::Kek;
|
||||||
|
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
|
||||||
|
use base64::Engine;
|
||||||
|
use josekit::jwe;
|
||||||
|
use josekit::jwe::alg::aeskw::AeskwJweAlgorithm;
|
||||||
|
use josekit::jwe::alg::rsaes::RsaesJweAlgorithm;
|
||||||
|
use josekit::jwe::JweHeader;
|
||||||
|
use josekit::jwk::alg::rsa::RsaKeyPair;
|
||||||
|
use josekit::jwk::Jwk;
|
||||||
|
use rand::{random, thread_rng};
|
||||||
|
use rsa::{Oaep, RsaPrivateKey, RsaPublicKey};
|
||||||
|
use rust_util::{opt_result, simple_error, XResult};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json::Value;
|
||||||
|
use sha1::Sha1;
|
||||||
|
|
||||||
|
const LOCAL_KMS_PREFIX: &str = "LKMS:";
|
||||||
|
|
||||||
|
// JWE format:
|
||||||
|
// BASE64URL(UTF8(JWE Protected Header)) || '.' ||
|
||||||
|
// BASE64URL(JWE Encrypted Key) || '.' || BASE64URL(JWE Initialization Vector)
|
||||||
|
// || '.' || BASE64URL(JWE Ciphertext) || '.' || BASE64URL(JWE Authentication Tag).
|
||||||
|
//
|
||||||
|
// RSA JWE Header:
|
||||||
|
// {"enc":"A256GCM","vendor":"local-mini-kms","alg":"RSA-OAEP"}
|
||||||
|
// eyJlbmMiOiJBMjU2R0NNIiwidmVuZG9yIjoibG9jYWwtbWluaS1rbXMiLCJhbGciOiJSU0EtT0FFUCJ9.VQ_R
|
||||||
|
// yGjXqQlUIbRIMgaYRSaX5FMRBzZ6ApfdZ2yAwiG70hjNfR3ss7x4PYqMm6QtITm1O4_fp7I3bY8iUz5Njyth_
|
||||||
|
// Min7Xm2-WsQ6gq9yN58btkUBFm60c7SC5XLaqE1pEtBAz7786bJk6M4NeOtDAOFAmIb2j1EwnS5vweBtmNv7N
|
||||||
|
// UFIgvx806T3WkCFDOkMSJ10_6LSa0z-lIac-s68svsU5WW8CXVKxHAbxaHyX_otu2HxXzDZlF5Goamh5ZJtr0
|
||||||
|
// 0yW_bzDCx3hZ2nMK3Ve7IJ2ZLAMmvhj9LKWkPtoqH0dGHaPHWff5P3rZ4vtKywt_h5b6SYII_mEoJcpByMyGw
|
||||||
|
// TXCtZymDt82Tyv_FesW2721JgyGxnukuOxQRTw4MfGYIO5bldL3uGGI_H4HXlXhM_kp3wuPAZ0vH4Jj2KD6MV
|
||||||
|
// DDTJQaEBQIEF07i7WiNynr57kbahYwextRXYP7LgoUHfFwA5GGGpN-UkuWLlKkYLTmXGrPYnL6Cf9D3euP7nF
|
||||||
|
// ml2oA2hjig-UuYf9A_QSEqNsMxYDuG-rggn3H_iXNl4ooYcxSVOXhTKfoV578MkNwG75BdHN5FeRYIKq0HCTM
|
||||||
|
// lGqqBWmDibPtMd7Uq1JrDd8774lnA8JcZcCMSia4m6WJSbG0kOuJ4NJPOUrYtNEJXgWKU3FQzDB-apLMQdac.
|
||||||
|
// WYJgsdZRLk310KWd.P333-S2VYg.PCfruTdk8vh3a8wcjJCe-g
|
||||||
|
//
|
||||||
|
// RSA-OAEP RSA using Optimal Asymmetric Encryption Padding (OAEP), as defined in RFC 3447 [RFC3447]
|
||||||
|
// A256GCM Advanced Encryption Standard (AES) using 256 bit keys in Galois/Counter Mode, as defined in [FIPS‑197] and [NIST‑800‑38D]
|
||||||
|
//
|
||||||
|
// AES JWE Header:
|
||||||
|
// {"enc":"A256GCM","vendor":"local-mini-kms","version":"5b90f66a1c6a918d","alg":"A256KW"}
|
||||||
|
// eyJlbmMiOiJBMjU2R0NNIiwidmVuZG9yIjoibG9jYWwtbWluaS1rbXMiLCJ2ZXJzaW9uIjoiNWI5MGY2NmExYz
|
||||||
|
// ZhOTE4ZCIsImFsZyI6IkEyNTZLVyJ9.K2_P-b_Gq9wbrssbcS5AmiUwcnNTnnZSe7rBI1SixVrC7TfFK0fruw.
|
||||||
|
// ez3OKjOHAIIYnfM0.wSO3aXo.-vGJwk8JQKhi3voIlAA9gQ
|
||||||
|
//
|
||||||
|
// A256GCM Advanced Encryption Standard (AES) using 256 bit keys in Galois/Counter Mode, as defined in [FIPS‑197] and [NIST‑800‑38D]
|
||||||
|
// A256KW Advanced Encryption Standard (AES) Key Wrap Algorithm using 256 bit keys, as defined in RFC 3394 [RFC3394]
|
||||||
|
|
||||||
|
// JWE Header: {"alg":"dir","enc":"A256GCM"}
|
||||||
|
// Encrypted key (CEK): (blank)
|
||||||
|
// IV: Vlf_WdLm-spHbfJe
|
||||||
|
// Ciphertext: RxMPrw
|
||||||
|
// Authentication Tag: 5VC8Y_qSPdSubbGNGyfn6A
|
||||||
|
//
|
||||||
|
// JWE Header: {"alg":"A256KW","enc":"A256GCM"}
|
||||||
|
// Encrypted key (CEK): 66xZoxFI18zfvLMO6WU1zzqqX1tT8xu_qZzMQyPcfVuajPNkOJUXQA
|
||||||
|
// IV: X5ZL8yaOektXmfny
|
||||||
|
// Ciphertext: brz-Lg
|
||||||
|
// Authentication Tag: xG-EvM-9hrw0XRiuRW7HrA
|
||||||
|
//
|
||||||
|
// https://security.stackexchange.com/questions/80966/what-is-the-point-of-aes-key-wrap-with-json-web-encryption
|
||||||
|
|
||||||
|
const JWE_ENC_A256GCM: &str = "A256GCM";
|
||||||
|
const JWE_ALG_A256KW: &str = "A256KW";
|
||||||
|
const JWE_ALG_RSA_OAEP: &str = "RSA-OAEP";
|
||||||
|
const JWE_DOT: &str = ".";
|
||||||
|
|
||||||
|
pub fn generate_rsa_key_2(bits: u32) -> XResult<RsaPrivateKey> {
|
||||||
|
let mut rng = thread_rng();
|
||||||
|
Ok(RsaPrivateKey::new(&mut rng, bits as usize)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate_rsa_key(bits: u32) -> XResult<RsaKeyPair> {
|
||||||
|
Ok(RsaKeyPair::generate(bits)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize_jwe_rsa_2(payload: &[u8], rsa_public_key: &RsaPublicKey) -> XResult<String> {
|
||||||
|
let header = JweHeader2 {
|
||||||
|
enc: JWE_ENC_A256GCM.to_string(),
|
||||||
|
alg: JWE_ALG_RSA_OAEP.to_string(),
|
||||||
|
vendor: "local-mini-kms".to_string(),
|
||||||
|
version: None,
|
||||||
|
};
|
||||||
|
serialize_jwe_fn(&header, payload, |data_key| -> XResult<Vec<u8>> {
|
||||||
|
let mut r = thread_rng();
|
||||||
|
Ok(opt_result!(rsa_public_key.encrypt(&mut r, Oaep::new::<Sha1>(), data_key), "Wrap key failed: {}"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize_jwe_rsa(payload: &[u8], jwk: &Jwk) -> XResult<String> {
|
||||||
|
let mut header = JweHeader::new();
|
||||||
|
header.set_content_encryption(JWE_ENC_A256GCM);
|
||||||
|
header.set_claim("vendor", Some(Value::String("local-mini-kms".to_string())))?;
|
||||||
|
let encrypter = RsaesJweAlgorithm::RsaOaep.encrypter_from_jwk(jwk)?;
|
||||||
|
Ok(format!("{}{}", LOCAL_KMS_PREFIX, jwe::serialize_compact(payload, &header, &encrypter)?))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deserialize_jwe_rsa_2(jwe: &str, rsa: &RsaPrivateKey) -> XResult<(Vec<u8>, JweHeader2)> {
|
||||||
|
deserialize_jwe_fn(jwe, |alg, key_wrap| -> XResult<Vec<u8>> {
|
||||||
|
if alg != JWE_ALG_RSA_OAEP {
|
||||||
|
return simple_error!("Invalid JWE header alg: {}", alg);
|
||||||
|
}
|
||||||
|
Ok(opt_result!(rsa.decrypt(Oaep::new::<Sha1>(), &key_wrap), "Unwrap key failed: {}"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deserialize_jwe_rsa(jwe: &str, jwk: &Jwk) -> XResult<(Vec<u8>, JweHeader)> {
|
||||||
|
let decrypter = RsaesJweAlgorithm::RsaOaep.decrypter_from_jwk(jwk)?;
|
||||||
|
Ok(jwe::deserialize_compact(&get_jwe(jwe), &decrypter)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct JweHeader2 {
|
||||||
|
pub enc: String,
|
||||||
|
pub alg: String,
|
||||||
|
pub vendor: String,
|
||||||
|
pub version: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize_jwe_aes_2(payload: &[u8], key: [u8; 32]) -> XResult<String> {
|
||||||
|
let header = JweHeader2 {
|
||||||
|
enc: JWE_ENC_A256GCM.to_string(),
|
||||||
|
alg: JWE_ALG_A256KW.to_string(),
|
||||||
|
vendor: "local-mini-kms".to_string(),
|
||||||
|
version: None,
|
||||||
|
};
|
||||||
|
serialize_jwe_fn(&header, payload, |data_key| -> XResult<Vec<u8>> {
|
||||||
|
let kek = Kek::from(key);
|
||||||
|
Ok(opt_result!(kek.wrap_vec(&data_key[..]), "Wrap key failed: {}"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize_jwe_aes(payload: &[u8], key: &[u8]) -> XResult<String> {
|
||||||
|
let mut header = JweHeader::new();
|
||||||
|
header.set_content_encryption(JWE_ENC_A256GCM);
|
||||||
|
header.set_claim("vendor", Some(Value::String("local-mini-kms".to_string())))?;
|
||||||
|
// header.set_claim("version", Some(Value::String(get_master_key_checksum(key))))?;
|
||||||
|
let encrypter = AeskwJweAlgorithm::A256kw.encrypter_from_bytes(key)?;
|
||||||
|
Ok(format!("{}{}", LOCAL_KMS_PREFIX, jwe::serialize_compact(payload, &header, &encrypter)?))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deserialize_jwe_aes_2(jwe: &str, key: [u8; 32]) -> XResult<(Vec<u8>, JweHeader2)> {
|
||||||
|
deserialize_jwe_fn(jwe, |alg, key_wrap| -> XResult<Vec<u8>> {
|
||||||
|
if alg != JWE_ALG_A256KW {
|
||||||
|
return simple_error!("Invalid JWE header alg: {}", alg);
|
||||||
|
}
|
||||||
|
let kek = Kek::from(key);
|
||||||
|
Ok(opt_result!(kek.unwrap_vec(&key_wrap), "Unwrap key failed: {}"))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deserialize_jwe_aes(jwe: &str, key: &[u8]) -> XResult<(Vec<u8>, JweHeader)> {
|
||||||
|
let decrypter = AeskwJweAlgorithm::A256kw.decrypter_from_bytes(key)?;
|
||||||
|
Ok(jwe::deserialize_compact(&get_jwe(jwe), &decrypter)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn serialize_jwe_fn<F>(header: &JweHeader2, payload: &[u8], key_wrap_fn: F) -> XResult<String>
|
||||||
|
where
|
||||||
|
F: Fn(&[u8]) -> XResult<Vec<u8>>,
|
||||||
|
{
|
||||||
|
let header_str = opt_result!(serde_json::to_string(&header), "Invalid JWE header: {}");
|
||||||
|
let header_b64 = URL_SAFE_NO_PAD.encode(header_str.as_bytes());
|
||||||
|
|
||||||
|
let data_key: [u8; 32] = random();
|
||||||
|
let iv: [u8; 12] = random();
|
||||||
|
let mut encryptor = Aes256GcmStreamEncryptor::new(data_key, &iv);
|
||||||
|
encryptor.init_adata(header_b64.as_bytes());
|
||||||
|
let mut ciphertext = encryptor.update(payload);
|
||||||
|
let (ciphertext_final, tag) = encryptor.finalize();
|
||||||
|
ciphertext.extend_from_slice(&ciphertext_final);
|
||||||
|
|
||||||
|
let cek = key_wrap_fn(&data_key)?;
|
||||||
|
|
||||||
|
Ok(format!(
|
||||||
|
"{}.{}.{}.{}.{}",
|
||||||
|
header_b64,
|
||||||
|
URL_SAFE_NO_PAD.encode(&cek),
|
||||||
|
URL_SAFE_NO_PAD.encode(&iv),
|
||||||
|
URL_SAFE_NO_PAD.encode(&ciphertext),
|
||||||
|
URL_SAFE_NO_PAD.encode(&tag)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_jwe_fn<F>(jwe: &str, key_unwrap_fn: F) -> XResult<(Vec<u8>, JweHeader2)>
|
||||||
|
where
|
||||||
|
F: Fn(&str, &[u8]) -> XResult<Vec<u8>>,
|
||||||
|
{
|
||||||
|
let jwe_parts = jwe.split(JWE_DOT).collect::<Vec<&str>>();
|
||||||
|
if jwe_parts.len() != 5 {
|
||||||
|
return simple_error!("Invalid JWE: {}", jwe);
|
||||||
|
}
|
||||||
|
let header_bytes = opt_result!(decode_url_safe_no_pad(jwe_parts[0]), "Invalid JWE header: {}, JWE: {}", jwe);
|
||||||
|
let header: JweHeader2 = opt_result!(serde_json::from_slice(&header_bytes), "Invalid JWE header: {}, JWE: {}", jwe);
|
||||||
|
if header.enc != JWE_ENC_A256GCM {
|
||||||
|
return simple_error!("Invalid JWE header enc: {}", header.enc);
|
||||||
|
}
|
||||||
|
|
||||||
|
let cek = opt_result!(decode_url_safe_no_pad(jwe_parts[1]), "Invalid JWE CEK: {}, JWE: {}", jwe);
|
||||||
|
let iv = opt_result!(decode_url_safe_no_pad(jwe_parts[2]), "Invalid JWE IV: {}, JWE: {}", jwe);
|
||||||
|
let ciphertext = opt_result!(decode_url_safe_no_pad(jwe_parts[3]), "Invalid JWE ciphertext: {}, JWE: {}", jwe);
|
||||||
|
let tag = opt_result!(decode_url_safe_no_pad(jwe_parts[4]), "Invalid JWE tag: {}, JWE: {}", jwe);
|
||||||
|
|
||||||
|
let data_key = key_unwrap_fn(&header.alg, &cek)?;
|
||||||
|
let data_key_b32 = opt_result!(to_bytes32(&data_key), "Invalid JWE CEK: {}, JWE: {}", jwe);
|
||||||
|
|
||||||
|
let mut decryptor = Aes256GcmStreamDecryptor::new(data_key_b32, &iv);
|
||||||
|
decryptor.init_adata(jwe_parts[0].as_bytes());
|
||||||
|
let mut plaintext = decryptor.update(&ciphertext);
|
||||||
|
let plaintext_2 = decryptor.update(&tag);
|
||||||
|
let plaintext_final = opt_result!(decryptor.finalize(), "Invalid JWE: {}, JWE: {}", jwe);
|
||||||
|
plaintext.extend_from_slice(&plaintext_2);
|
||||||
|
plaintext.extend_from_slice(&plaintext_final);
|
||||||
|
Ok((plaintext, header))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn decode_url_safe_no_pad(s: &str) -> XResult<Vec<u8>> {
|
||||||
|
Ok(URL_SAFE_NO_PAD.decode(s.as_bytes())?)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn to_bytes32(bytes: &[u8]) -> XResult<[u8; 32]> {
|
||||||
|
if bytes.len() != 32 {
|
||||||
|
return simple_error!("Not valid 32 bytes");
|
||||||
|
}
|
||||||
|
let mut ret = [0; 32];
|
||||||
|
for i in 0..32 {
|
||||||
|
ret[i] = bytes[i];
|
||||||
|
}
|
||||||
|
Ok(ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn get_jwe(jwe: &str) -> String {
|
||||||
|
if jwe.starts_with(LOCAL_KMS_PREFIX) {
|
||||||
|
jwe.chars().skip(LOCAL_KMS_PREFIX.len()).collect()
|
||||||
|
} else {
|
||||||
|
jwe.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
92
__crypto/jose-test/src/main.rs
Normal file
92
__crypto/jose-test/src/main.rs
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
mod jose;
|
||||||
|
|
||||||
|
use crate::jose::{deserialize_jwe_aes, deserialize_jwe_aes_2, deserialize_jwe_rsa_2, serialize_jwe_aes_2, serialize_jwe_rsa, serialize_jwe_rsa_2};
|
||||||
|
use base64::engine::general_purpose::STANDARD;
|
||||||
|
use base64::Engine;
|
||||||
|
use jose_jwk::{Jwk, Key, Rsa};
|
||||||
|
use rand::random;
|
||||||
|
use rand::rngs::ThreadRng;
|
||||||
|
use rsa::traits::{PrivateKeyParts, PublicKeyParts};
|
||||||
|
use rsa::{Oaep, Pkcs1v15Encrypt};
|
||||||
|
use sha2::Sha256;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let key: [u8; 32] = random();
|
||||||
|
let payload = b"hello world";
|
||||||
|
|
||||||
|
let e = serialize_jwe_aes_2(payload, key).unwrap();
|
||||||
|
println!("{}", e);
|
||||||
|
|
||||||
|
let (d, h) = deserialize_jwe_aes(&e, &key).unwrap();
|
||||||
|
println!("{:?}", d);
|
||||||
|
println!("{:?}", h);
|
||||||
|
|
||||||
|
let (d2, h2) = deserialize_jwe_aes_2(&e, key).unwrap();
|
||||||
|
println!("{:?}", d2);
|
||||||
|
println!("{:?}", h2);
|
||||||
|
|
||||||
|
let rsa_key = jose::generate_rsa_key_2(2048).unwrap();
|
||||||
|
let rsa_public_key = rsa_key.as_ref();
|
||||||
|
let public_rsa: Rsa = rsa_public_key.into();
|
||||||
|
// let rsa: Rsa = rsa_key.into();
|
||||||
|
// println!("{:?}", public_rsa);
|
||||||
|
// println!("{:?}", rsa);
|
||||||
|
|
||||||
|
let jwk = Jwk {
|
||||||
|
key: Key::Rsa(public_rsa),
|
||||||
|
prm: Default::default(),
|
||||||
|
};
|
||||||
|
let jwk_str = serde_json::to_string(&jwk).unwrap();
|
||||||
|
println!("{}", &jwk_str);
|
||||||
|
// let rsa: Rsa = serde_json::from_str(&jwk_str).unwrap();
|
||||||
|
let josekitjwk = josekit::jwk::Jwk::from_bytes(jwk_str.as_bytes()).unwrap();
|
||||||
|
let rsa_jwe = serialize_jwe_rsa(b"hello world 001", &josekitjwk).unwrap();
|
||||||
|
// let rsa_key_2: RsaPrivateKey = rsa.try_into().unwrap();
|
||||||
|
println!(">>> {}", rsa_jwe);
|
||||||
|
let rsa_jwe = rsa_jwe.chars().skip(5).collect::<String>();
|
||||||
|
let (dd, hh) = deserialize_jwe_rsa_2(&rsa_jwe, &rsa_key).unwrap();
|
||||||
|
println!("DD: {}", String::from_utf8_lossy(&dd));
|
||||||
|
println!("HH: {:?}", hh);
|
||||||
|
|
||||||
|
println!("-------------------------------------------------------------------------------------");
|
||||||
|
let rsa_jwe2 = serialize_jwe_rsa_2(b"hello world 003", rsa_public_key).unwrap();
|
||||||
|
println!(">>> {}", rsa_jwe2);
|
||||||
|
// let rsa_jwe2 = rsa_jwe2.chars().skip(5).collect::<String>();
|
||||||
|
let (ddd, hhh) = deserialize_jwe_rsa_2(&rsa_jwe2, &rsa_key).unwrap();
|
||||||
|
println!("DDD: {}", String::from_utf8_lossy(&ddd));
|
||||||
|
println!("HHH: {:?}", hhh);
|
||||||
|
|
||||||
|
println!("-------------------------------------------------------------------------------------");
|
||||||
|
main2();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main2() {
|
||||||
|
let rsa_jwk = r##"{
|
||||||
|
"kty":"RSA",
|
||||||
|
"e":"AQAB",
|
||||||
|
"n":"5xyyPQx8Z7AjVf8Mg4xTE6yN8efPHc0lCdO056R2lzaEQeFwVCbOxFCnmly2-HtE_F_Wd3-B0nxOmODIyC4T
|
||||||
|
kLS3hXuflZb-OH73GwYDRmfcvWorACm0hv_a3p8YCuXvZ9aQUPRXwLn1jmAnKJiVRtObZTmmG5TsO-Q-U1DJjKhuP
|
||||||
|
--4co9T434y3U9xGIBYAudQ8tn4QSuVInrO2svg4gb9PExLDBn_46yEiLn-q0TzvO-s2rZ0iCpfB0Gji3djQiF-op
|
||||||
|
WUjLeGIMLC-gwAOKB4PjlsJBPlIg3pYpRuUEDERIy7kxZ8PIe4Nrfli_sRwMknm9HgQaigu3euYcjxXG9CALTs_vR
|
||||||
|
a7lRdpEKQY1ysY_z0bjIk1v-erEyNflQimpDHXGxujVj1EUrYz2diu60acmLSEciThafweAupr_qyKXUutBsc_KPK
|
||||||
|
33n8KBIPjl8X7bX2z-dXMKXo312vfPb6iO1ZcoFXG2nkFzwvFUKYFHSGjuZTQKgiaVEhlbq7N-80BlynnkHLYGcbn
|
||||||
|
9MtrT8O2Fci1i2ByxyL6B3vB1D5J1VyZ7IBY5AD1GanK2uFmC9nAoFvjTQJt3k2TI_MiPHgb1fZkHu0r-yrf9W_Hr
|
||||||
|
PrhBTp5wbepRSC6hs-yTykLJKSE5CD43KbjoW5GCqOkkQMnVjvSY4FpAdTj8Qt7kk"
|
||||||
|
}"##;
|
||||||
|
let rsa_jwk = rsa_jwk.replace(" ", "");
|
||||||
|
let rsa_jwk = rsa_jwk.replace("\r", "");
|
||||||
|
let rsa_jwk = rsa_jwk.replace("\n", "");
|
||||||
|
|
||||||
|
println!("{}", rsa_jwk);
|
||||||
|
let rsa: Rsa = serde_json::from_str(&rsa_jwk).unwrap();
|
||||||
|
|
||||||
|
let rsa_public_key = rsa::RsaPublicKey::try_from(rsa).unwrap();
|
||||||
|
// println!("{:?}", rsa_public_key);
|
||||||
|
|
||||||
|
let mut r = ThreadRng::default();
|
||||||
|
let enc = rsa_public_key.encrypt(&mut r, Pkcs1v15Encrypt, b"aaaaaaaa").unwrap();
|
||||||
|
println!("{}", STANDARD.encode(&enc));
|
||||||
|
|
||||||
|
let enc2 = rsa_public_key.encrypt(&mut r, Oaep::new::<Sha256>(), b"").unwrap();
|
||||||
|
println!("{}", STANDARD.encode(&enc2));
|
||||||
|
}
|
||||||
433
__crypto/liboqs-rust-demo/Cargo.lock
generated
Normal file
433
__crypto/liboqs-rust-demo/Cargo.lock
generated
Normal file
@@ -0,0 +1,433 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.22.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bindgen"
|
||||||
|
version = "0.68.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"cexpr",
|
||||||
|
"clang-sys",
|
||||||
|
"lazy_static",
|
||||||
|
"lazycell",
|
||||||
|
"log",
|
||||||
|
"peeking_take_while",
|
||||||
|
"prettyplease",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"regex",
|
||||||
|
"rustc-hash",
|
||||||
|
"shlex",
|
||||||
|
"syn",
|
||||||
|
"which",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "build-deps"
|
||||||
|
version = "0.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "64f14468960818ce4f3e3553c32d524446687884f8e7af5d3e252331d8a87e43"
|
||||||
|
dependencies = [
|
||||||
|
"glob",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cc"
|
||||||
|
version = "1.0.90"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cexpr"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
||||||
|
dependencies = [
|
||||||
|
"nom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clang-sys"
|
||||||
|
version = "1.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "67523a3b4be3ce1989d607a828d036249522dd9c1c8de7f4dd2dae43a37369d1"
|
||||||
|
dependencies = [
|
||||||
|
"glob",
|
||||||
|
"libc",
|
||||||
|
"libloading",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cmake"
|
||||||
|
version = "0.1.50"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cstr_core"
|
||||||
|
version = "0.2.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dd98742e4fdca832d40cab219dc2e3048de17d873248f83f17df47c1bea70956"
|
||||||
|
dependencies = [
|
||||||
|
"cty",
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cty"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "either"
|
||||||
|
version = "1.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "errno"
|
||||||
|
version = "0.3.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glob"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "home"
|
||||||
|
version = "0.5.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lazy_static"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lazycell"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.153"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libloading"
|
||||||
|
version = "0.8.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "liboqs-rust-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"base64",
|
||||||
|
"oqs",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "linux-raw-sys"
|
||||||
|
version = "0.4.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "minimal-lexical"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nom"
|
||||||
|
version = "7.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
"minimal-lexical",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.19.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "oqs"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "311616b64e55f9dc110286ea7cc5e475216dc332c54291e59a709c32fddb3a14"
|
||||||
|
dependencies = [
|
||||||
|
"cstr_core",
|
||||||
|
"libc",
|
||||||
|
"oqs-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "oqs-sys"
|
||||||
|
version = "0.9.1+liboqs-0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "afa79adc3c10f8e01d0b134c159254e5843ec3f91c0bd868e57777beb3329e17"
|
||||||
|
dependencies = [
|
||||||
|
"bindgen",
|
||||||
|
"build-deps",
|
||||||
|
"cmake",
|
||||||
|
"libc",
|
||||||
|
"pkg-config",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "peeking_take_while"
|
||||||
|
version = "0.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkg-config"
|
||||||
|
version = "0.3.30"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "prettyplease"
|
||||||
|
version = "0.2.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.79"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.35"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.10.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-hash"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustix"
|
||||||
|
version = "0.38.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"errno",
|
||||||
|
"libc",
|
||||||
|
"linux-raw-sys",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shlex"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.55"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "which"
|
||||||
|
version = "4.4.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
"home",
|
||||||
|
"once_cell",
|
||||||
|
"rustix",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.52.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm",
|
||||||
|
"windows_aarch64_msvc",
|
||||||
|
"windows_i686_gnu",
|
||||||
|
"windows_i686_msvc",
|
||||||
|
"windows_x86_64_gnu",
|
||||||
|
"windows_x86_64_gnullvm",
|
||||||
|
"windows_x86_64_msvc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.52.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"
|
||||||
10
__crypto/liboqs-rust-demo/Cargo.toml
Normal file
10
__crypto/liboqs-rust-demo/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "liboqs-rust-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
base64 = "0.22.0"
|
||||||
|
oqs = "0.9.0"
|
||||||
35
__crypto/liboqs-rust-demo/src/main.rs
Normal file
35
__crypto/liboqs-rust-demo/src/main.rs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
use base64::Engine;
|
||||||
|
use base64::engine::general_purpose::STANDARD;
|
||||||
|
use oqs::*;
|
||||||
|
|
||||||
|
// from: https://github.com/open-quantum-safe/liboqs-rust
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let sigalg = sig::Sig::new(sig::Algorithm::Dilithium2)?;
|
||||||
|
let kemalg = kem::Kem::new(kem::Algorithm::Kyber512)?;
|
||||||
|
// A's long-term secrets
|
||||||
|
let (a_sig_pk, a_sig_sk) = sigalg.keypair()?;
|
||||||
|
// B's long-term secrets
|
||||||
|
let (b_sig_pk, b_sig_sk) = sigalg.keypair()?;
|
||||||
|
|
||||||
|
// assumption: A has (a_sig_sk, a_sig_pk, b_sig_pk)
|
||||||
|
// assumption: B has (b_sig_sk, b_sig_pk, a_sig_pk)
|
||||||
|
|
||||||
|
// A -> B: kem_pk, signature
|
||||||
|
let (kem_pk, kem_sk) = kemalg.keypair()?;
|
||||||
|
let signature = sigalg.sign(kem_pk.as_ref(), &a_sig_sk)?;
|
||||||
|
println!(">>>>> Signature: {}\n", STANDARD.encode(&signature));
|
||||||
|
|
||||||
|
// B -> A: kem_ct, signature
|
||||||
|
sigalg.verify(kem_pk.as_ref(), &signature, &a_sig_pk)?;
|
||||||
|
let (kem_ct, b_kem_ss) = kemalg.encapsulate(&kem_pk)?;
|
||||||
|
let signature = sigalg.sign(kem_ct.as_ref(), &b_sig_sk)?;
|
||||||
|
println!(">>>>> Signature: {}\n", STANDARD.encode(&signature));
|
||||||
|
|
||||||
|
// A verifies, decapsulates, now both have kem_ss
|
||||||
|
sigalg.verify(kem_ct.as_ref(), &signature, &b_sig_pk)?;
|
||||||
|
let a_kem_ss = kemalg.decapsulate(&kem_sk, &kem_ct)?;
|
||||||
|
println!(">>>>> Shared secret: {}", STANDARD.encode(&a_kem_ss));
|
||||||
|
assert_eq!(a_kem_ss, b_kem_ss);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
258
__crypto/ml-kem-demo/Cargo.lock
generated
Normal file
258
__crypto/ml-kem-demo/Cargo.lock
generated
Normal file
@@ -0,0 +1,258 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.22.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "block-buffer"
|
||||||
|
version = "0.10.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cpufeatures"
|
||||||
|
version = "0.2.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-common"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
"typenum",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "digest"
|
||||||
|
version = "0.10.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||||
|
dependencies = [
|
||||||
|
"block-buffer",
|
||||||
|
"crypto-common",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "generic-array"
|
||||||
|
version = "0.14.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||||
|
dependencies = [
|
||||||
|
"typenum",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.2.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hybrid-array"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f2d35805454dc9f8662a98d6d61886ffe26bd465f5960e0e55345c70d5c0d2a9"
|
||||||
|
dependencies = [
|
||||||
|
"typenum",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "keccak"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654"
|
||||||
|
dependencies = [
|
||||||
|
"cpufeatures",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "kem"
|
||||||
|
version = "0.3.0-pre.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b8645470337db67b01a7f966decf7d0bafedbae74147d33e641c67a91df239f"
|
||||||
|
dependencies = [
|
||||||
|
"rand_core",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.176"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ml-kem"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "97befee0c869cb56f3118f49d0f9bb68c9e3f380dec23c1100aedc4ec3ba239a"
|
||||||
|
dependencies = [
|
||||||
|
"hybrid-array",
|
||||||
|
"kem",
|
||||||
|
"rand_core",
|
||||||
|
"sha3",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ml-kem-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"base64",
|
||||||
|
"ml-kem",
|
||||||
|
"rand",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.101"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sha3"
|
||||||
|
version = "0.10.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60"
|
||||||
|
dependencies = [
|
||||||
|
"digest",
|
||||||
|
"keccak",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.106"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typenum"
|
||||||
|
version = "1.18.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.1+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy"
|
||||||
|
version = "0.8.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy-derive"
|
||||||
|
version = "0.8.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zeroize"
|
||||||
|
version = "1.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
|
||||||
9
__crypto/ml-kem-demo/Cargo.toml
Normal file
9
__crypto/ml-kem-demo/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "ml-kem-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
base64 = "0.22.1"
|
||||||
|
ml-kem = { version = "0.2.1", features = ["zeroize"] }
|
||||||
|
rand = "0.8"
|
||||||
31
__crypto/ml-kem-demo/src/main.rs
Normal file
31
__crypto/ml-kem-demo/src/main.rs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
use base64::Engine;
|
||||||
|
use base64::engine::general_purpose::STANDARD;
|
||||||
|
use ml_kem::kem::Encapsulate;
|
||||||
|
use ml_kem::{Encoded, EncodedSizeUser, KemCore, MlKem768};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let ek_bytes = STANDARD.decode("fZKrgJTGZYMogAO0u8XI/skLXXCx/hCmQjKdEGGaBitoBWCrbaw\
|
||||||
|
+t7nAT7G8lexlEdwGJrdwNuBVJFZOEnxH9Fu2e7kZrAA0EWZThrhrlCQb7SKSJ3MKP9jGeNA2igU/cXhQj9qSaWzNqplMffhuZHjBAT\
|
||||||
|
Nxglk6IwBcUnNpgEit0dYJgsxsMkfD8AzOaHKm4ybKwzJtYBN6nREl/OZE9CvDtVmZx+wkE1JwWuJJzLqdHWvJ4lyFq2YRUnxtpACKp\
|
||||||
|
xAkVfOzRuqlPUDJijwAc1UvXaFDLydJ/kcKiAorUfQtUoVJ8hkGK8OED3B15NxfJsRwt1kLhEgk89lD6GGhRRFmU8WQHBuX0pppe5A5\
|
||||||
|
BEm148Gv82c+KUUXSAcIFTFMg+UyPDKCaPFu5XBfyvM5RveXuyBFs/IF47BTmKfMVVOPXuh/SIZCONsBAOZgoneexKp8NyjMsVc8kWC\
|
||||||
|
OCVc+2sIcKjIElmRtjDFK9vooRVwGXppfPcV2vMeUk5IMF7aGnDdjkdGm1/oYkPqnvesi5bIpL+kGj9EPDibIPAS4AUQajgNNioRErB\
|
||||||
|
mxAdlZHWpXD+ixmbJp4geG7gJ3OsbBhmmBtJuPTcZeSLOg3HVtQTwyhxd1WjcMh1eqp0i5bDF/0Zin8dcqE0JRmTBj4MTAEbs1xNe1+\
|
||||||
|
xCZB3tnviVOU9d5uSpF6MNmdVWFiYmJJFYyeiJIOWmL1Och79S565dhxxO+ndd2DHVIuTaBW3cu4WSn9AlMqAcPvMxPAYcY7kFcOjc/\
|
||||||
|
PvYI4+oIfGgLaCcFNWcZUCBKz2Qi1zYqSjYYTrnJQVGClpOaGpdXi0zDYvagA2ZSDzNZS6oki6ZeimU0YzQDlRirNPx6ARSgdJU7WgA\
|
||||||
|
SpUNen0QLcoa7iwTDwGeEkHMt2OhUmqdv8bUNJ7YjpJuHOKuMX2C6fJslY5pyP5FJNVE7BugCSdSU1rxOKcHN0iiQSEgd8BU8hkZmof\
|
||||||
|
GahyzPgABI1cJjViMb/cgoiRtrsZuzBWDCVjog8mx7ulYhkszM9ghookGbHHwx/abBbRcTr1HIl0ursSCJPoZT3UWFRNgvVuA7gMQVJ\
|
||||||
|
FxxiFBOxOuHrMTABhVdpPCpNYvEgWRC+Skj3XhZRWovTLuDWPazRMe31iWVirBWTUIeIEEiRsvBPXMW3Ne1gsVwDFEOiaxp5SOAnAGK\
|
||||||
|
mkg/8LIRTHA0LbpBDEjEK+VllQeCIaUJk9g2FxlgatuqcDgIY2KH2NZapIOiRyZYs8shb2JJIRAWqcwRNIBL7ZwBOpafsyJc3BS4YSY\
|
||||||
|
ErVdAOOZe8/G9mcrNwOKzkkPFDUsb+eBEdHIr4bCUGGyinLkGskkXb1Gl8FCbTOGU04ZZtqhFI6eP5Stb7MiY7ywRhiOvokduQTLN26\
|
||||||
|
CsRJa579VOqdeSsNjFI6lxMhgwaxGaHcwWiGBDSbGGcyskujyPebYl+UlhDXGGVHYfZStkj8Sm84KGWqaq9BSQmIgU8oCj7SRMTGC3c\
|
||||||
|
dmjK5QiTGV+LEZKWwpQ9+GU5TIrTqImmeBj+dpGoPFmbliytiKbH53ZsFCfVNMqOvJ24IxdfgWNpBmrChnYmLQ=").unwrap();
|
||||||
|
|
||||||
|
let e: Encoded<<MlKem768 as KemCore>::EncapsulationKey> =
|
||||||
|
ek_bytes.as_slice().try_into().unwrap();
|
||||||
|
let ek = <MlKem768 as KemCore>::EncapsulationKey::from_bytes(&e);
|
||||||
|
let mut rng = rand::rngs::OsRng;
|
||||||
|
let k = ek.encapsulate(&mut rng).unwrap();
|
||||||
|
println!("{}", STANDARD.encode(k.0.as_slice()));
|
||||||
|
println!("Shared secret: {}", STANDARD.encode(k.1.as_slice()));
|
||||||
|
}
|
||||||
257
__crypto/okta-bcrypt-issue/Cargo.lock
generated
Normal file
257
__crypto/okta-bcrypt-issue/Cargo.lock
generated
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.22.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bcrypt"
|
||||||
|
version = "0.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "92758ad6077e4c76a6cadbce5005f666df70d4f13b19976b1a8062eef880040f"
|
||||||
|
dependencies = [
|
||||||
|
"base64",
|
||||||
|
"blowfish",
|
||||||
|
"getrandom",
|
||||||
|
"subtle",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "blowfish"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e412e2cd0f2b2d93e02543ceae7917b3c70331573df19ee046bcbc35e45e87d7"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
"cipher",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cipher"
|
||||||
|
version = "0.4.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
|
||||||
|
dependencies = [
|
||||||
|
"crypto-common",
|
||||||
|
"inout",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-common"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
"typenum",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "generic-array"
|
||||||
|
version = "0.14.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||||
|
dependencies = [
|
||||||
|
"typenum",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"r-efi",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "inout"
|
||||||
|
version = "0.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.174"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "okta-bcrypt-issue"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"base64",
|
||||||
|
"bcrypt",
|
||||||
|
"rand",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.95"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.40"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "r-efi"
|
||||||
|
version = "5.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
|
||||||
|
dependencies = [
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "subtle"
|
||||||
|
version = "2.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.104"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typenum"
|
||||||
|
version = "1.18.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.14.2+wasi-0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
|
||||||
|
dependencies = [
|
||||||
|
"wit-bindgen-rt",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen-rt"
|
||||||
|
version = "0.39.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy"
|
||||||
|
version = "0.8.26"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f"
|
||||||
|
dependencies = [
|
||||||
|
"zerocopy-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy-derive"
|
||||||
|
version = "0.8.26"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zeroize"
|
||||||
|
version = "1.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
|
||||||
9
__crypto/okta-bcrypt-issue/Cargo.toml
Normal file
9
__crypto/okta-bcrypt-issue/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "okta-bcrypt-issue"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
base64 = "0.22.1"
|
||||||
|
bcrypt = "0.17.0"
|
||||||
|
rand = "0.9.1"
|
||||||
33
__crypto/okta-bcrypt-issue/src/main.rs
Normal file
33
__crypto/okta-bcrypt-issue/src/main.rs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
use rand::RngCore;
|
||||||
|
use base64::{Engine as _, engine::general_purpose::URL_SAFE};
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
|
fn random_string(length: usize) -> String {
|
||||||
|
let mut bytes = vec![0u8; length];
|
||||||
|
rand::rng().fill_bytes(&mut bytes);
|
||||||
|
URL_SAFE.encode(&bytes)[..length].to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://n0rdy.foo/posts/20250121/okta-bcrypt-lessons-for-better-apis/
|
||||||
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
// 18 + 55 + 1 = 74, so above 72 characters' limit of BCrypt
|
||||||
|
let user_id = random_string(18);
|
||||||
|
let username = random_string(55);
|
||||||
|
let password = "super-duper-secure-password";
|
||||||
|
|
||||||
|
let combined_string = format!("{}:{}:{}", user_id, username, password);
|
||||||
|
let combined_hash = bcrypt::hash(combined_string.as_bytes(), bcrypt::DEFAULT_COST)?;
|
||||||
|
|
||||||
|
// let's try to break it
|
||||||
|
let wrong_password = "wrong-password";
|
||||||
|
let wrong_combined_string = format!("{}:{}:{}", user_id, username, wrong_password);
|
||||||
|
|
||||||
|
match bcrypt::verify(wrong_combined_string.as_bytes(), &combined_hash) {
|
||||||
|
Ok(true) => println!("Password is correct"),
|
||||||
|
Ok(false) => println!("Password is incorrect"),
|
||||||
|
Err(e) => println!("{}", e),
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
108
__crypto/orion-demo/Cargo.lock
generated
Normal file
108
__crypto/orion-demo/Cargo.lock
generated
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ct-codecs"
|
||||||
|
version = "1.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b10589d1a5e400d61f9f38f12f884cfd080ff345de8f17efda36fe0e4a02aa8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fiat-crypto"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "64cd1e32ddd350061ae6edb1b082d7c54915b5c672c389143b9a63403a109f24"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"r-efi",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hex"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.174"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "orion"
|
||||||
|
version = "0.17.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "21b3da83b2b4cdc74ab6a556b2e7b473da046d5aa4008c0a7a3ae96b1b4aabb4"
|
||||||
|
dependencies = [
|
||||||
|
"ct-codecs",
|
||||||
|
"fiat-crypto",
|
||||||
|
"getrandom",
|
||||||
|
"subtle",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "orion-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"hex",
|
||||||
|
"orion",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "r-efi"
|
||||||
|
version = "5.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "subtle"
|
||||||
|
version = "2.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.14.2+wasi-0.2.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
|
||||||
|
dependencies = [
|
||||||
|
"wit-bindgen-rt",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen-rt"
|
||||||
|
version = "0.39.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zeroize"
|
||||||
|
version = "1.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
|
||||||
8
__crypto/orion-demo/Cargo.toml
Normal file
8
__crypto/orion-demo/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "orion-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
hex = "0.4.3"
|
||||||
|
orion = "0.17.11"
|
||||||
44
__crypto/orion-demo/src/main.rs
Normal file
44
__crypto/orion-demo/src/main.rs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
use orion::hazardous::ecc::x25519::key_agreement;
|
||||||
|
use orion::kex::{PrivateKey, PublicKey};
|
||||||
|
use orion::pwhash::{Password, hash_password, hash_password_verify};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let password = Password::from_slice(b"hello_world").unwrap();
|
||||||
|
let password_hash = hash_password(&password, 100, 1024).unwrap();
|
||||||
|
println!("{}", password_hash.unprotected_as_encoded());
|
||||||
|
println!("{:?}", hash_password_verify(&password_hash, &password));
|
||||||
|
|
||||||
|
println!("{}", "-".repeat(88));
|
||||||
|
|
||||||
|
let alice_sk = PrivateKey::generate();
|
||||||
|
let alice_pk = PublicKey::try_from(&alice_sk).unwrap();
|
||||||
|
|
||||||
|
let bob_sk = PrivateKey::generate();
|
||||||
|
let bob_pk = PublicKey::try_from(&bob_sk).unwrap();
|
||||||
|
|
||||||
|
let alice_shared = key_agreement(&alice_sk, &bob_pk).unwrap();
|
||||||
|
let bob_shared = key_agreement(&bob_sk, &alice_pk).unwrap();
|
||||||
|
|
||||||
|
println!("{}", hex::encode(alice_shared.unprotected_as_bytes()));
|
||||||
|
println!("{}", hex::encode(bob_shared.unprotected_as_bytes()));
|
||||||
|
|
||||||
|
println!("{}", "-".repeat(88));
|
||||||
|
|
||||||
|
let user_password = Password::from_slice(b"hello_world").unwrap();
|
||||||
|
let salt = orion::kdf::Salt::default();
|
||||||
|
let derived_key = orion::kdf::derive_key(&user_password, &salt, 3, 1 << 16, 32).unwrap();
|
||||||
|
println!(
|
||||||
|
"{} {}",
|
||||||
|
hex::encode(salt.as_ref()),
|
||||||
|
hex::encode(derived_key.unprotected_as_bytes())
|
||||||
|
);
|
||||||
|
|
||||||
|
println!("{}", "-".repeat(88));
|
||||||
|
|
||||||
|
let aead_key = orion::aead::SecretKey::generate(32).unwrap();
|
||||||
|
let ciphertext = orion::aead::seal(&aead_key, b"hello world").unwrap();
|
||||||
|
|
||||||
|
let plaintext = orion::aead::open(&aead_key, &ciphertext).unwrap();
|
||||||
|
println!("{}", hex::encode(&ciphertext));
|
||||||
|
println!("{} {}", hex::encode(&plaintext), String::from_utf8_lossy(&plaintext));
|
||||||
|
}
|
||||||
1504
__crypto/passkey-rs-demo/Cargo.lock
generated
Normal file
1504
__crypto/passkey-rs-demo/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
__crypto/passkey-rs-demo/Cargo.toml
Normal file
12
__crypto/passkey-rs-demo/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "passkey-rs-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
passkey = "0.4.0"
|
||||||
|
url = "2.5.4"
|
||||||
|
async-trait = "0.1.88"
|
||||||
|
passkey-client = "0.4.0"
|
||||||
|
coset = "0.3.8"
|
||||||
|
tokio = { version = "1.45.1", features = ["full"] }
|
||||||
4
__crypto/passkey-rs-demo/README.md
Normal file
4
__crypto/passkey-rs-demo/README.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
Source code: https://github.com/1Password/passkey-rs/blob/main/passkey/examples/usage.rs
|
||||||
|
|
||||||
|
|
||||||
230
__crypto/passkey-rs-demo/src/main.rs
Normal file
230
__crypto/passkey-rs-demo/src/main.rs
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
use passkey::{
|
||||||
|
authenticator::{Authenticator, UserCheck, UserValidationMethod},
|
||||||
|
client::{Client, WebauthnError},
|
||||||
|
types::{crypto::sha256, ctap2::*, rand::random_vec, webauthn::*, Bytes, Passkey},
|
||||||
|
};
|
||||||
|
|
||||||
|
use coset::iana;
|
||||||
|
use passkey_client::DefaultClientData;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
// MyUserValidationMethod is a stub impl of the UserValidationMethod trait, used later.
|
||||||
|
struct MyUserValidationMethod {}
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl UserValidationMethod for MyUserValidationMethod {
|
||||||
|
type PasskeyItem = Passkey;
|
||||||
|
|
||||||
|
async fn check_user<'a>(
|
||||||
|
&self,
|
||||||
|
_credential: Option<&'a Passkey>,
|
||||||
|
presence: bool,
|
||||||
|
verification: bool,
|
||||||
|
) -> Result<UserCheck, Ctap2Error> {
|
||||||
|
Ok(UserCheck {
|
||||||
|
presence,
|
||||||
|
verification,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_verification_enabled(&self) -> Option<bool> {
|
||||||
|
Some(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_presence_enabled(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example of how to set up, register and authenticate with a `Client`.
|
||||||
|
async fn client_setup(
|
||||||
|
challenge_bytes_from_rp: Bytes,
|
||||||
|
parameters_from_rp: PublicKeyCredentialParameters,
|
||||||
|
origin: &Url,
|
||||||
|
user_entity: PublicKeyCredentialUserEntity,
|
||||||
|
) -> Result<(CreatedPublicKeyCredential, AuthenticatedPublicKeyCredential), WebauthnError> {
|
||||||
|
// First create an Authenticator for the Client to use.
|
||||||
|
let my_aaguid = Aaguid::new_empty();
|
||||||
|
let user_validation_method = MyUserValidationMethod {};
|
||||||
|
// Create the CredentialStore for the Authenticator.
|
||||||
|
// Option<Passkey> is the simplest possible implementation of CredentialStore
|
||||||
|
let store: Option<Passkey> = None;
|
||||||
|
let my_authenticator = Authenticator::new(my_aaguid, store, user_validation_method);
|
||||||
|
|
||||||
|
// Create the Client
|
||||||
|
// If you are creating credentials, you need to declare the Client as mut
|
||||||
|
let mut my_client = Client::new(my_authenticator);
|
||||||
|
|
||||||
|
// The following values, provided as parameters to this function would usually be
|
||||||
|
// retrieved from a Relying Party according to the context of the application.
|
||||||
|
let request = CredentialCreationOptions {
|
||||||
|
public_key: PublicKeyCredentialCreationOptions {
|
||||||
|
rp: PublicKeyCredentialRpEntity {
|
||||||
|
id: None, // Leaving the ID as None means use the effective domain
|
||||||
|
name: origin.domain().unwrap().into(),
|
||||||
|
},
|
||||||
|
user: user_entity,
|
||||||
|
challenge: challenge_bytes_from_rp,
|
||||||
|
pub_key_cred_params: vec![parameters_from_rp],
|
||||||
|
timeout: None,
|
||||||
|
exclude_credentials: None,
|
||||||
|
authenticator_selection: None,
|
||||||
|
hints: None,
|
||||||
|
attestation: AttestationConveyancePreference::None,
|
||||||
|
attestation_formats: None,
|
||||||
|
extensions: None,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Now create the credential.
|
||||||
|
let my_webauthn_credential = my_client
|
||||||
|
.register(origin, request, DefaultClientData)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
// Let's try and authenticate.
|
||||||
|
// Create a challenge that would usually come from the RP.
|
||||||
|
let challenge_bytes_from_rp: Bytes = random_vec(32).into();
|
||||||
|
// Now try and authenticate
|
||||||
|
let credential_request = CredentialRequestOptions {
|
||||||
|
public_key: PublicKeyCredentialRequestOptions {
|
||||||
|
challenge: challenge_bytes_from_rp,
|
||||||
|
timeout: None,
|
||||||
|
rp_id: Some(String::from(origin.domain().unwrap())),
|
||||||
|
allow_credentials: None,
|
||||||
|
user_verification: UserVerificationRequirement::default(),
|
||||||
|
hints: None,
|
||||||
|
attestation: AttestationConveyancePreference::None,
|
||||||
|
attestation_formats: None,
|
||||||
|
extensions: None,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let authenticated_cred = my_client
|
||||||
|
.authenticate(origin, credential_request, DefaultClientData)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok((my_webauthn_credential, authenticated_cred))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn authenticator_setup(
|
||||||
|
user_entity: PublicKeyCredentialUserEntity,
|
||||||
|
client_data_hash: Bytes,
|
||||||
|
algorithms_from_rp: PublicKeyCredentialParameters,
|
||||||
|
rp_id: String,
|
||||||
|
) -> Result<get_assertion::Response, StatusCode> {
|
||||||
|
let store: Option<Passkey> = None;
|
||||||
|
let user_validation_method = MyUserValidationMethod {};
|
||||||
|
let my_aaguid = Aaguid::new_empty();
|
||||||
|
|
||||||
|
let mut my_authenticator = Authenticator::new(my_aaguid, store, user_validation_method);
|
||||||
|
|
||||||
|
let reg_request = make_credential::Request {
|
||||||
|
client_data_hash: client_data_hash.clone(),
|
||||||
|
rp: make_credential::PublicKeyCredentialRpEntity {
|
||||||
|
id: rp_id.clone(),
|
||||||
|
name: None,
|
||||||
|
},
|
||||||
|
user: user_entity,
|
||||||
|
pub_key_cred_params: vec![algorithms_from_rp],
|
||||||
|
exclude_list: None,
|
||||||
|
extensions: None,
|
||||||
|
options: make_credential::Options::default(),
|
||||||
|
pin_auth: None,
|
||||||
|
pin_protocol: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let credential: make_credential::Response =
|
||||||
|
my_authenticator.make_credential(reg_request).await?;
|
||||||
|
|
||||||
|
ctap2_creation_success(credential);
|
||||||
|
|
||||||
|
let auth_request = get_assertion::Request {
|
||||||
|
rp_id,
|
||||||
|
client_data_hash,
|
||||||
|
allow_list: None,
|
||||||
|
extensions: None,
|
||||||
|
options: make_credential::Options::default(),
|
||||||
|
pin_auth: None,
|
||||||
|
pin_protocol: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let response = my_authenticator.get_assertion(auth_request).await?;
|
||||||
|
|
||||||
|
Ok(response)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ctap2_creation_success(credential: make_credential::Response) {
|
||||||
|
println!(
|
||||||
|
"CTAP2 credential creation succeeded:\n\n{:?}\n\n",
|
||||||
|
credential
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ctap2_auth_success(credential: get_assertion::Response) {
|
||||||
|
println!(
|
||||||
|
"CTAP2 credential authentication succeeded:\n\n{:?}\n\n",
|
||||||
|
credential
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ctap2_credential_not_found() {
|
||||||
|
println!("CTAP2 error: Credential not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ctap2_other_error(code: StatusCode) {
|
||||||
|
println!("CTAP2 error: Other Status Code: {:?}", code);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), WebauthnError> {
|
||||||
|
let rp_url = Url::parse("https://example.com/").expect("Should Parse");
|
||||||
|
let user_entity = PublicKeyCredentialUserEntity {
|
||||||
|
id: random_vec(32).into(),
|
||||||
|
display_name: "Hatter Jiang".into(),
|
||||||
|
name: "jpasskey@example.org".into(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set up a client, create and authenticate a credential, then report results.
|
||||||
|
let (created_cred, authed_cred) = client_setup(
|
||||||
|
random_vec(32).into(), // challenge_bytes_from_rp
|
||||||
|
PublicKeyCredentialParameters {
|
||||||
|
ty: PublicKeyCredentialType::PublicKey,
|
||||||
|
alg: iana::Algorithm::ES256,
|
||||||
|
},
|
||||||
|
&rp_url, // origin
|
||||||
|
user_entity.clone(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
println!("Webauthn credential created:\n\n{:?}\n\n", created_cred);
|
||||||
|
println!("Webauthn credential auth'ed:\n\n{:?}\n\n", authed_cred);
|
||||||
|
|
||||||
|
// Generate the client_data_hash from the created_cred response
|
||||||
|
let client_data_hash = sha256(&created_cred.response.client_data_json).to_vec();
|
||||||
|
|
||||||
|
// Authenticator Version
|
||||||
|
let authenticator_result = authenticator_setup(
|
||||||
|
user_entity,
|
||||||
|
client_data_hash.into(),
|
||||||
|
PublicKeyCredentialParameters {
|
||||||
|
ty: PublicKeyCredentialType::PublicKey,
|
||||||
|
alg: iana::Algorithm::ES256,
|
||||||
|
},
|
||||||
|
rp_url
|
||||||
|
.domain()
|
||||||
|
.expect("Our example should unwrap.")
|
||||||
|
.to_string(), // tld_from_rp
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
match authenticator_result {
|
||||||
|
Ok(authresponse) => {
|
||||||
|
ctap2_auth_success(authresponse);
|
||||||
|
}
|
||||||
|
Err(StatusCode::Ctap2(Ctap2Code::Known(Ctap2Error::NoCredentials))) => {
|
||||||
|
ctap2_credential_not_found()
|
||||||
|
}
|
||||||
|
Err(status_code) => ctap2_other_error(status_code),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
1204
__crypto/rpgp-demo/Cargo.lock
generated
Normal file
1204
__crypto/rpgp-demo/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
10
__crypto/rpgp-demo/Cargo.toml
Normal file
10
__crypto/rpgp-demo/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "rpgp-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
pgp = "0.9.0"
|
||||||
|
smallvec = "1.10.0"
|
||||||
34
__crypto/rpgp-demo/src/main.rs
Normal file
34
__crypto/rpgp-demo/src/main.rs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// use pgp::composed::{key::SecretKeyParamsBuilder, KeyDetails, KeyType, SecretKey, SecretSubkey};
|
||||||
|
// use pgp::packet::{KeyFlags, UserAttribute, UserId};
|
||||||
|
// use pgp::types::{CompressionAlgorithm, PublicKeyTrait, SecretKeyTrait};
|
||||||
|
use pgp::composed::{key::SecretKeyParamsBuilder, KeyType};
|
||||||
|
use pgp::crypto::{hash::HashAlgorithm, sym::SymmetricKeyAlgorithm};
|
||||||
|
use pgp::types::{CompressionAlgorithm, SecretKeyTrait};
|
||||||
|
use smallvec::*;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut key_params = SecretKeyParamsBuilder::default();
|
||||||
|
key_params
|
||||||
|
.key_type(KeyType::Rsa(2048))
|
||||||
|
.can_create_certificates(false)
|
||||||
|
.can_sign(true)
|
||||||
|
.primary_user_id("Me <me@example.com>".into())
|
||||||
|
.preferred_symmetric_algorithms(smallvec![
|
||||||
|
SymmetricKeyAlgorithm::AES256,
|
||||||
|
])
|
||||||
|
.preferred_hash_algorithms(smallvec![
|
||||||
|
HashAlgorithm::SHA2_256,
|
||||||
|
])
|
||||||
|
.preferred_compression_algorithms(smallvec![
|
||||||
|
CompressionAlgorithm::ZLIB,
|
||||||
|
]);
|
||||||
|
let secret_key_params = key_params.build().expect("Must be able to create secret key params");
|
||||||
|
let secret_key = secret_key_params.generate().expect("Failed to generate a plain key.");
|
||||||
|
let passwd_fn = || String::new();
|
||||||
|
let signed_secret_key = secret_key.sign(passwd_fn).expect("Must be able to sign its own metadata");
|
||||||
|
let public_key = signed_secret_key.public_key();
|
||||||
|
|
||||||
|
// println!("{:?}", secret_key);
|
||||||
|
println!("{:?}", signed_secret_key);
|
||||||
|
println!("{:?}", public_key);
|
||||||
|
}
|
||||||
8
__crypto/secretshare/CHANGELOG.md
Normal file
8
__crypto/secretshare/CHANGELOG.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
2015-02-03:
|
||||||
|
|
||||||
|
* I changed the CRC-24 checksum computation to include the coding parameter
|
||||||
|
K and the share number N so that these numbers are also protected.
|
||||||
|
If you have older shares generated with a previous version, you can still
|
||||||
|
decode the secret by simply removing the checksum part of the shares.
|
||||||
|
* The README now includes more information about the inner workings of
|
||||||
|
secretshare and also a note on "perfect secrecy".
|
||||||
105
__crypto/secretshare/Cargo.lock
generated
Normal file
105
__crypto/secretshare/Cargo.lock
generated
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crc24"
|
||||||
|
version = "0.1.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fd121741cf3eb82c08dd3023eb55bf2665e5f60ec20f89760cf836ae4562e6a0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getopts"
|
||||||
|
version = "0.2.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-width",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.2.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.147"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-serialize"
|
||||||
|
version = "0.3.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "secretshare"
|
||||||
|
version = "0.1.6"
|
||||||
|
dependencies = [
|
||||||
|
"crc24",
|
||||||
|
"getopts",
|
||||||
|
"rand",
|
||||||
|
"rustc-serialize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-width"
|
||||||
|
version = "0.1.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||||
21
__crypto/secretshare/Cargo.toml
Normal file
21
__crypto/secretshare/Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
[package]
|
||||||
|
name = "secretshare"
|
||||||
|
version = "0.1.6"
|
||||||
|
authors = ["Sebastian Gesemann <s.gesemann@gmail.com>"]
|
||||||
|
description = "This is an implementation of Shamir's secret sharing scheme."
|
||||||
|
license = "GPLv3"
|
||||||
|
readme = "README.md"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
getopts = "0.2"
|
||||||
|
rustc-serialize = "0.3"
|
||||||
|
crc24 = "0.1"
|
||||||
|
rand = "0.8"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = "z"
|
||||||
|
lto = true
|
||||||
|
codegen-units = 1
|
||||||
|
panic = "abort"
|
||||||
|
strip = true
|
||||||
114
__crypto/secretshare/README.md
Normal file
114
__crypto/secretshare/README.md
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
> From: https://github.com/sellibitze/secretshare
|
||||||
|
|
||||||
|
# secretshare
|
||||||
|
|
||||||
|
This program is an implementation of
|
||||||
|
[Shamir's secret sharing](https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing).
|
||||||
|
A secret can be split into N shares in a way so that
|
||||||
|
a selectable number of shares K (with K ≤ N) is required
|
||||||
|
to reconstruct the secret again.
|
||||||
|
|
||||||
|
**Warning**: I don't yet recommend the serious use of this tool. The
|
||||||
|
encoding of the shares might change in a newer version in which case
|
||||||
|
you would have trouble decoding secrets that have been shared using
|
||||||
|
an older version of the program. For now, this is experimental.
|
||||||
|
|
||||||
|
# Example
|
||||||
|
|
||||||
|
Passing a secret to secretshare for encoding:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ echo My secret | ./secretshare -e2,5
|
||||||
|
2-1-1YAYwmOHqZ69jA-v+mz
|
||||||
|
2-2-YJZQDGm22Y77Gw-IhSh
|
||||||
|
2-3-+G9ovW9SAnUynQ-Elwi
|
||||||
|
2-4-F7rAjX3UOa53KA-b2vm
|
||||||
|
2-5-j0P4PHsw4lW+rg-XyNl
|
||||||
|
```
|
||||||
|
|
||||||
|
The parameters following the `-e` option tell `secretshare` to create 5 shares of which 2 will be necessary for decoding.
|
||||||
|
|
||||||
|
Decoding a subset of shares (one share per line) can be done like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ echo -e "2-2-YJZQDGm22Y77Gw-IhSh \n 2-4-F7rAjX3UOa53KA-b2vm" | ./secretshare -d
|
||||||
|
My secret
|
||||||
|
```
|
||||||
|
|
||||||
|
# Building
|
||||||
|
|
||||||
|
This project is Cargo-enabled. So, you should be able to build it with
|
||||||
|
|
||||||
|
```
|
||||||
|
$ cargo build --release
|
||||||
|
```
|
||||||
|
|
||||||
|
once you have made sure that `rustc` (the compiler) and `cargo`
|
||||||
|
(the build and dependency management tool) are installed.
|
||||||
|
Visit the [Rust homepage](http://www.rust-lang.org/) if you are
|
||||||
|
don't know where to get these tools.
|
||||||
|
|
||||||
|
# I/O
|
||||||
|
|
||||||
|
The secret data does not have to be text. `secretshare` treats it as
|
||||||
|
binary data. But, of course, you can feed it text as well. In the above
|
||||||
|
example the echo command terminated the string with a line feed which
|
||||||
|
is actually part of the secret and output as well after decoding.
|
||||||
|
Note that, while `secretshare` supports secrets of up to 64 KiB
|
||||||
|
it makes little sense to use such large secrets directly. In situations
|
||||||
|
where you want to share larger secrets, you would usually pick a random
|
||||||
|
password for encryption and use that password as secret for `secretshare`.
|
||||||
|
|
||||||
|
The generated shares are lines of ASCII text.
|
||||||
|
|
||||||
|
# Structure of the shares
|
||||||
|
|
||||||
|
```
|
||||||
|
2-1-LiTyeXwEP71IUA-Qj6n
|
||||||
|
^ ^ ^^^^^^^^^^^^^^ ^^^^
|
||||||
|
K N D C
|
||||||
|
```
|
||||||
|
|
||||||
|
A share is built out of three or four parts separated with a minus: K-N-D-C.
|
||||||
|
The last part is optional. K is one of the encoding parameters that tell you
|
||||||
|
how many distinct
|
||||||
|
shares of a specific secret are necessary to be able to recover the
|
||||||
|
secret. The number N identifies the share (ranging from 1 to the number
|
||||||
|
of shares that have been created). The D part is a Base64 encoding of
|
||||||
|
a specific share's raw data. The optional part C is a Base64 encoding
|
||||||
|
of a CRC-24 checksum of the concatenation of K and N as bytes followed
|
||||||
|
by the share's raw data (before Base64 encoding). The same checksum
|
||||||
|
algorithm is used in the OpenPGP format for “ASCII amoring”.
|
||||||
|
|
||||||
|
# A word on the secrecy
|
||||||
|
|
||||||
|
Shamir's secret sharing is known to have the perfect secrecy property.
|
||||||
|
In the context of (K,N)-threshold schemes this means that if you have
|
||||||
|
less than K shares available, you have absolutely no information about
|
||||||
|
what the secret is except for its length. The checksums that are included
|
||||||
|
in the shares
|
||||||
|
also don't reveal anything about the secret.
|
||||||
|
They are just a simple integrity protection of the shares themselves.
|
||||||
|
In other words, given a share without checksum, we can derive a share
|
||||||
|
with a checksum. This obviously does not add any new information.
|
||||||
|
|
||||||
|
# Galois field
|
||||||
|
|
||||||
|
Shamir's secret sharing algorithm requires the use of polynomials over
|
||||||
|
a finite field. One easy way of constructing a finite field is to pick
|
||||||
|
a prime number p, use the integers 0, 1, 2, ..., p-1 as field elements
|
||||||
|
and simply use modular arithmetic (mod p) for the field operations.
|
||||||
|
|
||||||
|
So, you *could* pick a prime like 257 to apply Shamir's algorithm
|
||||||
|
byte-wise. The downside of this is that the shares would consist of
|
||||||
|
sequences of values each between 0 and 256 *inclusive*. So, you would
|
||||||
|
need more than 8 bits to encode each of them.
|
||||||
|
|
||||||
|
But there is another way. We are not restricted to so-called
|
||||||
|
prime fields. There are also non-prime fields where the number of
|
||||||
|
elements is a *power* of a prime, for example 2^8=256. It's just
|
||||||
|
a bit harder to explain how they are constructed. The finite
|
||||||
|
field I used is the same as the one you can find in the RAID 6
|
||||||
|
implementation of the Linux kernel or the Anubis block cipher:
|
||||||
|
Gf(2^8) reduction polynomial is x^8 + x^4 + x^3 + x^2 + 1 or
|
||||||
|
alternatively 11D in hex.
|
||||||
9
__crypto/secretshare/justfile
Normal file
9
__crypto/secretshare/justfile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
_:
|
||||||
|
@just --list
|
||||||
|
|
||||||
|
build-n:
|
||||||
|
cargo +nightly build -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-apple-darwin --release
|
||||||
|
|
||||||
|
upx:
|
||||||
|
upx --best --lzma target/x86_64-apple-darwin/release/secretshare
|
||||||
|
|
||||||
143
__crypto/secretshare/src/gf256.rs
Normal file
143
__crypto/secretshare/src/gf256.rs
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
//! This module provides the Gf256 type which is used to represent
|
||||||
|
//! elements of a finite field witch 256 elements.
|
||||||
|
|
||||||
|
use std::num::Wrapping;
|
||||||
|
use std::ops::{Add, Div, Mul, Sub};
|
||||||
|
use std::sync::Once;
|
||||||
|
|
||||||
|
const POLY: u8 = 0x1D; // represents x^8 + x^4 + x^3 + x^2 + 1
|
||||||
|
|
||||||
|
/// replicates the least significant bit to every other bit
|
||||||
|
#[inline]
|
||||||
|
fn mask(bit: u8) -> u8 {
|
||||||
|
(Wrapping(0u8) - Wrapping(bit & 1)).0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// multiplies a polynomial with x and returns the residual
|
||||||
|
/// of the polynomial division with POLY as divisor
|
||||||
|
#[inline]
|
||||||
|
fn xtimes(poly: u8) -> u8 {
|
||||||
|
(poly << 1) ^ (mask(poly >> 7) & POLY)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Tables used for multiplication and division
|
||||||
|
struct Tables {
|
||||||
|
exp: [u8; 256],
|
||||||
|
log: [u8; 256],
|
||||||
|
inv: [u8; 256],
|
||||||
|
}
|
||||||
|
|
||||||
|
static INIT: Once = Once::new();
|
||||||
|
static mut TABLES: Tables = Tables {
|
||||||
|
exp: [0; 256],
|
||||||
|
log: [0; 256],
|
||||||
|
inv: [0; 256],
|
||||||
|
};
|
||||||
|
|
||||||
|
fn get_tables() -> &'static Tables {
|
||||||
|
INIT.call_once(|| {
|
||||||
|
// mutable access is fine because of synchronization via INIT
|
||||||
|
let tabs = unsafe { &mut TABLES };
|
||||||
|
let mut tmp = 1;
|
||||||
|
for power in 0..255usize {
|
||||||
|
tabs.exp[power] = tmp;
|
||||||
|
tabs.log[tmp as usize] = power as u8;
|
||||||
|
tmp = xtimes(tmp);
|
||||||
|
}
|
||||||
|
tabs.exp[255] = 1;
|
||||||
|
for x in 1..256usize {
|
||||||
|
let l = tabs.log[x];
|
||||||
|
let nl = if l == 0 { 0 } else { 255 - l };
|
||||||
|
let i = tabs.exp[nl as usize];
|
||||||
|
tabs.inv[x] = i;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// We're guaranteed to have TABLES initialized by now
|
||||||
|
return unsafe { &TABLES };
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Type for elements of a finite field with 256 elements
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
|
pub struct Gf256 {
|
||||||
|
pub poly: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Gf256 {
|
||||||
|
/// returns the additive neutral element of the field
|
||||||
|
#[inline]
|
||||||
|
pub fn zero() -> Gf256 {
|
||||||
|
Gf256 { poly: 0 }
|
||||||
|
}
|
||||||
|
/// returns the multiplicative neutral element of the field
|
||||||
|
#[inline]
|
||||||
|
pub fn one() -> Gf256 {
|
||||||
|
Gf256 { poly: 1 }
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn from_byte(b: u8) -> Gf256 {
|
||||||
|
Gf256 { poly: b }
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn to_byte(&self) -> u8 {
|
||||||
|
self.poly
|
||||||
|
}
|
||||||
|
pub fn log(&self) -> Option<u8> {
|
||||||
|
if self.poly == 0 {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
let tabs = get_tables();
|
||||||
|
Some(tabs.log[self.poly as usize])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn exp(power: u8) -> Gf256 {
|
||||||
|
let tabs = get_tables();
|
||||||
|
Gf256 { poly: tabs.exp[power as usize] }
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
pub fn inv(&self) -> Option<Gf256> {
|
||||||
|
self.log().map(|l| Gf256::exp(255 - l))
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Add<Gf256> for Gf256 {
|
||||||
|
type Output = Gf256;
|
||||||
|
#[inline]
|
||||||
|
fn add(self, rhs: Gf256) -> Gf256 {
|
||||||
|
Gf256::from_byte(self.poly ^ rhs.poly)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sub<Gf256> for Gf256 {
|
||||||
|
type Output = Gf256;
|
||||||
|
#[inline]
|
||||||
|
fn sub(self, rhs: Gf256) -> Gf256 {
|
||||||
|
Gf256::from_byte(self.poly ^ rhs.poly)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Mul<Gf256> for Gf256 {
|
||||||
|
type Output = Gf256;
|
||||||
|
fn mul(self, rhs: Gf256) -> Gf256 {
|
||||||
|
if let (Some(l1), Some(l2)) = (self.log(), rhs.log()) {
|
||||||
|
let tmp = ((l1 as u16) + (l2 as u16)) % 255;
|
||||||
|
Gf256::exp(tmp as u8)
|
||||||
|
} else {
|
||||||
|
Gf256 { poly: 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Div<Gf256> for Gf256 {
|
||||||
|
type Output = Gf256;
|
||||||
|
fn div(self, rhs: Gf256) -> Gf256 {
|
||||||
|
let l2 = rhs.log().expect("division by zero");
|
||||||
|
if let Some(l1) = self.log() {
|
||||||
|
let tmp = ((l1 as u16) + 255 - (l2 as u16)) % 255;
|
||||||
|
Gf256::exp(tmp as u8)
|
||||||
|
} else {
|
||||||
|
Gf256 { poly: 0 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
340
__crypto/secretshare/src/main.rs
Normal file
340
__crypto/secretshare/src/main.rs
Normal file
@@ -0,0 +1,340 @@
|
|||||||
|
use std::convert;
|
||||||
|
use std::env;
|
||||||
|
use std::error;
|
||||||
|
use std::fmt;
|
||||||
|
use std::io;
|
||||||
|
use std::io::prelude::*;
|
||||||
|
use std::iter::repeat;
|
||||||
|
use std::num;
|
||||||
|
|
||||||
|
use getopts::Options;
|
||||||
|
use rand::RngCore;
|
||||||
|
use rustc_serialize::base64::{self, FromBase64, ToBase64};
|
||||||
|
|
||||||
|
use gf256::Gf256;
|
||||||
|
|
||||||
|
mod gf256;
|
||||||
|
|
||||||
|
fn new_vec<T: Clone>(n: usize, x: T) -> Vec<T> {
|
||||||
|
repeat(x).take(n).collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Error {
|
||||||
|
descr: &'static str,
|
||||||
|
detail: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Error {
|
||||||
|
fn new(descr: &'static str, detail: Option<String>) -> Error {
|
||||||
|
Error { descr: descr, detail: detail }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
match self.detail {
|
||||||
|
None => write!(f, "{}", self.descr),
|
||||||
|
Some(ref detail) => write!(f, "{} ({})", self.descr, detail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl error::Error for Error {
|
||||||
|
fn description(&self) -> &str { self.descr }
|
||||||
|
fn cause(&self) -> Option<&dyn error::Error> { None }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl convert::From<Error> for io::Error {
|
||||||
|
fn from(me: Error) -> io::Error {
|
||||||
|
io::Error::new(io::ErrorKind::Other, me)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// a try!-like macro for Option<T> expressions that takes
|
||||||
|
// a &'static str as error message as 2nd parameter
|
||||||
|
// and creates an Error out of it if necessary.
|
||||||
|
macro_rules! otry {
|
||||||
|
($o:expr, $e:expr) => (
|
||||||
|
match $o {
|
||||||
|
Some(thing_) => thing_,
|
||||||
|
None => return Err(convert::From::from(Error::new($e, None)))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// maps a ParseIntError to an io::Error
|
||||||
|
fn pie2io(p: num::ParseIntError) -> io::Error {
|
||||||
|
convert::From::from(
|
||||||
|
Error::new("Integer parsing error", Some(p.to_string()))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn other_io_err(descr: &'static str, detail: Option<String>) -> io::Error {
|
||||||
|
convert::From::from(
|
||||||
|
Error::new(descr, detail)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// evaluates a polynomial at x=1, 2, 3, ... n (inclusive)
|
||||||
|
fn encode<W: Write>(src: &[u8], n: u8, w: &mut W) -> io::Result<()> {
|
||||||
|
for raw_x in 1..((n as u16) + 1) {
|
||||||
|
let x = Gf256::from_byte(raw_x as u8);
|
||||||
|
let mut fac = Gf256::one();
|
||||||
|
let mut acc = Gf256::zero();
|
||||||
|
for &coeff in src.iter() {
|
||||||
|
acc = acc + fac * Gf256::from_byte(coeff);
|
||||||
|
fac = fac * x;
|
||||||
|
}
|
||||||
|
w.write(&[acc.to_byte()])?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// evaluates an interpolated polynomial at `raw_x` where
|
||||||
|
/// the polynomial is determined using Lagrangian interpolation
|
||||||
|
/// based on the given x/y coordinates `src`.
|
||||||
|
fn lagrange_interpolate(src: &[(u8, u8)], raw_x: u8) -> u8 {
|
||||||
|
let x = Gf256::from_byte(raw_x);
|
||||||
|
let mut sum = Gf256::zero();
|
||||||
|
for (i, &(raw_xi, raw_yi)) in src.iter().enumerate() {
|
||||||
|
let xi = Gf256::from_byte(raw_xi);
|
||||||
|
let yi = Gf256::from_byte(raw_yi);
|
||||||
|
let mut lix = Gf256::one();
|
||||||
|
for (j, &(raw_xj, _)) in src.iter().enumerate() {
|
||||||
|
if i != j {
|
||||||
|
let xj = Gf256::from_byte(raw_xj);
|
||||||
|
let delta = xi - xj;
|
||||||
|
assert!(delta.poly != 0, "Duplicate shares");
|
||||||
|
lix = lix * (x - xj) / delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sum = sum + lix * yi;
|
||||||
|
}
|
||||||
|
sum.to_byte()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn secret_share(src: &[u8], k: u8, n: u8) -> io::Result<Vec<Vec<u8>>> {
|
||||||
|
let mut result = Vec::with_capacity(n as usize);
|
||||||
|
for _ in 0..(n as usize) {
|
||||||
|
result.push(new_vec(src.len(), 0u8));
|
||||||
|
}
|
||||||
|
let mut col_in = new_vec(k as usize, 0u8);
|
||||||
|
let mut col_out = Vec::with_capacity(n as usize);
|
||||||
|
let mut osrng = rand::thread_rng();
|
||||||
|
for (c, &s) in src.iter().enumerate() {
|
||||||
|
col_in[0] = s;
|
||||||
|
osrng.fill_bytes(&mut col_in[1..]);
|
||||||
|
col_out.clear();
|
||||||
|
encode(&*col_in, n, &mut col_out)?;
|
||||||
|
for (&y, share) in col_out.iter().zip(result.iter_mut()) {
|
||||||
|
share[c] = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Action {
|
||||||
|
Encode(u8, u8),
|
||||||
|
// k and n parameter
|
||||||
|
Decode,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_k_n(s: &str) -> io::Result<(u8, u8)> {
|
||||||
|
let mut iter = s.split(',');
|
||||||
|
let msg = "K and N have to be separated with a comma";
|
||||||
|
let s1 = otry!(iter.next(), msg).trim();
|
||||||
|
let s2 = otry!(iter.next(), msg).trim();
|
||||||
|
let k = s1.parse().map_err(pie2io)?;
|
||||||
|
let n = s2.parse().map_err(pie2io)?;
|
||||||
|
Ok((k, n))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// computes a CRC-24 hash over the concatenated coding parameters k, n
|
||||||
|
/// and the raw share data
|
||||||
|
fn crc24_as_bytes(k: u8, n: u8, octets: &[u8]) -> [u8; 3] {
|
||||||
|
use std::hash::Hasher;
|
||||||
|
|
||||||
|
let mut h = crc24::Crc24Hasher::new();
|
||||||
|
h.write(&[k, n]);
|
||||||
|
h.write(octets);
|
||||||
|
let v = h.finish();
|
||||||
|
|
||||||
|
[((v >> 16) & 0xFF) as u8,
|
||||||
|
((v >> 8) & 0xFF) as u8,
|
||||||
|
(v & 0xFF) as u8]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn perform_encode(k: u8, n: u8, with_checksums: bool) -> io::Result<()> {
|
||||||
|
let secret = {
|
||||||
|
let limit: usize = 0x10000;
|
||||||
|
let stdin = io::stdin();
|
||||||
|
let mut locked = stdin.lock();
|
||||||
|
let mut tmp: Vec<u8> = Vec::new();
|
||||||
|
locked.by_ref().take(limit as u64).read_to_end(&mut tmp)?;
|
||||||
|
if tmp.len() == limit {
|
||||||
|
let mut dummy = [0u8];
|
||||||
|
if locked.read(&mut dummy)? > 0 {
|
||||||
|
return Err(other_io_err("Secret too large",
|
||||||
|
Some(format!("My limit is at {} bytes.", limit))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tmp
|
||||||
|
};
|
||||||
|
let shares = secret_share(&*secret, k, n)?;
|
||||||
|
let config = base64::Config {
|
||||||
|
pad: false,
|
||||||
|
..base64::STANDARD
|
||||||
|
};
|
||||||
|
for (index, share) in shares.iter().enumerate() {
|
||||||
|
let salad = share.to_base64(config);
|
||||||
|
if with_checksums {
|
||||||
|
let crc_bytes = crc24_as_bytes(k, (index + 1) as u8, &**share);
|
||||||
|
println!("{}-{}-{}-{}", k, index + 1, salad, crc_bytes.to_base64(config));
|
||||||
|
} else {
|
||||||
|
println!("{}-{}-{}", k, index + 1, salad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// reads shares from stdin and returns Ok(k, shares) on success
|
||||||
|
/// where shares is a Vec<(u8, Vec<u8>)> representing x-coordinates
|
||||||
|
/// and share data.
|
||||||
|
fn read_shares() -> io::Result<(u8, Vec<(u8, Vec<u8>)>)> {
|
||||||
|
let stdin = io::stdin();
|
||||||
|
let stdin = io::BufReader::new(stdin.lock());
|
||||||
|
let mut opt_k_l: Option<(u8, usize)> = None;
|
||||||
|
let mut counter = 0u8;
|
||||||
|
let mut shares: Vec<(u8, Vec<u8>)> = Vec::new();
|
||||||
|
for line in stdin.lines() {
|
||||||
|
let line = line?;
|
||||||
|
let parts: Vec<_> = line.trim().split('-').collect();
|
||||||
|
if parts.len() < 3 || parts.len() > 4 {
|
||||||
|
return Err(other_io_err("Share parse error: Expected 3 or 4 \
|
||||||
|
parts searated by a minus sign", None));
|
||||||
|
}
|
||||||
|
let (k, n, p3, opt_p4) = {
|
||||||
|
let mut iter = parts.into_iter();
|
||||||
|
let k = iter.next().unwrap().parse::<u8>().map_err(pie2io)?;
|
||||||
|
let n = iter.next().unwrap().parse::<u8>().map_err(pie2io)?;
|
||||||
|
let p3 = iter.next().unwrap();
|
||||||
|
let opt_p4 = iter.next();
|
||||||
|
(k, n, p3, opt_p4)
|
||||||
|
};
|
||||||
|
if k < 1 || n < 1 {
|
||||||
|
return Err(other_io_err("Share parse error: Illegal K,N parameters", None));
|
||||||
|
}
|
||||||
|
let data = p3.from_base64().map_err(|_| other_io_err(
|
||||||
|
"Share parse error: Base64 decoding of data block failed", None))?;
|
||||||
|
if let Some(check) = opt_p4 {
|
||||||
|
if check.len() != 4 {
|
||||||
|
return Err(other_io_err("Share parse error: Checksum part is \
|
||||||
|
expected to be four characters", None));
|
||||||
|
}
|
||||||
|
let crc_bytes = check.from_base64().map_err(|_| other_io_err(
|
||||||
|
"Share parse error: Base64 decoding of checksum failed", None))?;
|
||||||
|
let mychksum = crc24_as_bytes(k, n, &*data);
|
||||||
|
if crc_bytes != mychksum {
|
||||||
|
return Err(other_io_err("Share parse error: Checksum mismatch", None));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some((ck, cl)) = opt_k_l {
|
||||||
|
if ck != k || cl != data.len() {
|
||||||
|
return Err(other_io_err("Incompatible shares", None));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
opt_k_l = Some((k, data.len()));
|
||||||
|
}
|
||||||
|
if shares.iter().all(|s| s.0 != n) {
|
||||||
|
shares.push((n, data));
|
||||||
|
counter += 1;
|
||||||
|
if counter == k {
|
||||||
|
return Ok((k, shares));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(other_io_err("Not enough shares provided!", None))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn perform_decode() -> io::Result<()> {
|
||||||
|
let (k, shares) = read_shares()?;
|
||||||
|
assert!(!shares.is_empty());
|
||||||
|
let slen = shares[0].1.len();
|
||||||
|
let mut col_in = Vec::with_capacity(k as usize);
|
||||||
|
let mut secret = Vec::with_capacity(slen);
|
||||||
|
for byteindex in 0..slen {
|
||||||
|
col_in.clear();
|
||||||
|
for s in shares.iter().take(k as usize) {
|
||||||
|
col_in.push((s.0, s.1[byteindex]));
|
||||||
|
}
|
||||||
|
secret.push(lagrange_interpolate(&*col_in, 0u8));
|
||||||
|
}
|
||||||
|
let mut out = io::stdout();
|
||||||
|
out.write_all(&*secret)?;
|
||||||
|
out.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut stderr = io::stderr();
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
|
let mut opts = Options::new();
|
||||||
|
opts.optflag("h", "help", "print this help text");
|
||||||
|
opts.optflag("d", "decode", "for decoding");
|
||||||
|
opts.optopt("e", "encode", "for encoding, K is the required number of \
|
||||||
|
shares for decoding, N is the number of shares \
|
||||||
|
to generate. 1 <= K <= N <= 255", "K,N");
|
||||||
|
let opt_matches = match opts.parse(&args[1..]) {
|
||||||
|
Ok(m) => m,
|
||||||
|
Err(f) => {
|
||||||
|
drop(writeln!(&mut stderr, "Error: {}", f));
|
||||||
|
// env::set_exit_status(1); // FIXME: unstable feature
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if args.len() < 2 || opt_matches.opt_present("h") {
|
||||||
|
println!(
|
||||||
|
"The program secretshare is an implementation of Shamir's secret sharing scheme.\n\
|
||||||
|
It is applied byte-wise within a finite field for arbitrarily long secrets.\n");
|
||||||
|
println!("{}", opts.usage("Usage: secretshare [options]"));
|
||||||
|
println!("Input is read from STDIN and output is written to STDOUT.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let action: Result<_, _> =
|
||||||
|
match (opt_matches.opt_present("e"), opt_matches.opt_present("d")) {
|
||||||
|
(false, false) => Err("Nothing to do! Use -e or -d"),
|
||||||
|
(true, true) => Err("Use either -e or -d and not both"),
|
||||||
|
(false, true) => Ok(Action::Decode),
|
||||||
|
(true, false) => {
|
||||||
|
if let Some(param) = opt_matches.opt_str("e") {
|
||||||
|
if let Ok((k, n)) = parse_k_n(&*param) {
|
||||||
|
if 0 < k && k <= n {
|
||||||
|
Ok(Action::Encode(k, n))
|
||||||
|
} else {
|
||||||
|
Err("Invalid encoding parameters K,N")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err("Could not parse K,N parameters")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err("No parameter for -e or -d provided")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let result =
|
||||||
|
match action {
|
||||||
|
Ok(Action::Encode(k, n)) => perform_encode(k, n, true),
|
||||||
|
Ok(Action::Decode) => perform_decode(),
|
||||||
|
Err(e) => Err(other_io_err(e, None))
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(e) = result {
|
||||||
|
drop(writeln!(&mut stderr, "{}", e));
|
||||||
|
// env::set_exit_status(1); // FIXME: unstable feature
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
95
__crypto/shamir-demo/Cargo.lock
generated
Normal file
95
__crypto/shamir-demo/Cargo.lock
generated
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.1.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.139"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ppv-lite86"
|
||||||
|
version = "0.2.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.7.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
"libc",
|
||||||
|
"rand_chacha",
|
||||||
|
"rand_core",
|
||||||
|
"rand_hc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_hc"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
|
||||||
|
dependencies = [
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shamir"
|
||||||
|
version = "2.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f3334e0accec0ef99f58b5d46fb41c32395f6531dde1e5f5c366e79e50dfe317"
|
||||||
|
dependencies = [
|
||||||
|
"rand",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shamir-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"shamir",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.9.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
|
||||||
9
__crypto/shamir-demo/Cargo.toml
Normal file
9
__crypto/shamir-demo/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "shamir-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
shamir = "2.0.0"
|
||||||
16
__crypto/shamir-demo/src/main.rs
Normal file
16
__crypto/shamir-demo/src/main.rs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
use shamir::SecretData;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let secret_data = SecretData::with_secret("Hello World!", 3);
|
||||||
|
|
||||||
|
let share1 = secret_data.get_share(1).unwrap();
|
||||||
|
let share2 = secret_data.get_share(2).unwrap();
|
||||||
|
let share3 = secret_data.get_share(3).unwrap();
|
||||||
|
let share4 = secret_data.get_share(4).unwrap();
|
||||||
|
|
||||||
|
println!("{:?}\n{:?}\n{:?}\n{:?}", share1, share2, share3, share4);
|
||||||
|
let recovered = SecretData::recover_secret(3, vec![share1, share2, share3]).unwrap();
|
||||||
|
|
||||||
|
println!("Recovered: {}", recovered);
|
||||||
|
}
|
||||||
|
|
||||||
1421
__crypto/yubikey-rs-demo/Cargo.lock
generated
Normal file
1421
__crypto/yubikey-rs-demo/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
15
__crypto/yubikey-rs-demo/Cargo.toml
Normal file
15
__crypto/yubikey-rs-demo/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
[package]
|
||||||
|
name = "yubikey-rs-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
elliptic-curve = { version = "0.13.2", features = ["sec1"] }
|
||||||
|
hex = "0.4.3"
|
||||||
|
p256 = { version = "0.13.0", features = ["ecdh", "pem"] }
|
||||||
|
rand = "0.8.5"
|
||||||
|
rust_util = "0.6.41"
|
||||||
|
sha2 = "0.10.6"
|
||||||
|
yubikey = { version = "0.7.0", features = ["untested"] }
|
||||||
127
__crypto/yubikey-rs-demo/src/main.rs
Normal file
127
__crypto/yubikey-rs-demo/src/main.rs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
use elliptic_curve::rand_core::{CryptoRng, Error, RngCore};
|
||||||
|
use p256::{ecdh::EphemeralSecret, PublicKey};
|
||||||
|
use p256::elliptic_curve::sec1::{FromEncodedPoint, ToEncodedPoint};
|
||||||
|
use rust_util::{failure_and_exit, information, warning, XResult};
|
||||||
|
use yubikey::certificate::PublicKeyInfo;
|
||||||
|
use yubikey::Context;
|
||||||
|
use yubikey::piv::{AlgorithmId, decrypt_data, metadata, RetiredSlotId, SlotId};
|
||||||
|
|
||||||
|
// const EPK_BYTES: usize = 33;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub(crate) struct EphemeralKeyBytes(p256::EncodedPoint);
|
||||||
|
|
||||||
|
impl EphemeralKeyBytes {
|
||||||
|
// fn from_bytes(bytes: [u8; EPK_BYTES]) -> Option<Self> {
|
||||||
|
// let encoded = p256::EncodedPoint::from_bytes(&bytes).ok()?;
|
||||||
|
// if encoded.is_compressed()
|
||||||
|
// && p256::PublicKey::from_encoded_point(&encoded)
|
||||||
|
// .is_some()
|
||||||
|
// .into()
|
||||||
|
// {
|
||||||
|
// Some(EphemeralKeyBytes(encoded))
|
||||||
|
// } else {
|
||||||
|
// None
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
fn from_public_key(epk: &p256::PublicKey) -> Self {
|
||||||
|
EphemeralKeyBytes(epk.to_encoded_point(true))
|
||||||
|
}
|
||||||
|
|
||||||
|
// pub(crate) fn as_bytes(&self) -> &[u8] {
|
||||||
|
// self.0.as_bytes()
|
||||||
|
// }
|
||||||
|
|
||||||
|
pub(crate) fn decompress(&self) -> p256::EncodedPoint {
|
||||||
|
// EphemeralKeyBytes is a valid compressed encoding by construction.
|
||||||
|
let p = p256::PublicKey::from_encoded_point(&self.0).unwrap();
|
||||||
|
p.to_encoded_point(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct FakeRandom;
|
||||||
|
|
||||||
|
impl CryptoRng for FakeRandom {}
|
||||||
|
|
||||||
|
impl RngCore for FakeRandom {
|
||||||
|
fn next_u32(&mut self) -> u32 {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_u64(&mut self) -> u64 {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fill_bytes(&mut self, dest: &mut [u8]) {
|
||||||
|
println!("Fill random dest len: {}", dest.len());
|
||||||
|
for i in 0..dest.len() {
|
||||||
|
dest[i]= 0x01;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_fill_bytes(&mut self, _dest: &mut [u8]) -> Result<(), Error> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn main() -> XResult<()> {
|
||||||
|
let mut readers = Context::open()?;
|
||||||
|
let reader = readers.iter()?.next().unwrap_or_else(|| failure_and_exit!("No reader!"));
|
||||||
|
let mut yubikey = reader.open()?;
|
||||||
|
|
||||||
|
information!("Yubikey serial: {}", yubikey.serial().0);
|
||||||
|
|
||||||
|
// let esk = EphemeralSecret::random(&mut rand::rngs::OsRng);
|
||||||
|
let esk = EphemeralSecret::random(&mut FakeRandom);
|
||||||
|
let epk = esk.public_key();
|
||||||
|
let epk_bytes = EphemeralKeyBytes::from_public_key(&epk);
|
||||||
|
|
||||||
|
let public_key_pem = r#"-----BEGIN PUBLIC KEY-----
|
||||||
|
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE3T7r2QbJzwCwjsKfftYYBNHMHRNS
|
||||||
|
2SV7YoGR4I/DcXxPrjKYzVxIKc7IvzqUbn22C3hX4Sh/aguuaz8jQvAH0A==
|
||||||
|
-----END PUBLIC KEY-----"#;
|
||||||
|
let public_key = public_key_pem.parse::<PublicKey>().unwrap();
|
||||||
|
|
||||||
|
// let encoded_point = p256::EncodedPoint::from_bytes(&hex::decode(
|
||||||
|
// "04dd3eebd906c9cf00b08ec29f7ed61804d1cc1d1352d9257b628191e08fc3717c4fae3298cd5c4829cec8bf3a946e7db60b7857e1287f6a0bae6b3f2342f007d0"
|
||||||
|
// )?)?;
|
||||||
|
// let public_key = PublicKey::from_encoded_point(&encoded_point).unwrap();
|
||||||
|
|
||||||
|
let shared_secret = esk.diffie_hellman(&public_key);
|
||||||
|
information!("Shared secret: {}", hex::encode(shared_secret.raw_secret_bytes()));
|
||||||
|
|
||||||
|
let meta_result = metadata(&mut yubikey, SlotId::Retired(RetiredSlotId::R1));
|
||||||
|
match meta_result {
|
||||||
|
Ok(meta) => {
|
||||||
|
information!("{:?}", meta);
|
||||||
|
if let Some(public_key) = &meta.public {
|
||||||
|
match public_key {
|
||||||
|
PublicKeyInfo::Rsa { algorithm, pubkey } => {
|
||||||
|
information!("RSA, {:?}, {:?}", algorithm, pubkey);
|
||||||
|
}
|
||||||
|
PublicKeyInfo::EcP256(pubkey) => {
|
||||||
|
information!("EC-P256, {}", hex::encode(pubkey.as_bytes()));
|
||||||
|
}
|
||||||
|
PublicKeyInfo::EcP384(pubkey) => {
|
||||||
|
information!("EC-P384, {}", hex::encode(pubkey.as_bytes()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => warning!("Get slot meta failed: {}", e)
|
||||||
|
}
|
||||||
|
yubikey.verify_pin(b"123456").expect("Verify pin!");
|
||||||
|
let decrypted_shared_secret = decrypt_data(
|
||||||
|
&mut yubikey,
|
||||||
|
epk_bytes.decompress().as_bytes(),
|
||||||
|
AlgorithmId::EccP256,
|
||||||
|
SlotId::Retired(RetiredSlotId::R1),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
information!("Decrypted shared secret: {}", hex::encode(&decrypted_shared_secret.to_vec()));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
1442
__database/duckdb-demo/Cargo.lock
generated
Normal file
1442
__database/duckdb-demo/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
10
__database/duckdb-demo/Cargo.toml
Normal file
10
__database/duckdb-demo/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "duckdb-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
duckdb = { version = "0.10", features = ["bundled"] }
|
||||||
|
|
||||||
55
__database/duckdb-demo/src/main.rs
Normal file
55
__database/duckdb-demo/src/main.rs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
use duckdb::{params, Connection, Result};
|
||||||
|
|
||||||
|
use duckdb::arrow::record_batch::RecordBatch;
|
||||||
|
use duckdb::arrow::util::pretty::print_batches;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Person {
|
||||||
|
id: i32,
|
||||||
|
name: String,
|
||||||
|
data: Option<Vec<u8>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let conn = Connection::open_in_memory()?;
|
||||||
|
|
||||||
|
conn.execute_batch(
|
||||||
|
r"CREATE SEQUENCE seq;
|
||||||
|
CREATE TABLE person (
|
||||||
|
id INTEGER PRIMARY KEY DEFAULT NEXTVAL('seq'),
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
data BLOB
|
||||||
|
);
|
||||||
|
")?;
|
||||||
|
|
||||||
|
let me = Person {
|
||||||
|
id: 0,
|
||||||
|
name: "Steven".to_string(),
|
||||||
|
data: None,
|
||||||
|
};
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO person (name, data) VALUES (?, ?)",
|
||||||
|
params![me.name, me.data],
|
||||||
|
)?;
|
||||||
|
|
||||||
|
// query table by rows
|
||||||
|
let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
|
||||||
|
let person_iter = stmt.query_map([], |row| {
|
||||||
|
Ok(Person {
|
||||||
|
id: row.get(0)?,
|
||||||
|
name: row.get(1)?,
|
||||||
|
data: row.get(2)?,
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
for person in person_iter {
|
||||||
|
let p = person.unwrap();
|
||||||
|
println!("ID: {}", p.id);
|
||||||
|
println!("Found person {:?}", p);
|
||||||
|
}
|
||||||
|
|
||||||
|
// query table by arrow
|
||||||
|
let rbs: Vec<RecordBatch> = stmt.query_arrow([])?.collect();
|
||||||
|
print_batches(&rbs).unwrap();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user