From 1258bc559b23c2075b8758484736674d0dab8b0d Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 1 Jun 2016 06:05:21 +0000 Subject: [PATCH] des_tables.c * missing/crypt_r.c: initialize DES tables statically. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- missing/crypt_r.c | 116 ++- missing/des_tables.c | 1612 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1723 insertions(+), 5 deletions(-) create mode 100644 missing/des_tables.c diff --git a/missing/crypt_r.c b/missing/crypt_r.c index d5a16ac57a..d55937865f 100644 --- a/missing/crypt_r.c +++ b/missing/crypt_r.c @@ -149,6 +149,7 @@ permute(const unsigned char *cp, C_block *out, register const C_block *p, int ch STATIC void prtab(const char *s, const unsigned char *t, int num_rows); #endif +#ifdef DUMP /* ===== (mostly) Standard DES Tables ==================== */ static const unsigned char IP[] = { /* initial permutation */ @@ -186,11 +187,13 @@ static const unsigned char PC1[] = { /* permuted choice table 1 */ 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4, }; +#endif static const unsigned char Rotates[] = { /* PC1 rotation schedule */ 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, }; +#ifdef DUMP /* note: each "row" of PC2 is left-padded with bits that make it invertible */ static const unsigned char PC2[] = { /* permuted choice table 2 */ 9, 18, 14, 17, 11, 24, 1, 5, @@ -285,6 +288,7 @@ static const unsigned char CIFP[] = { /* compressed/interleaved permutation */ 41, 42, 43, 44, 57, 58, 59, 60, 45, 46, 47, 48, 61, 62, 63, 64, }; +#endif static const unsigned char itoa64[] = /* 0..63 => ascii-64 */ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; @@ -305,6 +309,7 @@ static const unsigned char a64toi[256] = { A64TOI64(0x00), A64TOI64(0x40), }; +#ifdef DUMP /* ===== Tables that are initialized at run time ==================== */ typedef struct { @@ -327,8 +332,6 @@ typedef struct { } des_tables_t; static des_tables_t des_tables[1]; -static const C_block constdatablock; /* encryption constant */ - #define des_tables ((const des_tables_t *)des_tables) #define PC1ROT (des_tables->PC1ROT) #define PC2ROT (des_tables->PC2ROT) @@ -336,13 +339,20 @@ static const C_block constdatablock; /* encryption constant */ #define SPE (des_tables->SPE) #define CF6464 (des_tables->CF6464) +STATIC void init_des(void); +STATIC void init_perm(C_block perm[64/CHUNKBITS][1<KS) #define cryptresult (data->cryptresult) #define des_ready (data->initialized) -STATIC void init_des(void); -STATIC void init_perm(C_block perm[64/CHUNKBITS][1<b); ++i) { + printf("%3d,", block->b[i]); + } + printf("}},\n"); +} + +int +main(void) +{ + int i, j, k; + init_des(); + printf("/* Initial key schedule permutation */\n"); + printf("static const C_block PC1ROT[64/CHUNKBITS][1< final permutation table */\n"); + printf("static const C_block CF6464[64/CHUNKBITS][1< final permutation table */ +static const C_block CF6464[64/CHUNKBITS][1<