1. <small id='QB4uK'></small><noframes id='QB4uK'>

      <tfoot id='QB4uK'></tfoot>

      <legend id='QB4uK'><style id='QB4uK'><dir id='QB4uK'><q id='QB4uK'></q></dir></style></legend>
        <bdo id='QB4uK'></bdo><ul id='QB4uK'></ul>

      <i id='QB4uK'><tr id='QB4uK'><dt id='QB4uK'><q id='QB4uK'><span id='QB4uK'><b id='QB4uK'><form id='QB4uK'><ins id='QB4uK'></ins><ul id='QB4uK'></ul><sub id='QB4uK'></sub></form><legend id='QB4uK'></legend><bdo id='QB4uK'><pre id='QB4uK'><center id='QB4uK'></center></pre></bdo></b><th id='QB4uK'></th></span></q></dt></tr></i><div id='QB4uK'><tfoot id='QB4uK'></tfoot><dl id='QB4uK'><fieldset id='QB4uK'></fieldset></dl></div>

      在 Visual Studio 2017 中计算 AES/CCM 的时间加密

      时间:2023-07-01

          <small id='Luqec'></small><noframes id='Luqec'>

          <legend id='Luqec'><style id='Luqec'><dir id='Luqec'><q id='Luqec'></q></dir></style></legend>

          • <tfoot id='Luqec'></tfoot>
            <i id='Luqec'><tr id='Luqec'><dt id='Luqec'><q id='Luqec'><span id='Luqec'><b id='Luqec'><form id='Luqec'><ins id='Luqec'></ins><ul id='Luqec'></ul><sub id='Luqec'></sub></form><legend id='Luqec'></legend><bdo id='Luqec'><pre id='Luqec'><center id='Luqec'></center></pre></bdo></b><th id='Luqec'></th></span></q></dt></tr></i><div id='Luqec'><tfoot id='Luqec'></tfoot><dl id='Luqec'><fieldset id='Luqec'></fieldset></dl></div>
              <tbody id='Luqec'></tbody>
              <bdo id='Luqec'></bdo><ul id='Luqec'></ul>
              • 本文介绍了在 Visual Studio 2017 中计算 AES/CCM 的时间加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用库 Crypto++ 5.6.5 和 Visual Studio 2017.

                I am using the library Crypto++ 5.6.5 and Visual Studio 2017.

                如何计算 AES-CCM 的加密时间?

                How can I calculate the encryption time for AES-CCM?

                推荐答案

                我想知道如何计算 AES-CCM 的加密时间.

                I would like to know how to calculate the encryption time for AES-CCM.

                Crypto++ wiki 提供了一篇文章基准.它提供了许多有关库性能、吞吐量计算方式的详细信息,甚至还引用了测量实际吞吐量的源代码.信不信由你,对 clock 的简单调用就可以很好地测量批量加密.另请参阅基准 |时间循环在同一篇维基文章中.

                The Crypto++ wiki provides an article Benchmarks. It provides a lot of details regarding library performance, how throughput is calculated, and it even references the source code where the actual throughput is measured. Believe it or not, a simple call to clock works just fine to measure bulk encryption. Also see Benchmarks | Timing Loop in the same wiki article.

                要对 AES/CCM 进行基准测试,请执行以下操作.它基于 Crypto++ 基准测试代码,但它使用 ThreadUserTimer 而不是直接调用 clock.ThreadUserTimer 适用于所有操作系统和所有版本的 C++.

                To benchmark AES/CCM, do something like the following. It is based on the Crypto++ benchmarking code, but it uses a ThreadUserTimer instead of a direct call to clock. ThreadUserTimer works across all OSes and all versions of C++.

                您需要在 cpuFreq 上拨入您的处理器速度.您应该还运行./Governor.sh perf 将 CPU 从空闲或 C 级睡眠状态移动,但你不能,因为它是一个 Linux 脚本.您可以在 TestScript/ 文件夹中找到它.

                You need to dial-in your processor speed at cpuFreq. You should also run ./governor.sh perf to move the CPU from an idle or C-level sleep state, but you can't because it is a Linux script. You can find it in the TestScript/ folder.

                #include "cryptlib.h"
                #include "secblock.h"
                #include "hrtimer.h"
                #include "osrng.h"
                #include "modes.h"
                #include "aes.h"
                #include "ccm.h"
                #include <iostream>
                
                const double runTimeInSeconds = 3.0;
                const double cpuFreq = 2.7*1000*1000*1000;
                
                int main(int argc, char* argv[])
                {
                    using namespace CryptoPP;
                    AutoSeededRandomPool prng;
                
                    SecByteBlock key(16);
                    prng.GenerateBlock(key, key.size());
                
                    CCM<AES>::Encryption cipher;
                    cipher.SetKeyWithIV(key, key.size(), key);
                
                    const int BUF_SIZE=RoundUpToMultipleOf(2048U,
                        dynamic_cast<StreamTransformation&>(cipher).OptimalBlockSize());
                
                    AlignedSecByteBlock buf(BUF_SIZE);
                    prng.GenerateBlock(buf, BUF_SIZE);
                
                    double elapsedTimeInSeconds;
                    unsigned long i=0, blocks=1;
                
                    ThreadUserTimer timer;
                    timer.StartTimer();
                
                    do
                    {
                        blocks *= 2;
                        for (; i<blocks; i++)
                            cipher.ProcessString(buf, BUF_SIZE);
                        elapsedTimeInSeconds = timer.ElapsedTimeAsDouble();
                    }
                    while (elapsedTimeInSeconds < runTimeInSeconds);
                
                    const double bytes = static_cast<double>(BUF_SIZE) * blocks;
                    const double ghz = cpuFreq / 1000 / 1000 / 1000;
                    const double mbs = bytes / 1024 / 1024 / elapsedTimeInSeconds;
                    const double cpb = elapsedTimeInSeconds * cpuFreq / bytes;
                
                    std::cout << cipher.AlgorithmName() << " benchmarks..." << std::endl;
                    std::cout << "  " << ghz << " GHz cpu frequency" << std::endl;
                    std::cout << "  " << cpb << " cycles per byte (cpb)" << std::endl;
                    std::cout << "  " << mbs << " MiB per second (MiB)" << std::endl;
                    // std::cout << "  " << elapsedTimeInSeconds << " seconds passed" << std::endl;
                    // std::cout << "  " << (word64) bytes << " bytes processed"  << std::endl;
                
                    return 0;
                }
                

                在 2.7 GHz 的 Core i5-6400 上运行结果:

                Running it on a Core i5-6400 at 2.7 GHz results in:

                $ g++ bench.cxx ./libcryptopp.a -o bench.exe
                $ ./bench.exe
                AES/CCM benchmarks...
                  2.7 GHz cpu frequency
                  3.00491 cycles per byte (cpb)
                  856.904 MiB per second (MiB)
                

                <小时>

                通常您使用 CTR 模式对库进行基准测试.例如,所有 SUPERCOP 基准测试都是使用该模式执行的.您可以通过包含 "modes.h" 来切换到 CTR 模式,然后:


                Usually you benchmark a library with CTR mode. For example, all of the SUPERCOP benchmarks are performed using the mode. You can switch to CTR mode by including "modes.h", and then:

                CTR_Mode<AES>::Encryption cipher;
                cipher.SetKeyWithIV(key, key.size(), key);
                

                最后,同样的测试使用CTR模式:

                Finally, the same test using CTR mode:

                $ ./bench.exe
                AES/CTR benchmarks...
                  2.7 GHz cpu frequency
                  0.568922 cycles per byte (cpb)
                  4525.97 MiB per second (MiB)
                

                这篇关于在 Visual Studio 2017 中计算 AES/CCM 的时间加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:我不明白为什么这会导致我的程序崩溃? 下一篇:如何在发布模式下调试?

                相关文章

                • <bdo id='TLcjy'></bdo><ul id='TLcjy'></ul>
                <legend id='TLcjy'><style id='TLcjy'><dir id='TLcjy'><q id='TLcjy'></q></dir></style></legend>
                <tfoot id='TLcjy'></tfoot>

                <small id='TLcjy'></small><noframes id='TLcjy'>

                    <i id='TLcjy'><tr id='TLcjy'><dt id='TLcjy'><q id='TLcjy'><span id='TLcjy'><b id='TLcjy'><form id='TLcjy'><ins id='TLcjy'></ins><ul id='TLcjy'></ul><sub id='TLcjy'></sub></form><legend id='TLcjy'></legend><bdo id='TLcjy'><pre id='TLcjy'><center id='TLcjy'></center></pre></bdo></b><th id='TLcjy'></th></span></q></dt></tr></i><div id='TLcjy'><tfoot id='TLcjy'></tfoot><dl id='TLcjy'><fieldset id='TLcjy'></fieldset></dl></div>