encryptのヘルプ・マニュアル
日本語 英語
encrypt --help
man encrypt
ENCRYPT(3) Linux Programmer’s Manual ENCRYPT(3)
名前
encrypt, setkey, encrypt_r, setkey_r - 64 ビットのメッセージを暗号化す
る
書式
#define _XOPEN_SOURCE
#include
void encrypt(char block[64], int edflag);
#define _XOPEN_SOURCE
#include
void setkey(const char *key);
#define _GNU_SOURCE
#include
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
#include
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), feature_test_macros(7)
2003-04-04 ENCRYPT(3)
ENCRYPT(3) Linux Programmer’s Manual ENCRYPT(3)
NAME
encrypt, setkey, encrypt_r, setkey_r - encrypt 64-bit messages
SYNOPSIS
#define _XOPEN_SOURCE
#include
void encrypt(char block[64], int edflag);
#define _XOPEN_SOURCE
#include
void setkey(const char *key);
#define _GNU_SOURCE
#include
void setkey_r(const char *key, struct crypt_data *data);
void encrypt_r(char *block, int edflag, struct crypt_data *data);
Each of these requires linking with -lcrypt.
DESCRIPTION
These functions encrypt and decrypt 64-bit messages. The setkey()
function sets the key used by encrypt(). The key argument used here is
an array of 64 bytes, each of which has numerical value 1 or 0. The
bytes key[n] where n=8*i-1 are ignored, so that the effective key
length is 56 bits.
The encrypt() function modifies the passed buffer, encoding if edflag
is 0, and decoding if 1 is being passed. Like the key argument, also
block is a bit vector representation of the actual value that is
encoded. The result is returned in that same vector.
These two functions are not reentrant, that is, the key data is kept in
static storage. The functions setkey_r() and encrypt_r() are the reen-
trant versions. They use the following structure to hold the key data:
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;
};
Before calling setkey_r() set data->initialized to zero.
RETURN VALUE
These functions do not return any value.
ERRORS
Set errno to zero before calling the above functions. On success, it
is unchanged.
ENOSYS The function is not provided. (For example because of former
USA export restrictions.)
CONFORMING TO
The functions encrypt() and setkey() conform to SVr4, SUSv2, and
POSIX.1-2001. The functions encrypt_r() and setkey_r() are GNU exten-
sions.
NOTES
In glibc 2.2 these functions use the DES algorithm.
EXAMPLE
You need to link with libcrypt to compile this example with glibc. To
do useful work the key[] and txt[] arrays must be filled with a useful
bit pattern.
#define _XOPEN_SOURCE
#include
#include
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 */
}
SEE ALSO
cbc_crypt(3), crypt(3), ecb_crypt(3), feature_test_macros(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
2003-04-04 ENCRYPT(3)