本文整理匯總了Java中com.sun.spot.security.implementation.ecc.PrimeField類的典型用法代碼示例。如果您正苦於以下問題:Java PrimeField類的具體用法?Java PrimeField怎麽用?Java PrimeField使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PrimeField類屬於com.sun.spot.security.implementation.ecc包,在下文中一共展示了PrimeField類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: verify
import com.sun.spot.security.implementation.ecc.PrimeField; //導入依賴的package包/類
public boolean verify(byte[] outbuf, int offset, int length)
throws SignatureException {
// See: ANSI X9.62-1998, 5.4 Signature Verification
if (verifyKey == null) {
throw new SignatureException("Not initialized.");
}
if (!verifyKey.isInitialized()) {
throw new SignatureException("Key not initialized.");
}
try {
digest.digest(digestBuf, 0,digestBuf.length);
} catch (DigestException e) {
throw new SignatureException(e.getMessage());
}
// We can use the PrimeField class to do all the (mod n) computations
ECCurve curve = verifyKey.getECCurve();
PrimeField field = curve.getOrder();
FFA ffa = field.getFFA();
// check the sequence header
if ((length < 6) || (outbuf[offset++] != (ASN_CONSTRUCTED | ASN_SEQUENCE))) return false;
int sequenceLen = (int)outbuf[offset++];
if ((sequenceLen != length - 2) || (sequenceLen < 4)) return false;
// read the first integer: 'r'
if (outbuf[offset++] != ASN_INTEGER) return false;
int len = (int)outbuf[offset++];
sequenceLen -= (2 + len);
if (sequenceLen < 2) return false;
int[] r = ffa.from(outbuf, offset, len); offset += len;
// read the second integer: 's'
if (outbuf[offset++] != ASN_INTEGER) return false;
len = (int)outbuf[offset++];
sequenceLen -= (2 + len);
if (sequenceLen != 0) return false;
int[] s = ffa.from(outbuf, offset, len);
// 'r' and 's' must be in the interval [1..n-1]
int[] n = field.getP();
if (ffa.is(r, 0) || ffa.is(s, 0) || (ffa.cmp(r, n) >= 0)
|| (ffa.cmp(s, n) >= 0)) {
return false;
}
int[] u1 = ffa.acquireVar();
int[] u2 = ffa.acquireVar();
int[] tmp = ffa.from(ffa.acquireVar(digestBuf.length * 8), digestBuf, 0, digestBuf.length);
field.trim(u1, tmp); // u1 = e mod n
field.invert(s, s);
field.multiply(u1, u1, s); // u1 = (e * s^-1) mod n
field.multiply(u2, r, s); // u2 = (r * s^-1) mod n
ECPoint G = curve.getGenerator().clonePoint();
ECPoint Q = verifyKey.getECPoint();
curve.multiplySum(G, u1, Q, u2); // G = u1 * G + u2 * Q;
field.trim(s, G.x); // s = x1 mod n
boolean verified = (ffa.cmp(r, s) == 0);
ffa.releaseVar(r);
ffa.releaseVar(s);
ffa.releaseVar(u1);
ffa.releaseVar(u2);
G.release();
Q.release();
return verified;
}