@dedis/kyber
Version:
A typescript implementation of Kyber interfaces
55 lines (54 loc) • 1.62 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// tslint:disable:no-bitwise
const bn_js_1 = __importDefault(require("bn.js"));
const elliptic_1 = __importDefault(require("elliptic"));
const point_1 = __importDefault(require("./point"));
const scalar_1 = __importDefault(require("./scalar"));
class Weierstrass {
constructor(config) {
const { name, bitSize, gx, gy, p, a, b, n } = config;
this.name = name;
const toBN = (bt) => new bn_js_1.default(bt, 16, "le");
this.curve = new elliptic_1.default.curve.short({
a: toBN(a),
b: toBN(b),
g: [new bn_js_1.default(gx, 16, "le"), new bn_js_1.default(gy, 16, "le")],
n,
p: toBN(p),
});
this.bitSize = bitSize;
this.redN = bn_js_1.default.red(n);
}
coordLen() {
return (this.bitSize + 7) >> 3;
}
/** @inheritdoc */
scalarLen() {
return (this.curve.n.bitLength() + 7) >> 3;
}
/** @inheritdoc */
scalar() {
return new scalar_1.default(this, this.redN);
}
/** @inheritdoc */
pointLen() {
// ANSI X9.62: 1 header byte plus 2 coords
return this.coordLen() * 2 + 1;
}
/** @inheritdoc */
point() {
return new point_1.default(this);
}
/**
* Get the name of the curve
* @returns the name
*/
string() {
return this.name;
}
}
exports.default = Weierstrass;