Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

大数在转化为byte数组时会溢出一位 #10

Open
hyfree opened this issue Jul 22, 2019 · 7 comments
Open

大数在转化为byte数组时会溢出一位 #10

hyfree opened this issue Jul 22, 2019 · 7 comments

Comments

@hyfree
Copy link

hyfree commented Jul 22, 2019

BigInteger 在转化为byte数组时会会出现一个补位

BigInteger 在转化为byte数组时会会出现一个补位,导致最后的sm3-Hash的计算作物,ZA计算错误

需要在计算sm3杂凑值时,做如下处理

byte[] array = bigInteger.toByteArray();
if (array[0] == 0) {
    byte[] tmp = new byte[array.length - 1];
    System.arraycopy(array, 1, tmp, 0, tmp.length);
    array = tmp;
}

SM2.java中的byte[] ZA(String IDA,Ecpoint aPublicKey)中处理

//这一行的sm3hash中的参数都要做上面的处理
byte[] ZA=sm3hash(............................);

链接
BigInteger to byte[]

IDA

USERID说明

请参阅SM2椭圆曲线公钥密码算法-P54 用户其他信息一栏。
USERID非IDa

设用户A的身份是:[email protected]。用ASCII编码记ID A :
414C 49434531 32334059 41484F4F 2E434F4D。ENTL A =0090。

https://github.com/hyfree/SM2_SM3_SM4Encrypt/tree/add_pdf/pdf

#9

@leesonchen
Copy link

正确。有好几处都要处理。

@hyfree
Copy link
Author

hyfree commented Apr 16, 2020

现在有2012国密规范了,sm2加密部分与2010版的略微不同。网上的部分大部分是2010规定写的。

@hyfree
Copy link
Author

hyfree commented Apr 16, 2020

另外注意一下国密推荐参数的问题

@wsliym
Copy link

wsliym commented Apr 21, 2020

2012规范和2010规范能相互加解密吗?

@hyfree
Copy link
Author

hyfree commented Apr 21, 2020

不能

@hyfree
Copy link
Author

hyfree commented Apr 21, 2020

c1c2c3顺序不一样

@hyfree
Copy link
Author

hyfree commented Apr 21, 2020

需要调整c1c2c3的顺序

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants