encrypt

ENCRYPT(3)                 Linux Programmer's Manual                ENCRYPT(3)



åå
       encrypt, setkey, encrypt_r, setkey_r - 64 ãããã®ã¡ãã»ã¼ã¸ãæå·åãã

æ¸å¼
       #define _XOPEN_SOURCE /* feature_test_macros(7) åç§ */
       #include <unistd.h>

       void encrypt(char block[64], int edflag);

       #define _XOPEN_SOURCE /* feature_test_macros(7) åç§ */
       #include <stdlib.h>

       void setkey(const char *key);

       #define _GNU_SOURCE /* feature_test_macros(7) åç§ */
       #include <crypt.h>

       void setkey_r(const char *key, struct crypt_data *data);
       void encrypt_r(char *block, int edflag, struct crypt_data *data);

       ãããã®é¢æ°ã¯ -lcrypt ã§ãªã³ã¯ããå¿è¦ãããã

説æ
       ãããã®é¢æ°ã¯ã64 ãããã®ã¡ãã»ã¼ã¸ã®æå·åã¨å¾©å·åãè¡ãã setkey()  é¢æ°ã¯
       encrypt() ã«ãã£ã¦ä½¿ãããæå·éµãè¨å®ããã ããã§ä½¿ãããå¼ãæ° key 㯠64
       ãã¤ãã®éåã§ãããåãã¤ãã¯æ°å¤ 1 ã¾ã㯠0 ã§ããã n=8*i-1 ã«å¯¾ãããã¤ã key[n]
       ã¯ç¡è¦ãããã®ã§ã æå¹ãªæå·éµã®é·ã㯠56 ãããã«ãªãã

       encrypt()  é¢æ°ã¯ã edflag ã 0 ã®å ´åã¯æå·åãã1
       ã渡ãããå ´åã¯å¾©å·åããã¨ããããã«ã 渡ããããããã¡ãå¤æ´ããã å¼ãæ° key ã¨åæ§ã«ã
       block ã¯ã¨ã³ã³ã¼ããããå®éã®å¤ã表ç¾ãããããã®éåã§ããã
       çµæã¯ãã®åãéåã使ã£ã¦è¿ãããã

       ããã 2 ã¤ã®é¢æ°ã¯ãªã¨ã³ãã©ã³ã (reentrant) ã§ã¯ãªãã
       ã¤ã¾ãæå·éµãã¼ã¿ã¯éçãªé åã«ä¿åãããã é¢æ° setkey_r() 㨠encrypt_r()
       ã¯ãªã¨ã³ãã©ã³ããªãã¼ã¸ã§ã³ã§ããã
       ãããã®é¢æ°ã¯æå·éµãã¼ã¿ãä¿æããããã«ä»¥ä¸ã®ãããªæ§é ä½ã使ãã

           struct crypt_data {
               char     keysched[16 * 8];
               char     sb0[32768];
               char     sb1[32768];
               char     sb2[32768];
               char     sb3[32768];
               char     crypt_3_buf[14];
               char     current_salt[2];
               long int current_saltbits;
               int      direction;
               int      initialized;
           };

       setkey_r()  ãå¼ã³åºãåã«ã¯ã data->initialized ã 0 ã«è¨å®ãããã¨ã

è¿ãå¤
       ãããã®é¢æ°ã¯ããªã«ãå¤ãè¿ããªãã

ã¨ã©ã¼
       ä¸è¨ã®é¢æ°ãå¼ã³åºãåã« errno ã 0 ã«è¨å®ãããã¨ã æåããå ´åããã®å¤ã¯å¤æ´ãããªãã

       ENOSYS (ä¾ãã°ä»¥åã®ã¢ã¡ãªã«åè¡å½è¼¸åºè¦å¶ãªã©ã«ãã)
              ãã®é¢æ°ãæä¾ããã¦ããªãã

æºæ
       é¢æ° encrypt()  㨠setkey()  㯠SVr4, SUSv2, and POSIX.1-2001 ã«æºæ ããã
       é¢æ° encrypt_r()  㨠setkey_r()  㯠GNU æ¡å¼µã§ããã

注æ
       glibc 2.2 ã§ã¯ããããã®é¢æ°ã¯ DES ã¢ã«ã´ãªãºã ã使ãã

ä¾
       ãã®ä¾ã glibc ã§ã³ã³ãã¤ã«ããã«ã¯ libcrypt ã¨ãªã³ã¯ããå¿è¦ãããã
       å®éã«åä½ãããããã«ã¯ãéå key[] 㨠txt[] ã«æå¹ãªããããã¿ã¼ã³ãæå®ããªããã°ãªããªãã

       #define _XOPEN_SOURCE
       #include <unistd.h>
       #include <stdlib.h>

       int
       main(void)
       {
           char key[64];      /* bit pattern for key */
           char txt[64];      /* bit pattern for messages */

           setkey(key);
           encrypt(txt, 0);   /* encode */
           encrypt(txt, 1);   /* decode */
       }

é¢é£é ç®
       cbc_crypt(3), crypt(3), ecb_crypt(3)

ãã®ææ¸ã«ã¤ãã¦
       ãã® man ãã¼ã¸ã¯ Linux man-pages ããã¸ã§ã¯ãã®ãªãªã¼ã¹ 3.51 ã®ä¸é¨
       ã§ãããããã¸ã§ã¯ãã®èª¬æã¨ãã°å ±åã«é¢ããæå ±ã¯
       http://www.kernel.org/doc/man-pages/ ã«æ¸ããã¦ããã



                                  2003-04-04                        ENCRYPT(3)