| 25 |
#include <sys/time.h> |
#include <sys/time.h> |
| 26 |
#include <assert.h> |
#include <assert.h> |
| 27 |
#include <ctype.h> |
#include <ctype.h> |
| 28 |
|
#include <limits.h> |
| 29 |
#include <stdint.h> |
#include <stdint.h> |
| 30 |
#include <stdio.h> |
#include <stdio.h> |
| 31 |
#include <stdlib.h> |
#include <stdlib.h> |
| 34 |
#include "crypt64.h" |
#include "crypt64.h" |
| 35 |
#include "dt4.h" |
#include "dt4.h" |
| 36 |
|
|
| 37 |
#ifdef MMX |
#if defined(USE_MMX) |
| 38 |
|
|
| 39 |
#define N_STRIDE 6 |
#define N_STRIDE 6 |
| 40 |
typedef uint64_t WS_T; |
typedef uint64_t WS_T; |
| 41 |
typedef uint32_t ALU_T; |
typedef uint32_t ALU_T; |
| 42 |
|
|
| 43 |
#else |
#elif defined(USE_64_XMM) |
| 44 |
|
|
| 45 |
|
#define N_STRIDE 7 |
| 46 |
|
typedef unsigned WS_T __attribute__ ((mode(V4SI))); |
| 47 |
|
typedef uint64_t ALU_T; |
| 48 |
|
|
| 49 |
|
#else /* XMM */ |
| 50 |
|
|
| 51 |
#define N_STRIDE 7 |
#define N_STRIDE 7 |
| 52 |
typedef unsigned WS_T __attribute__ ((mode(V4SI))); |
typedef unsigned WS_T __attribute__ ((mode(V4SI))); |
| 54 |
|
|
| 55 |
#endif |
#endif |
| 56 |
|
|
| 57 |
|
#define N_I (sizeof(WS_T) / sizeof(uint32_t)) |
| 58 |
#define N_ALU (sizeof(WS_T) / sizeof(ALU_T)) |
#define N_ALU (sizeof(WS_T) / sizeof(ALU_T)) |
| 59 |
#define ALU_BITS (8 * sizeof(ALU_T)) |
#define ALU_BITS (CHAR_BIT * sizeof(ALU_T)) |
| 60 |
|
|
| 61 |
/* 鍵転置 PC1 */ |
/* 鍵転置 PC1 */ |
| 62 |
static int const tr_pc1[8][7] = |
static int const tr_pc1[8][7] = |
| 88 |
/* 1ビット分 */ |
/* 1ビット分 */ |
| 89 |
typedef union SLICE |
typedef union SLICE |
| 90 |
{ |
{ |
| 91 |
|
uint32_t i[N_I]; /* 32-bit initializer */ |
| 92 |
ALU_T a[N_ALU]; /* C で扱いやすいサイズ */ |
ALU_T a[N_ALU]; /* C で扱いやすいサイズ */ |
| 93 |
WS_T w; /* エンコードで扱うサイズ */ |
WS_T w; /* エンコードで扱うサイズ */ |
| 94 |
} SLICE; |
} SLICE; |
| 862 |
* |
* |
| 863 |
*/ |
*/ |
| 864 |
|
|
| 865 |
#ifdef MMX |
#if N_STRIDE == 6 |
| 866 |
#define C(c,i,j,o) (*(signed char *)((c) + (loo - crypt64_sta) + los[6 * (i) + (j) + (o)])) |
#define C(c,i,j,o) (*(int8_t *)((c) + (loo - crypt64_sta) + los[6 * (i) + (j) + (o)])) |
| 867 |
#else |
#elif N_STRIDE == 7 |
| 868 |
#define C(c,i,j,o) (*(signed long *)((c) + (loo - crypt64_sta) + los[6 * (i) + (j) + (o)])) |
#define C(c,i,j,o) (*(int32_t *)((c) + (loo - crypt64_sta) + los[6 * (i) + (j) + (o)])) |
| 869 |
#endif |
#endif |
| 870 |
|
|
| 871 |
void |
void |
| 1415 |
/* 探索ループだぞっと */ |
/* 探索ループだぞっと */ |
| 1416 |
for (;;) |
for (;;) |
| 1417 |
{ |
{ |
| 1418 |
int cnt; |
int32_t cnt; |
| 1419 |
int k, kk; |
int k, kk; |
| 1420 |
|
|
| 1421 |
/* 鍵のセット */ |
/* 鍵のセット */ |
| 1443 |
if (cr) |
if (cr) |
| 1444 |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
| 1445 |
cr = 0; |
cr = 0; |
| 1446 |
fprintf(stderr, "cycle=%d\n", cnt); |
fprintf(stderr, "cycle=%d\n", (int)cnt); |
| 1447 |
} |
} |
| 1448 |
/* XXX 手抜きのため、ワークにはみ出ている2ビットを落とす */ |
/* XXX 手抜きのため、ワークにはみ出ている2ビットを落とす */ |
| 1449 |
for (i = 0; i < N_ALU; i++) |
for (i = 0; i < N_ALU; i++) |
| 1453 |
for (kk = 0; kk < N_ALU; kk++) |
for (kk = 0; kk < N_ALU; kk++) |
| 1454 |
{ |
{ |
| 1455 |
ALU_T t; |
ALU_T t; |
| 1456 |
//continue;/*XXX*/ |
|
| 1457 |
t = param64.t[31].a[kk]; |
t = param64.t[31].a[kk]; |
|
#if 1 |
|
| 1458 |
if (!t) |
if (!t) |
| 1459 |
continue; |
continue; |
| 1460 |
#endif |
|
| 1461 |
for (k = 0; k < ALU_BITS; k++) |
for (k = 0; k < ALU_BITS; k++) |
| 1462 |
{ |
{ |
| 1463 |
char hash[16]; |
char hash[16]; |
| 1464 |
unsigned char buf[32]; |
unsigned char buf[32]; |
| 1465 |
#if 1 |
|
| 1466 |
if (!(t & (1 << k))) |
if (!(t & ((ALU_T)1 << k))) |
| 1467 |
continue; |
continue; |
| 1468 |
#endif |
|
| 1469 |
for (i = 1; i < 11; i++) |
for (i = 1; i < 11; i++) |
| 1470 |
{ |
{ |
| 1471 |
unsigned c = 0; |
unsigned c = 0; |
| 1472 |
for (j = 0; j < 6; j++) |
for (j = 0; j < 6; j++) |
| 1473 |
c = (c << 1) | !!(param64.lr[0][tr_fp[6 * i + j]].a[kk] & (1 << k)); |
c = (c << 1) | !!(param64.lr[0][tr_fp[6 * i + j]].a[kk] & ((ALU_T)1 << k)); |
| 1474 |
hash[i - 1] = c["./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"]; |
hash[i - 1] = c["./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"]; |
| 1475 |
} |
} |
| 1476 |
hash[10] = 0; |
hash[10] = 0; |
| 1477 |
|
|
| 1478 |
memcpy(buf, key, 32); |
memcpy(buf, key, 32); |
| 1479 |
buf[8] = buf[9] = 0; |
buf[8] = buf[9] = 0; |
| 1480 |
buf[7] = (buf[7] & 0x40) + 32 * kk + k; |
buf[7] = (buf[7] & (1 << N_STRIDE) & 0x7F) + ALU_BITS * kk + k; |
| 1481 |
if (translate(buf, 0, 1)) |
if (translate(buf, 0, 1)) |
| 1482 |
{ |
{ |
| 1483 |
if (cr) |
if (cr) |