From 49895f21a6fbbe1b2dd038cc8b9425f897ada204 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 1 Jun 2016 00:14:32 +0000 Subject: add crypt_r * missing/crypt.c (crypt_r, setkey_r, encrypt_r): add reentrant versions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- missing/crypt.c | 133 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 94 insertions(+), 39 deletions(-) (limited to 'missing') diff --git a/missing/crypt.c b/missing/crypt.c index 912605a02d..00e4adafb4 100644 --- a/missing/crypt.c +++ b/missing/crypt.c @@ -43,6 +43,7 @@ static char sccsid[] = "@(#)crypt.c 8.1 (Berkeley) 6/4/93"; #include #endif #include +#include #ifndef _PASSWORD_EFMT1 #define _PASSWORD_EFMT1 '_' #endif @@ -107,9 +108,6 @@ static char sccsid[] = "@(#)crypt.c 8.1 (Berkeley) 6/4/93"; #define LARGEDATA #endif -void des_setkey(const char *key); -void des_cipher(const char *in, char *out, long salt, int num_iter); - /* compile with "-DSTATIC=int" when profiling */ #ifndef STATIC #define STATIC static @@ -315,9 +313,6 @@ permute(unsigned char *cp, C_block *out, register C_block *p, int chars_in) } #endif /* LARGEDATA */ -STATIC void init_des(void); -STATIC void init_perm(C_block perm[64/CHUNKBITS][1< ascii-64 */ /* ===== Tables that are initialized at run time ==================== */ +struct crypt_data { -static unsigned char a64toi[128]; /* ascii-64 => 0..63 */ + unsigned char a64toi[128]; /* ascii-64 => 0..63 */ -/* Initial key schedule permutation */ -static C_block PC1ROT[64/CHUNKBITS][1< final permutation table */ -static C_block CF6464[64/CHUNKBITS][1< final permutation table */ + C_block CF6464[64/CHUNKBITS][1<a64toi) +#define PC1ROT (data->PC1ROT) +#define PC2ROT (data->PC2ROT) +#define IE3264 (data->IE3264) +#define SPE (data->SPE) +#define CF6464 (data->CF6464) +#define KS (data->KS) +#define constdatablock (data->constdatablock) +#define cryptresult (data->cryptresult) +#define des_ready (data->initialized) + +char *crypt(const char *key, const char *setting); +void des_setkey(const char *key); +void des_cipher(const char *in, char *out, long salt, int num_iter); +void setkey(const char *key); +void encrypt(char *block, int flag); -static C_block constdatablock; /* encryption constant */ -static char cryptresult[1+4+4+11+1]; /* encrypted result */ +char *crypt_r(const char *key, const char *setting, struct crypt_data *data); +void des_setkey_r(const char *key, struct crypt_data *data); +void des_cipher_r(const char *in, char *out, long salt, int num_iter, struct crypt_data *data); +void setkey_r(const char *key, struct crypt_data *data); +void encrypt_r(char *block, int flag, struct crypt_data *data); + +STATIC void init_des(struct crypt_data *); +STATIC void init_perm(C_block perm[64/CHUNKBITS][1<= 0; i--) { k = cblock.b[i]; for (j = 7; j >= 0; j--) { -- cgit v1.2.3