Files
rspade_system/node_modules/browserify-sign/browser/verify.js
root f6ac36c632 Enhance refactor commands with controller-aware Route() updates and fix code quality violations
Add semantic token highlighting for 'that' variable and comment file references in VS Code extension
Add Phone_Text_Input and Currency_Input components with formatting utilities
Implement client widgets, form standardization, and soft delete functionality
Add modal scroll lock and update documentation
Implement comprehensive modal system with form integration and validation
Fix modal component instantiation using jQuery plugin API
Implement modal system with responsive sizing, queuing, and validation support
Implement form submission with validation, error handling, and loading states
Implement country/state selectors with dynamic data loading and Bootstrap styling
Revert Rsx::Route() highlighting in Blade/PHP files
Target specific PHP scopes for Rsx::Route() highlighting in Blade
Expand injection selector for Rsx::Route() highlighting
Add custom syntax highlighting for Rsx::Route() and Rsx.Route() calls
Update jqhtml packages to v2.2.165
Add bundle path validation for common mistakes (development mode only)
Create Ajax_Select_Input widget and Rsx_Reference_Data controller
Create Country_Select_Input widget with default country support
Initialize Tom Select on Select_Input widgets
Add Tom Select bundle for enhanced select dropdowns
Implement ISO 3166 geographic data system for country/region selection
Implement widget-based form system with disabled state support

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 06:21:56 +00:00

87 lines
2.5 KiB
JavaScript

'use strict';
// much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
var Buffer = require('safe-buffer').Buffer;
var BN = require('bn.js');
var EC = require('elliptic').ec;
var parseKeys = require('parse-asn1');
var curves = require('./curves.json');
function verify(sig, hash, key, signType, tag) {
var pub = parseKeys(key);
if (pub.type === 'ec') {
// rsa keys can be interpreted as ecdsa ones in openssl
if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') { throw new Error('wrong public key type'); }
return ecVerify(sig, hash, pub);
} else if (pub.type === 'dsa') {
if (signType !== 'dsa') { throw new Error('wrong public key type'); }
return dsaVerify(sig, hash, pub);
}
if (signType !== 'rsa' && signType !== 'ecdsa/rsa') { throw new Error('wrong public key type'); }
hash = Buffer.concat([tag, hash]);
var len = pub.modulus.byteLength();
var pad = [1];
var padNum = 0;
while (hash.length + pad.length + 2 < len) {
pad.push(0xff);
padNum += 1;
}
pad.push(0x00);
var i = -1;
while (++i < hash.length) {
pad.push(hash[i]);
}
pad = Buffer.from(pad);
var red = BN.mont(pub.modulus);
sig = new BN(sig).toRed(red);
sig = sig.redPow(new BN(pub.publicExponent));
sig = Buffer.from(sig.fromRed().toArray());
var out = padNum < 8 ? 1 : 0;
len = Math.min(sig.length, pad.length);
if (sig.length !== pad.length) { out = 1; }
i = -1;
while (++i < len) { out |= sig[i] ^ pad[i]; }
return out === 0;
}
function ecVerify(sig, hash, pub) {
var curveId = curves[pub.data.algorithm.curve.join('.')];
if (!curveId) { throw new Error('unknown curve ' + pub.data.algorithm.curve.join('.')); }
var curve = new EC(curveId);
var pubkey = pub.data.subjectPrivateKey.data;
return curve.verify(hash, sig, pubkey);
}
function dsaVerify(sig, hash, pub) {
var p = pub.data.p;
var q = pub.data.q;
var g = pub.data.g;
var y = pub.data.pub_key;
var unpacked = parseKeys.signature.decode(sig, 'der');
var s = unpacked.s;
var r = unpacked.r;
checkValue(s, q);
checkValue(r, q);
var montp = BN.mont(p);
var w = s.invm(q);
var v = g.toRed(montp)
.redPow(new BN(hash).mul(w).mod(q))
.fromRed()
.mul(y.toRed(montp).redPow(r.mul(w).mod(q)).fromRed())
.mod(p)
.mod(q);
return v.cmp(r) === 0;
}
function checkValue(b, q) {
if (b.cmpn(0) <= 0) { throw new Error('invalid sig'); }
if (b.cmp(q) >= 0) { throw new Error('invalid sig'); }
}
module.exports = verify;