tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ECNamedCurves.ts (1340B)


      1 export interface ECNamedCurve {
      2  /**
      3   * The curve ASN.1 object identifier
      4   */
      5  id: string;
      6  /**
      7   * The name of the curve
      8   */
      9  name: string;
     10  /**
     11   * The coordinate length in bytes
     12   */
     13  size: number;
     14 }
     15 
     16 export class ECNamedCurves {
     17 
     18  public static readonly namedCurves: Record<string, ECNamedCurve> = {};
     19 
     20  /**
     21   * Registers an ECC named curve
     22   * @param name The name o the curve
     23   * @param id The curve ASN.1 object identifier
     24   * @param size The coordinate length in bytes
     25   */
     26  public static register(name: string, id: string, size: number): void {
     27    this.namedCurves[name.toLowerCase()] = this.namedCurves[id] = { name, id, size };
     28  }
     29 
     30  /**
     31  * Returns an ECC named curve object
     32  * @param nameOrId Name or identifier of the named curve
     33  * @returns
     34  */
     35  static find(nameOrId: string): ECNamedCurve | null {
     36    return this.namedCurves[nameOrId.toLowerCase()] || null;
     37  }
     38 
     39  static {
     40    // Register default curves
     41 
     42    // NIST
     43    this.register("P-256", "1.2.840.10045.3.1.7", 32);
     44    this.register("P-384", "1.3.132.0.34", 48);
     45    this.register("P-521", "1.3.132.0.35", 66);
     46 
     47    // Brainpool
     48    this.register("brainpoolP256r1", "1.3.36.3.3.2.8.1.1.7", 32);
     49    this.register("brainpoolP384r1", "1.3.36.3.3.2.8.1.1.11", 48);
     50    this.register("brainpoolP512r1", "1.3.36.3.3.2.8.1.1.13", 64);
     51  }
     52 
     53 }