【问题标题】:Rust: How to add one to a u8 arrayRust:如何将 1 添加到 u8 数组
【发布时间】:2020-05-05 12:13:59
【问题描述】:

出于学习目的,我在 CTR 模式下在 AES 工作,需要在最后的 ctr 块中添加“一个”。但为了添加一个,我必须将前面代码的结果(aes_encryption 返回 [u8;16])转换为 u128。现在我想把这个 u128 转换回一个数组。有没有可能这样做? 我的替代想法是使用std::collections::BitVecsplit_off() 函数将一个直接添加到数组中,我认为这会更简单更快。

【问题讨论】:

标签: arrays math rust aes add


【解决方案1】:

但为了添加一个,我必须将前一个代码的结果(aes_encryption 返回 [u8;16])转换为 u128。现在我想把这个 u128 转换回一个数组。有没有可能这样做?

https://doc.rust-lang.org/std/?search=to_*_bytes

【讨论】:

  • 那是因为 to_bytes 对数字没有意义,因为它没有考虑 endianness,因此为什么 - 如提供的链接中所列 - - 数字有to_be_bytesto_le_bytesto_ne_bytes
猜你喜欢
  • 2020-01-22
  • 2021-03-18
  • 1970-01-01
  • 1970-01-01
  • 2019-11-03
  • 1970-01-01
  • 2021-04-28
  • 2021-03-27
  • 2021-06-21
相关资源
最近更新 更多