MCPcopy Index your code
hub / github.com/SeanDragon/protools / verify

Method verify

security/src/main/java/pro/tools/security/sm/SM2.java:523–547  ·  view source on GitHub ↗

验签 @param M 签名信息 @param signature 签名 @param IDA 签名方唯一标识 @param aPublicKey 签名方公钥 @return true or false

(String M, Signature signature, String IDA, ECPoint aPublicKey)

Source from the content-addressed store, hash-verified

521 * @return true or false
522 */
523 public boolean verify(String M, Signature signature, String IDA, ECPoint aPublicKey) {
524 if (!between(signature.r, BigInteger.ONE, n)) {
525 return false;
526 }
527 if (!between(signature.s, BigInteger.ONE, n)) {
528 return false;
529 }
530
531 byte[] M_ = join(ZA(IDA, aPublicKey), M.getBytes());
532 BigInteger e = new BigInteger(1, sm3hash(M_));
533 BigInteger t = signature.r.add(signature.s).mod(n);
534
535 if (t.equals(BigInteger.ZERO)) {
536 return false;
537 }
538
539 ECPoint p1 = G.multiply(signature.s).normalize();
540 ECPoint p2 = aPublicKey.multiply(t).normalize();
541 BigInteger x1 = p1.add(p2).normalize().getXCoord().toBigInteger();
542 BigInteger R = e.add(x1).mod(n);
543 if (R.equals(signature.r)) {
544 return true;
545 }
546 return false;
547 }
548
549 /**
550 * 传输实体类

Callers

nothing calls this directly

Calls 6

betweenMethod · 0.95
joinMethod · 0.95
ZAMethod · 0.95
sm3hashMethod · 0.95
addMethod · 0.80
equalsMethod · 0.45

Tested by

no test coverage detected