This is a specification of a Web Crypto API for OPRF base mode, which is specified in https://datatracker.ietf.org/doc/draft-irtf-cfrg-voprf.
Author: Armando Faz (armfazh@cloudflare.com)
License: BSD-3-Clause
Group | namedCurve | Size of scalar (n bytes) | Size of points (n+1 bytes) |
---|---|---|---|
P-256 | "P-256" | 32 | 33 |
P-384 | "P-384" | 48 | 49 |
P-521 | "P-521" | 66 | 67 |
This is the expected functionality for an OPRF server.
OPRF Method | Spec | WebCrypto Method | Comments |
---|---|---|---|
Keygen | Section 2.1 | key = crypto.subtle.generateKey(algorithm, extractable, keyUsages) | Use this function for generating an OPRF CryptoKey (private key). Internally, the key stores a scalar k. |
Evaluate | Section 3.4.1.1 | sig = crypto.subtle.sign(key, msg) | Behind the scenes, this is a scalar multiplication. key = a CryptoKey containing a scalar k. msg = a compressed point P on the curve (an ArrayBuffer of size n+1) sig = a compressed point kP on the curve (an ArrayBuffer of size n+1) |
crypto.subtle.importKey | Converts raw bytes into an OPRF CryptoKey. During importing, the key can be defined as exportable or not. If exportable, subtle.export can recover the raw bytes from the OPRF CryptoKey. | ||
crypto.subtle.exportKey | if exportable, converts a OPRF CryptoKey into raw bytes. | ||
crypto.subtle.verify (not implemented) | No method is mapped to subtle.verify |
const result = crypto.subtle.generateKey(algorithm, extractable, keyUsages)
algorithm: {
name: "OPRF",
namedCurve: "P-256" // one of "P-256", "P-384", "P-521"
}
extractable: true
keyUsages: [ "sign" ]
It returns a CryptoKey
used only for OPRF signatures.
const signature = crypto.subtle.sign(algorithm, key, data);
algorithm: {
name: "OPRF"
}
key:
key is a CryptoKey
imported with subtle.importKey.
data:
data is an ArrayBuffer containing a compressed point on the curve.
It returns a Promise to an ArrayBufer containing a compressed point on the curve.
const result = crypto.subtle.importKey(
format,
keyData,
algorithm,
extractable,
keyUsages
);
format: "raw"
keyData:
keydata is an ArrayBuffer of length n containing the key.
algorithm: {
name: "OPRF",
namedCurve: "P-256" // one of "P-256", "P-384", "P-521"
}
extractable: true
keyUsages: [ "sign" ]
It returns a CryptoKey
used only for OPRF signatures.
const result = crypto.subtle.exportKey(format, key);
format: "raw"
key:
key is a CryptoKey
used only for OPRF signatures.
It returns an ArrayBuffer of length n containing the key.