Skip to content

Instantly share code, notes, and snippets.

@rzarzynski
Last active July 27, 2018 23:40
Show Gist options
  • Save rzarzynski/988106ae3b1985c64f50f05e5e9b3a58 to your computer and use it in GitHub Desktop.
Save rzarzynski/988106ae3b1985c64f50f05e5e9b3a58 to your computer and use it in GitHub Desktop.
#define SIZE_NUM        5
// ...
static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
// ...
#define COND(c) (run && count<0x7fffffff)
// ...
int MAIN(int argc, char **argv)
        {
        // ...
        if (doit[D_CBC_128_AES])
                {
                for (j=0; j<SIZE_NUM; j++)
                        {
                        print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
                        Time_F(START);
                        for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
                                AES_cbc_encrypt(buf,buf,
                                        (unsigned long)lengths[j],&aes_ks1,
                                        iv,AES_ENCRYPT);
                        d=Time_F(STOP);
                        print_result(D_CBC_128_AES,j,count,d);
                        }
                }
        // ...
        if (doit[D_EVP])
                {
                for (j=0; j<SIZE_NUM; j++)
                        {
                        if (evp_cipher)
                                {
                                EVP_CIPHER_CTX ctx;
                                int outl;

                                names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
                                /* -O3 -fschedule-insns messes up an
                                 * optimization here!  names[D_EVP]
                                 * somehow becomes NULL */
                                print_message(names[D_EVP],save_count,
                                        lengths[j]);

                                EVP_CIPHER_CTX_init(&ctx);
                                if(decrypt)
                                        EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
                                else
                                        EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
                                EVP_CIPHER_CTX_set_padding(&ctx, 0);

                                Time_F(START);
                                if(decrypt)
                                        for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
                                                EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
                                else
                                        for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
                                                EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
                                if(decrypt)
                                        EVP_DecryptFinal_ex(&ctx,buf,&outl);
                                else
                                        EVP_EncryptFinal_ex(&ctx,buf,&outl);
                                d=Time_F(STOP);
                                EVP_CIPHER_CTX_cleanup(&ctx);
                                }
                        // ...
                        print_result(D_EVP,j,count,d);
                        }
                }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment