【问题标题】:Basic group arithmetic in libsodiumlibsodium 中的基本群算术
【发布时间】:2020-02-10 18:47:22
【问题描述】:

我正在尝试实现一个简单的加密原语。

在下面的代码下:给定sa,sk,hn,我想计算sb:使得sg*G = (sb + sk .hn)*G。

但是,在找到 sb 之后,以下等式不成立:sb*G + (sk.hn)G = saG。

我的理解是指数中的算术模数是组的阶数而不是 L。

但是,我对它们的实现有几个问题:

  1. 为什么标量必须从 [0,L] 中选择,其中 L 是子群的阶数?

  2. 是否有一个“辅助”函数可以将两个大标量相乘而不执行模 L?

int main(void)
{
    if (sodium_init() < 0) {
        /* panic! the library couldn't be initialized, it is not safe to use */
        return -1;
    }
    uint8_t sb[crypto_core_ed25519_SCALARBYTES];
    uint8_t sa[crypto_core_ed25519_SCALARBYTES];
    uint8_t hn[crypto_core_ed25519_SCALARBYTES];
    uint8_t sk[crypto_core_ed25519_SCALARBYTES];
    crypto_core_ed25519_scalar_random(sa); // s_a <- [0,l]
    crypto_core_ed25519_scalar_random(sk);  // sk  <- [0,l]
    crypto_core_ed25519_scalar_random(hn);  // hn  <- [0,l]

    uint8_t product[crypto_core_ed25519_SCALARBYTES];
    crypto_core_ed25519_scalar_mul(product, sk,hn);  // sk*hn
    crypto_core_ed25519_scalar_sub(sb, sa, product); // sb = sa-hn*sk

    uint8_t point1[crypto_core_ed25519_BYTES];
    crypto_scalarmult_ed25519_base(point1, sa);

    uint8_t point2[crypto_core_ed25519_BYTES];
    uint8_t sum[crypto_core_ed25519_BYTES];

    // equal
    // crypto_core_ed25519_scalar_add(sum, sb, product);
    // crypto_scalarmult_ed25519_base(point2, sum);

    // is not equal
    uint8_t temp1[crypto_core_ed25519_BYTES];
    uint8_t temp2[crypto_core_ed25519_BYTES];
    crypto_scalarmult_ed25519_base(temp1, sb);      // sb*G
    crypto_scalarmult_ed25519_base(temp2, product); //
    crypto_core_ed25519_add(point2, temp1, temp2);
    if(memcmp(point1, point2, 32) != 0)
    {
        printf("[-] Not equal ");
        return -1;
    }
    printf("[+] equal");

    return 0;
}

【问题讨论】:

    标签: libsodium ed25519


    【解决方案1】:

    我从 libsodium 的作者 jedisct1 那里得到了答案,我会在这里发布:

    crypto_scalarmult_ed25519_base() 在执行乘法之前钳制标量(清除低 3 位,设置高位)。

    使用 crypto_scalarmult_ed25519_base_noclamp() 来防止这种情况发生。

    或者,更好的是,改用 Ristretto 组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 2019-07-21
      • 1970-01-01
      • 2013-10-21
      • 2012-05-18
      • 2015-01-28
      相关资源
      最近更新 更多