发布:RustCrypto: p256
和 k256
v0.2.0: 纯 Rust NIST P-256 和 secp256k1 曲线算法
这个版本用 Rust 实现了如下两个曲线算法。
• p256: NIST P-256
□ GitHub: https://github.com/RustCrypto/elliptic-curves/tree/master/p256
□ crates.io: https://crates.io/crates/p256
□ docs.rs: https://docs.rs/p256/
• k256: secp256k1 (as used by Bitcoin, Ethereum, etc)
□ GitHub: https://github.com/RustCrypto/elliptic-curves/tree/master/k256
□ crates.io: https://crates.io/crates/k256
□ docs.rs: https://docs.rs/k256/
tco: 用过程宏实现的尾递归优化能力
这个思路很清奇——用属性宏来实现尾递归调用优化。类似于下面这个样子:
#[tco::rewrite]
fn fac_with_acc(n: u128, acc: u128) -> u128 {
if n > 1 {
fac_with_acc(n - 1, acc * n)
} else {
acc
}
}
优化后的代码为:
fn fac_with_acc(n: u128, acc: u128) -> u128 {
let mut n = n;
let mut acc = acc;
'__tco_loop: loop {
return {
if n > 1 {
{
let __tco_0 = (n - 1, acc * n);
n = __tco_0.0;
acc = __tco_0.1;
continue '__tco_loop;
}
} else {
acc
}
};
}
}
仓库:https://github.com/samsieber/tco
-- Edit by Rust 日报小组 Mike
1
共 0 条评论, 1 页
评论区
写评论还没有评论