【问题标题】:Libsodium - use crypto_box_easy where receiver and sender are the sameLibsodium - 在接收方和发送方相同的地方使用 crypto_box_easy
【发布时间】:2023-01-26 23:25:43
【问题描述】:

我想使用 libsodium 来加密小消息/秘密并在不同用户之间共享它们。如果接收方和发送方不同,API 很简单。但是,当我也想允许用户为自己的东西加密并将它们存储在云中时,会发生什么?

#define MESSAGE (const unsigned char *) "test"
#define MESSAGE_LEN 4
#define CIPHERTEXT_LEN (crypto_box_MACBYTES + MESSAGE_LEN)

unsigned char alice_publickey[crypto_box_PUBLICKEYBYTES];
unsigned char alice_secretkey[crypto_box_SECRETKEYBYTES];
crypto_box_keypair(alice_publickey, alice_secretkey);

unsigned char nonce[crypto_box_NONCEBYTES];
unsigned char ciphertext[CIPHERTEXT_LEN];
randombytes_buf(nonce, sizeof nonce);
if (crypto_box_easy(ciphertext, MESSAGE, MESSAGE_LEN, nonce,
                    alice_publickey, alice_secretkey) != 0) {
    /* error */
}

unsigned char decrypted[MESSAGE_LEN];
if (crypto_box_open_easy(decrypted, ciphertext, CIPHERTEXT_LEN, nonce,
                         alice_publickey, alice_secretkey) != 0) {
    /* message for Bob pretending to be from Alice has been forged! */
}

这是否会破坏引擎盖下的算法?因为在那种情况下使用了 Diffie Hellmann,从我的角度来看,至少 Diffie Hellmann 不是为这种用例设计的,我很担心。如果禁止或允许,我找不到任何提示。

【问题讨论】:

    标签: encryption diffie-hellman libsodium


    【解决方案1】:

    这似乎是可能的,因为从数学上讲它并没有削弱算法。来源:https://crypto.stackexchange.com/questions/103925/ecdh-between-identical-public-keys

    【讨论】:

      猜你喜欢
      • 2011-07-26
      • 2016-01-09
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多