/** * Generic raw verify any type * * Warning, nonstandard for EdDSA, double-hashes, not recommended. * * @throws GeneralSecurityException if algorithm unvailable or on other errors * @since 0.9.9 */ private boolean altVerifySigRaw(Signature signature, SimpleDataStructure hash, SigningPublicKey verifyingKey) throws GeneralSecurityException { SigType type = signature.getType(); if (type != verifyingKey.getType()) throw new IllegalArgumentException("type mismatch sig=" + type + " key=" + verifyingKey.getType()); PublicKey pubKey = SigUtil.toJavaKey(verifyingKey); return verifySignature(signature, hash, pubKey); }
/** * Generic signature type. * If you have a Java pubkey, use this, so you don't lose the key parameters, * which may be different than the ones defined in SigType. * * Warning, nonstandard for EdDSA, double-hashes, not recommended. * * @param hash SHA1Hash, Hash, Hash384, or Hash512 * @param pubKey Java key * @since 0.9.9 */ public boolean verifySignature(Signature signature, SimpleDataStructure hash, PublicKey pubKey) { try { return altVerifySigRaw(signature, hash, pubKey); } catch (GeneralSecurityException gse) { if (_log.shouldLog(Log.WARN)) _log.warn(signature.getType() + " Sig Verify Fail", gse); return false; } }
SigType type = signature.getType(); int hashlen = hash.length(); if (type.getHashLen() != hashlen)
/** * Generic signature type. * * Warning, nonstandard for EdDSA, double-hashes, not recommended. * * @param hash SHA1Hash, Hash, Hash384, or Hash512 * @since 0.9.9 */ public boolean verifySignature(Signature signature, SimpleDataStructure hash, SigningPublicKey verifyingKey) { SigType type = signature.getType(); if (type != verifyingKey.getType()) throw new IllegalArgumentException("type mismatch sig=" + type + " key=" + verifyingKey.getType()); int hashlen = type.getHashLen(); if (hash.length() != hashlen) throw new IllegalArgumentException("type mismatch hash=" + hash.getClass() + " sig=" + type); if (type == SigType.DSA_SHA1) return verifySig(signature, hash, verifyingKey); try { return altVerifySigRaw(signature, hash, verifyingKey); } catch (GeneralSecurityException gse) { if (_log.shouldLog(Log.WARN)) _log.warn(type + " Sig Verify Fail", gse); return false; } }
/** * Generic verify any type. * * @throws GeneralSecurityException if algorithm unvailable or on other errors * @since 0.9.9 added off/len 0.9.12 */ private boolean altVerifySig(Signature signature, byte[] data, int offset, int len, SigningPublicKey verifyingKey) throws GeneralSecurityException { SigType type = signature.getType(); if (type != verifyingKey.getType()) throw new IllegalArgumentException("type mismatch sig=" + type + " key=" + verifyingKey.getType()); if (type == SigType.DSA_SHA1) return altVerifySigSHA1(signature, data, offset, len, verifyingKey); PublicKey pubKey = SigUtil.toJavaKey(verifyingKey); byte[] sigbytes = SigUtil.toJavaSig(signature); boolean rv; if (type.getBaseAlgorithm() == SigAlgo.EdDSA) { // take advantage of one-shot mode EdDSAEngine jsig = new EdDSAEngine(type.getDigestInstance()); jsig.initVerify(pubKey); rv = jsig.verifyOneShot(data, offset, len, sigbytes); } else { java.security.Signature jsig = java.security.Signature.getInstance(type.getAlgorithmName()); jsig.initVerify(pubKey); jsig.update(data, offset, len); rv = jsig.verify(sigbytes); } return rv; }
return false; SigType type = _signature.getType(); if (type == null || type.getBaseAlgorithm() == SigAlgo.RSA) return false;
if (type != _optionSignature.getType() && type.getSigLen() == _optionSignature.length()) _optionSignature = new Signature(type, _optionSignature.getData());
SigType stype = _leaseSet.getSignature().getType(); if (stype == null) throw new I2CPMessageException("Unsupported sig type");
if (type != _optionSignature.getType() && type.getSigLen() == _optionSignature.length()) _optionSignature = new Signature(type, _optionSignature.getData());