0

How does AESCrypt handle the initialization vector (IV) for file format 2?

It seems like you cannot specify an IV when generating a file... so I'm assuming that the IV is stored unencrypted next to the ciphertext?

It's open source. I took a quick look at the code and it wasn't immediately clear.

This link references an IV1... but it's not fully clear. Where does IV1 come from?

4

1 回答 1

2

我只是环顾了一下它,大部分情况下我确实理解它。我会尽我所能回答你的问题。

1) AESCrypt 每次加密使用 2 个 IV。它们有一个密钥,IV 对用于加密消息的大部分,它们是 Key2 和 IV2,它们还有一个密钥,IV 对仅用于加密 Key2 和 IV2,它们称为 Key1 和 IV1。Key1 当然不是加密文件的一部分,但 IV1 确实未加密地存储在您链接的灰色框底部附近的 16 个八位字节中。紧随其后的 48 个八位字节是已加密的 Key2 和 IV2。IV(尤其是 IV1)不加密是可以的。它使相同的 16 字节数据块几乎不可能每次出现在密文中时看起来都一样。但是,IV 完全没有必要保密。我真的很惊讶他们将 IV2 保密(加密),但他们这样做并没有什么害处。

2) 是的,我想我已经回答了这个问题,但是 IV1 在每个格式 2 规范的文件的 16 个八位字节块中未加密,而 IV2 在之后的 48 个八位字节中使用 Key2 加密。

3 &4 我会一起回答。你可能见过 IV2 的函数,它只是一个直接生成字节的随机函数。IV1 以更复杂的方式生成。我将在这里发布最相关的代码。

因此,如果您仔细查看,程序会抓取它可以在网络上找到的设备。然后它遍历它们,寻找一个具有它可以使用的 MAC 地址的地址。如果它没有找到它可以使用的,它使用 DEFAULT_MAC,它是程序中其他地方定义的常量,作为数组 {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}。

现在它需要当前的日期和时间,并用它填充原始 IV 的 8 个字节。然后它使用它找到的任何 MAC 并使用它在同一个原始 IV 数组中填充更多字节。

完成后,它将这个原始数组发送到 DigestRandomBytes 方法,在该方法中,根据代码(该代码块不包括在此处),该方法重复一个循环 256 次以获取加密安全的随机字节,然后使用 SHA-256 对它们进行哈希处理。让我担心的一件事——只有一点点——是我看不到 MAC 和日期时间刻度字节如何在 DigestRandomBytes 方法中幸存下来,或者根本没有帮助增加其输出的熵。它们被发送到 DigestRandomBytes 方法,但它似乎丢弃它们并用随机字节替换它们,并且它这样做了 256 次。

无论如何,是的,IV1 是随机生成的。

        private byte[] GenerateIv1()
        {
            byte[] iv = new byte[IV_SIZE];
            long time = DateTime.Now.Ticks;
            byte[] mac = null;

            /**********************************************************************
            *                                                                     *
            *   NOTE: The time and mac are COMPONENTS in the random IV input.     *
            *         The IV does not require the time or mac to be random.       *
            *                                                                     *
            *         The mac and time are used to INCREASE the ENTROPY, and      *
            *         DECOUPLE the IV from the PRNG output, in case the PRNG      *
            *         has a defect (intentional or not)                           *
            *                                                                     *
            *         Please review the DigestRandomBytes method before           *
            *         INCORRECTLY ASSUMING that the IV is generated from          *
            *         time and mac inputs.                                        *
            *                                                                     *
            ***********************************************************************/                

            try
            {
                System.Net.NetworkInformation.NetworkInterface[] interfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
                for (int i = 0; i < interfaces.Length; i++)
                    if (i != System.Net.NetworkInformation.NetworkInterface.LoopbackInterfaceIndex)
                    {
                        mac = interfaces[i].GetPhysicalAddress().GetAddressBytes();
                        break;
                    }
            }
            catch
            {
                //Not much to do, just go with default MAC
            }

            if (mac == null)
                mac = DEFAULT_MAC;

            for (int i = 0; i < 8; i++)
                iv[i] = (byte)((time >> (i * 8)) & 0xff);

            Array.Copy(mac, 0, iv, 8, Math.Min(mac.Length, iv.Length - 8));
            return DigestRandomBytes(iv, 256);
        }
于 2015-08-09T07:57:19.277 回答