ここで、最後のチャンクは埋め込まれる必要がありますか、それとも文字列全体ですか?
私は物事の両方が同じであると信じています。文字列全体を埋め込むことは、最後のチャンクだけをパディングすることを意味します。
いくつかの擬似コード
here古き良きウィキからのコードを見てみると、あなたにいくつかの洞察力を与えるかもしれない:
から撮影:mattmahoney.net/dc/sha1.c
void SHA1PadMessage(SHA1Context *context)
{
/*
* Check to see if the current message block is too small to hold
* the initial padding bits and length. If so, we will pad the
* block, process it, and then continue padding into a second
* block.
*/
if (context->Message_Block_Index > 55)
{
context->Message_Block[context->Message_Block_Index++] = 0x80;
while(context->Message_Block_Index < 64)
{
context->Message_Block[context->Message_Block_Index++] = 0;
}
SHA1ProcessMessageBlock(context);
while(context->Message_Block_Index < 56)
{
context->Message_Block[context->Message_Block_Index++] = 0;
}
}
else
{
context->Message_Block[context->Message_Block_Index++] = 0x80;
while(context->Message_Block_Index < 56)
{
context->Message_Block[context->Message_Block_Index++] = 0;
}
}
/*
* Store the message length as the last 8 octets
*/
context->Message_Block[56] = context->Length_High >> 24;
context->Message_Block[57] = context->Length_High >> 16;
context->Message_Block[58] = context->Length_High >> 8;
context->Message_Block[59] = context->Length_High;
context->Message_Block[60] = context->Length_Low >> 24;
context->Message_Block[61] = context->Length_Low >> 16;
context->Message_Block[62] = context->Length_Low >> 8;
context->Message_Block[63] = context->Length_Low;
SHA1ProcessMessageBlock(context);
}
出典
2016-09-01 07:43:08
PRP
しかし、あなたの場合には、文字列全体の長さがありますストリングの最後のパディングされていない部分の長さと等しくない。そして、パディング後、最後の8バイトに長さを挿入する必要があります。しかし、これはどれくらいの長さですか?メッセージ全体の長さですか? –
はい...パディング – PRP
とメッセージ全体の長さのおかげで、非常に微妙な細部もしそうなら、時には物事をぼかす:) –