33 r = (r << 32) | rand();
37 static const uint8_t test_key[] = { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
43 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
44 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01,
45 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23
51 int delay = cbc && !decrypt ? 2 : 1;
61 return res == 0xc5cecf63ecec514cULL;
63 return res == 0xcb191f85d1ed8439ULL;
66 return res == 0x8325397644091a0aULL;
68 return res == 0xdd17e8b8b437d232ULL;
82 uint64_t roundkeys[16];
88 printf(
"Test 1 failed\n");
94 printf(
"Public API decryption failed\n");
98 printf(
"Partial Monte-Carlo test failed\n");
101 for (i = 0; i < 1000; i++) {
111 printf(
"Test 2 failed\n");
116 printf(
"static const uint32_t S_boxes_P_shuffle[8][64] = {\n");
117 for (i = 0; i < 8; i++) {
120 for (j = 0; j < 64; j++) {
121 uint32_t v = S_boxes[i][j >> 1];
122 v = j & 1 ? v >> 4 : v & 0xf;
124 v =
shuffle(v, P_shuffle,
sizeof(P_shuffle));
125 printf((j & 7) == 0 ?
"\n " :
" ");
126 printf(
"0x%08X,", v);
static void gen_roundkeys(uint64_t K[16], uint64_t key)
void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt)
Encrypts / decrypts using the DES algorithm.
static const uint8_t cbc_key[]
static const uint8_t plain[]
static uint64_t rand64(void)
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
high precision timer, useful to profile code
int av_des_init(AVDES *d, const uint8_t *key, int key_bits, av_unused int decrypt)
static const uint8_t crypt_ref[]
int64_t av_gettime(void)
Get the current time in microseconds.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_WB16 unsigned int_TMPL byte
static int run_test(int cbc, int decrypt)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_RB64
static uint8_t large_buffer[10002][8]
static uint64_t des_encdec(uint64_t in, uint64_t K[16], int decrypt)
static const uint8_t test_key[]
static uint64_t shuffle(uint64_t in, const uint8_t *shuffle, int shuffle_len)