填充在SHA256消息 [英] Padding the message in SHA256

查看:592
本文介绍了填充在SHA256消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解SHA256。在维基百科页面这样说的:

I am trying to understand SHA256. On the Wikipedia page it says:

追加位1的消息

追加k比特'0',其中k是最小数目> = 0,使得所得的消息       长度(模512位)为448。

append k bits '0', where k is the minimum number >= 0 such that the resulting message length (modulo 512 in bits) is 448.

附加信息的长度(不包括'1'位或填充),中位,64位大端   整       (这将使整个后处理的长度为512位的倍数)

append length of message (without the '1' bit or padding), in bits, as 64-bit big-endian integer (this will make the entire post-processed length a multiple of 512 bits)

所以,如果我的信息是 01100001 01100010 01100011 我先添加一个 1 获得

So if my message is 01100001 01100010 01100011 I would first add a 1 to get

01100001 01100010 01100011 1

然后你将填补 0 如此,总长度为448 MOD 512:

Then you would fill in 0s so that the total length is 448 mod 512:

01100001 01100010 01100011千万0000 ... 0000

(因此,在本实施例中,人们会添加448 - 25 0 多个)

(So in this example, one would add 448 - 25 0s)

我的问题是:什么是后半句是什么意思?我希望看到一个例子。

My question is: What does the last part mean? I would like to see an example.

推荐答案

这意味着消息长度,填充至64位,出现以意义的字节。因此,如果消息长度为37113,这是90 F9以十六进制;两个字节。有两种基本的(*)的方式来重新present此作为一个64位整数,

It means the message length, padded to 64 bits, with the bytes appearing in order of significance. So if the message length is 37113, that's 90 f9 in hex; two bytes. There are two basic(*) ways to represent this as a 64-bit integer,

00 00 00 00 00 00 90 f9  # big endian

f9 90 00 00 00 00 00 00  # little endian

,前者约定如下号码通常写在小数方式:102写102,与被写入第一最显著的部分(以下简称大底),最少的显著(小末)持续。认为这是明确指定的原因是,这两个约定在实践中使用;网络协议采用大端,英特尔兼容处理器使用little endian的,所以,如果他们是十进制的机器,他们会写102为201。

The former convention follows the way numbers are usually written out in decimal: one hundred and two is written 102, with the most significant part (the "big end") being written first, the least significant ("little end") last. The reason that this is specified explicitly is that both conventions are used in practice; internet protocols use big endian, Intel-compatible processors use little endian, so if they were decimal machines, they'd write one hundred and two as 201.

(*)其实有8! = 40320的方法来重新present一个64位整数,如果8位字节是最小的单位要被排列,但两者在实际使用中。

(*) Actually there are 8! = 40320 ways to represent a 64-bit integer if 8-bit bytes are the smallest units to be permuted, but two are in actual use.

这篇关于填充在SHA256消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆