Search in sources :

Example 1 with SM3Digest

use of org.bouncycastle.crypto.digests.SM3Digest in project xipki by xipki.

the class GMUtil method getSM2Z.

// CHECKSTYLE:SKIP
public static byte[] getSM2Z(byte[] userID, ASN1ObjectIdentifier curveOid, BigInteger pubPointX, BigInteger pubPointY) {
    SM3Digest digest = new SM3Digest();
    addUserId(digest, userID);
    X9ECParameters ecParams = GMNamedCurves.getByOID(curveOid);
    addFieldElement(digest, ecParams.getCurve().getA());
    addFieldElement(digest, ecParams.getCurve().getB());
    addFieldElement(digest, ecParams.getG().getAffineXCoord());
    addFieldElement(digest, ecParams.getG().getAffineYCoord());
    int fieldSize = (ecParams.getCurve().getFieldSize() + 7) / 8;
    byte[] bytes = BigIntegers.asUnsignedByteArray(fieldSize, pubPointX);
    digest.update(bytes, 0, fieldSize);
    bytes = BigIntegers.asUnsignedByteArray(fieldSize, pubPointY);
    digest.update(bytes, 0, fieldSize);
    byte[] result = new byte[digest.getDigestSize()];
    digest.doFinal(result, 0);
    return result;
}
Also used : SM3Digest(org.bouncycastle.crypto.digests.SM3Digest) X9ECParameters(org.bouncycastle.asn1.x9.X9ECParameters)

Aggregations

X9ECParameters (org.bouncycastle.asn1.x9.X9ECParameters)1 SM3Digest (org.bouncycastle.crypto.digests.SM3Digest)1