use of org.fisco.bcos.web3j.crypto.gm.sm2.crypto.digests.SM3Digest in project web3sdk by FISCO-BCOS.
the class SM2Algorithm method calculateC3.
/*
* 第7步:计算 C3 = Hash(X2 || M || Y2)
*/
private static byte[] calculateC3(BigInteger x2, byte[] m, BigInteger y2) {
SM3Digest sm3 = new SM3Digest();
byte[] c3 = new byte[32];
byte[] x2Buf = padding(x2.toByteArray());
byte[] y2Buf = padding(y2.toByteArray());
sm3.update(x2Buf, 0, x2Buf.length);
sm3.update(m, 0, m.length);
sm3.update(y2Buf, 0, y2Buf.length);
sm3.doFinal(c3, 0);
return c3;
}
use of org.fisco.bcos.web3j.crypto.gm.sm2.crypto.digests.SM3Digest in project web3sdk by FISCO-BCOS.
the class SM2Algorithm method sm2GetZ.
/**
* 计算Za
*
* @param userId
* @param publicKey
* @return
* @date 2015年12月4日
* @author fisco-bcos
*/
private static byte[] sm2GetZ(byte[] userId, ECPoint publicKey) {
SM3Digest sm3 = new SM3Digest();
int BitsLength = userId.length << 3;
sm3.update((byte) (BitsLength >> 8 & 0xFF));
sm3.update((byte) (BitsLength & 0xFF));
sm3BlockUpdate(sm3, userId);
sm3BlockUpdate(sm3, getEncoded(a));
sm3BlockUpdate(sm3, getEncoded(b));
sm3BlockUpdate(sm3, getEncoded(gx));
sm3BlockUpdate(sm3, getEncoded(gy));
ECPoint ecPoint = publicKey.normalize();
sm3BlockUpdate(sm3, getEncoded(ecPoint.getAffineXCoord().toBigInteger()));
sm3BlockUpdate(sm3, getEncoded(ecPoint.getAffineYCoord().toBigInteger()));
byte[] md = new byte[sm3.getDigestSize()];
sm3.doFinal(md, 0);
return md;
}
Aggregations