我想用这个方案
âHess - Efficient identity based signature schemes based on pairings.â
Charm-Crypto
.
据我所知
this related question
,序列化元素会得到一个Base64编码的字符串。从那以后
this other question about Base64
signature = {'S1' : S1, 'S2' : S2}
S2_serial = group.serialize(signature['S2'])
sigLenInBase64 = len(S2_serial)
sigLenInByte = (sigLenInBase64 *3)/4
sigLenInBit = sigLenInByte * 8
由于S2是G1的一个组元素,我希望其大小与基础曲线的大小相同(“SS512”的大小为512Bit,“MNT224”的大小为224Bit,等等)。然而,“SS512”和“MNT224”的大小相差28位(分别为540位和252位),而“MNT159”的大小相差21位。为什么?对于给定的曲线,我如何预测它会偏离多少?
我目前的猜测是,我没有考虑一些额外的信息(比如符号的字节)。
更新:
使用公认的答案,我现在可以正确计算如下大小:
def compute_bitsize(base64_input):
b_padded = base64_input.split(str.encode(":"))[1]
pad_size = b_padded.count(str.encode("="))
b_len_without_pad = len(b_padded)-4
byte_len = (b_len_without_pad *3)/4 +(3-pad_size)-1
bit_len = byte_len * 8
return bit_len