任意のサイズのキー (1 バイトから任意のサイズ) を使用する場合、openssl はどのようにキーと連携しますか。ここで実際のキーに移動する手順は何ですか..
openssl enc -d -des-ecb -in cipher.txt -out text.out -K '530343412312345445123345677812345678812324'
任意のサイズのキー (1 バイトから任意のサイズ) を使用する場合、openssl はどのようにキーと連携しますか。ここで実際のキーに移動する手順は何ですか..
openssl enc -d -des-ecb -in cipher.txt -out text.out -K '530343412312345445123345677812345678812324'
opensslはキーでどのように機能しますか...手順は何ですか...
プログラムによって異なりますが、プロシージャは通常、ライブラリ全体で一貫しています。あなたの例では、を使用しているopenssl dec
ため、dec
サブプログラムを使用しています。ソース コードは<openssl dir>/apps/enc.c
(enc
およびdec
の一部enc.c
) で入手できます。
関連する部分は次のとおりです。
unsigned char key[EVP_MAX_KEY_LENGTH],iv[EVP_MAX_IV_LENGTH];
unsigned char salt[PKCS5_SALT_LEN];
...
char *hkey=NULL,*hiv=NULL,*hsalt = NULL;
への引数-K
は次の場所に格納されhkey
ます。
else if (strcmp(*argv,"-K") == 0)
{
if (--argc < 1) goto bad;
hkey= *(++argv);
}
次に、580行目あたり:
if ((hkey != NULL) && !set_hex(hkey,key,sizeof key))
{
/* Handle failure */
}
set_hex
は以下に示され、16 進数は を介して渡された引数をデコードします-K
。を介して未使用の長さを 0 で埋め戻しmemset
ます。未使用の長さは、長さの引数をEVP_MAX_KEY_LENGTH
引いたものです (16 進デコード後)。-K
最後に、610行目あたり:
if (!EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, enc))
{
/* Handle failure */
}
注: -k
(small k
) は別のコード パスを取りEVP_BytesToKey
、キーの派生に使用します。
int set_hex(char *in, unsigned char *out, int size)
{
int i,n;
unsigned char j;
n=strlen(in);
if (n > (size*2))
{
BIO_printf(bio_err,"hex string is too long\n");
return(0);
}
memset(out,0,size);
for (i=0; i<n; i++)
{
j=(unsigned char)*in;
*(in++)='\0';
if (j == 0) break;
if ((j >= '0') && (j <= '9'))
j-='0';
else if ((j >= 'A') && (j <= 'F'))
j=j-'A'+10;
else if ((j >= 'a') && (j <= 'f'))
j=j-'a'+10;
else
{
BIO_printf(bio_err,"non-hex digit\n");
return(0);
}
if (i&1)
out[i/2]|=j;
else
out[i/2]=(j<<4);
}
return(1);
}