diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /third_party/js/PKI.js/src/ECNamedCurves.ts | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/js/PKI.js/src/ECNamedCurves.ts')
-rw-r--r-- | third_party/js/PKI.js/src/ECNamedCurves.ts | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/third_party/js/PKI.js/src/ECNamedCurves.ts b/third_party/js/PKI.js/src/ECNamedCurves.ts new file mode 100644 index 0000000000..123bad1558 --- /dev/null +++ b/third_party/js/PKI.js/src/ECNamedCurves.ts @@ -0,0 +1,53 @@ +export interface ECNamedCurve { + /** + * The curve ASN.1 object identifier + */ + id: string; + /** + * The name of the curve + */ + name: string; + /** + * The coordinate length in bytes + */ + size: number; +} + +export class ECNamedCurves { + + public static readonly namedCurves: Record<string, ECNamedCurve> = {}; + + /** + * Registers an ECC named curve + * @param name The name o the curve + * @param id The curve ASN.1 object identifier + * @param size The coordinate length in bytes + */ + public static register(name: string, id: string, size: number): void { + this.namedCurves[name.toLowerCase()] = this.namedCurves[id] = { name, id, size }; + } + + /** + * Returns an ECC named curve object + * @param nameOrId Name or identifier of the named curve + * @returns + */ + static find(nameOrId: string): ECNamedCurve | null { + return this.namedCurves[nameOrId.toLowerCase()] || null; + } + + static { + // Register default curves + + // NIST + this.register("P-256", "1.2.840.10045.3.1.7", 32); + this.register("P-384", "1.3.132.0.34", 48); + this.register("P-521", "1.3.132.0.35", 66); + + // Brainpool + this.register("brainpoolP256r1", "1.3.36.3.3.2.8.1.1.7", 32); + this.register("brainpoolP384r1", "1.3.36.3.3.2.8.1.1.11", 48); + this.register("brainpoolP512r1", "1.3.36.3.3.2.8.1.1.13", 64); + } + +} |