mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-06 15:49:50 +08:00
avutil/aes: use pthread_once to fill the static tables
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
@ -29,6 +29,7 @@
|
|||||||
#include "intreadwrite.h"
|
#include "intreadwrite.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
#include "thread.h"
|
||||||
|
|
||||||
const int av_aes_size= sizeof(AVAES);
|
const int av_aes_size= sizeof(AVAES);
|
||||||
|
|
||||||
@ -197,22 +198,14 @@ static void init_multbl2(uint32_t tbl[][256], const int c[4],
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is based on the reference AES code by Paulo Barreto and Vincent Rijmen
|
static AVOnce aes_static_init = AV_ONCE_INIT;
|
||||||
int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
|
|
||||||
|
static void aes_init_static(void)
|
||||||
{
|
{
|
||||||
int i, j, t, rconpointer = 0;
|
|
||||||
uint8_t tk[8][4];
|
|
||||||
int KC = key_bits >> 5;
|
|
||||||
int rounds = KC + 6;
|
|
||||||
uint8_t log8[256];
|
uint8_t log8[256];
|
||||||
uint8_t alog8[512];
|
uint8_t alog8[512];
|
||||||
|
int i, j = 1;
|
||||||
|
|
||||||
a->crypt = decrypt ? aes_decrypt : aes_encrypt;
|
|
||||||
if (ARCH_X86)
|
|
||||||
ff_init_aes_x86(a, decrypt);
|
|
||||||
|
|
||||||
if (!enc_multbl[FF_ARRAY_ELEMS(enc_multbl) - 1][FF_ARRAY_ELEMS(enc_multbl[0]) - 1]) {
|
|
||||||
j = 1;
|
|
||||||
for (i = 0; i < 255; i++) {
|
for (i = 0; i < 255; i++) {
|
||||||
alog8[i] = alog8[i + 255] = j;
|
alog8[i] = alog8[i + 255] = j;
|
||||||
log8[j] = i;
|
log8[j] = i;
|
||||||
@ -233,6 +226,20 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
|
|||||||
log8, alog8, sbox);
|
log8, alog8, sbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this is based on the reference AES code by Paulo Barreto and Vincent Rijmen
|
||||||
|
int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
|
||||||
|
{
|
||||||
|
int i, j, t, rconpointer = 0;
|
||||||
|
uint8_t tk[8][4];
|
||||||
|
int KC = key_bits >> 5;
|
||||||
|
int rounds = KC + 6;
|
||||||
|
|
||||||
|
a->crypt = decrypt ? aes_decrypt : aes_encrypt;
|
||||||
|
if (ARCH_X86)
|
||||||
|
ff_init_aes_x86(a, decrypt);
|
||||||
|
|
||||||
|
ff_thread_once(&aes_static_init, aes_init_static);
|
||||||
|
|
||||||
if (key_bits != 128 && key_bits != 192 && key_bits != 256)
|
if (key_bits != 128 && key_bits != 192 && key_bits != 256)
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user