dongre6270 2013-12-05 22:17
浏览 30
已采纳

试图从Go理解此功能,为什么要使一个功能始终保持恒定运行,它又如何工作呢?

I was encounter the following function crypto/subtle package which caused me a lot curiosity, wish someone can explain the purpose behind it. Thanks,

// ConstantTimeByteEq returns 1 if x == y and 0 otherwise.
    27  func ConstantTimeByteEq(x, y uint8) int {
    28      z := ^(x ^ y)
    29      z &= z >> 4
    30      z &= z >> 2
    31      z &= z >> 1
    32  
    33      return int(z)
    34  }
  • 写回答

1条回答 默认 最新

  • dongxie2613 2013-12-05 22:43
    关注

    It prevents timing attacks against cryptosystems: Any code path takes exactly the same amount of time.

    If you are careless about timing you open up a sidechannel which leaks information about your secret. E.g. you could determine that the first character of a password is 'R' because the system fails 10ns faster if your wrong password starts with 'R'. Repeat with next character until you found the password.

    Implementing cryptography is really hard. Really really hard.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表