Browse Source

Speed up AES-NI detection significantly

tags/v1.0
Bernhard Fröhlich 5 years ago
parent
commit
358f52e724
1 changed files with 6 additions and 12 deletions
  1. 6
    12
      drmdecrypt.c

+ 6
- 12
drmdecrypt.c View File

@@ -20,7 +20,7 @@
20 20
 
21 21
 
22 22
 block_state state;
23
-unsigned short enable_aesni = 1;
23
+int enable_aesni = 0;
24 24
 
25 25
 
26 26
 /*
@@ -30,18 +30,10 @@ int Check_CPU_support_AES()
30 30
 {
31 31
 #if defined(__INTEL_COMPILER)
32 32
    int CPUInfo[4] = {-1};
33
-
34
-   if(!enable_aesni)
35
-      return 0;
36
-
37 33
    __cpuid(CPUInfo, 1);
38 34
    return (CPUInfo[2] & 0x2000000);
39 35
 #else
40 36
    unsigned int a=1,b,c,d;
41
-
42
-   if(!enable_aesni)
43
-      return 0;
44
-
45 37
    __cpuid(1, a,b,c,d);
46 38
    return (c & 0x2000000);
47 39
 #endif
@@ -88,7 +80,7 @@ int readdrmkey(char *mdbfile)
88 80
       trace(TRC_INFO, "drm key successfully read from %s", basename(mdbfile));
89 81
       trace(TRC_INFO, "KEY: %s", tmpbuf);
90 82
 
91
-      if(Check_CPU_support_AES())
83
+      if(enable_aesni)
92 84
          block_init_aesni(&state, drmkey, BLOCK_SIZE);
93 85
       else
94 86
          block_init_aes(&state, drmkey, BLOCK_SIZE);
@@ -159,7 +151,7 @@ int decrypt_aes128cbc(unsigned char *pin, int len, unsigned char *pout)
159 151
 
160 152
    for(i=0; i < len; i+=BLOCK_SIZE)
161 153
    {
162
-      if(Check_CPU_support_AES())
154
+      if(enable_aesni)
163 155
          block_decrypt_aesni(&state, pin + i, pout + i);
164 156
       else
165 157
          block_decrypt_aes(&state, pin + i, pout + i);
@@ -291,6 +283,8 @@ int main(int argc, char *argv[])
291 283
    memset(inffile, '\0', sizeof(inffile));
292 284
    memset(outfile, '\0', sizeof(outfile));
293 285
 
286
+   enable_aesni = Check_CPU_support_AES();
287
+
294 288
    while ((ch = getopt(argc, argv, "o:x")) != -1)
295 289
    {
296 290
       switch (ch)
@@ -313,7 +307,7 @@ int main(int argc, char *argv[])
313 307
       exit(EXIT_FAILURE);
314 308
    }
315 309
 
316
-   trace(TRC_INFO, "AES-NI CPU support %s", Check_CPU_support_AES() ? "enabled" : "disabled");
310
+   trace(TRC_INFO, "AES-NI CPU support %s", enable_aesni ? "enabled" : "disabled");
317 311
 
318 312
    strcpy(srffile, argv[optind]);
319 313
 

Loading…
Cancel
Save