Interface KemInterface

The KEM interface.

interface KemInterface {
    encSize: number;
    id: KemId;
    privateKeySize: number;
    publicKeySize: number;
    secretSize: number;
    decap(params: RecipientContextParams): Promise<ArrayBuffer>;
    deriveKeyPair(ikm: ArrayBuffer): Promise<CryptoKeyPair>;
    deserializePrivateKey(key: ArrayBuffer): Promise<CryptoKey>;
    deserializePublicKey(key: ArrayBuffer): Promise<CryptoKey>;
    encap(params: SenderContextParams): Promise<{
        enc: ArrayBuffer;
        sharedSecret: ArrayBuffer;
    }>;
    generateKeyPair(): Promise<CryptoKeyPair>;
    importKey(format: "raw" | "jwk", key: ArrayBuffer | JsonWebKey, isPublic?: boolean): Promise<CryptoKey>;
    serializePrivateKey(key: CryptoKey): Promise<ArrayBuffer>;
    serializePublicKey(key: CryptoKey): Promise<ArrayBuffer>;
}

Properties

encSize: number

The length in bytes of an encapsulated key produced by this KEM (Nenc).

id: KemId

The KEM identifier.

privateKeySize: number

The length in bytes of an encoded private key for this KEM (Nsk).

publicKeySize: number

The length in bytes of an encoded public key for this KEM (Npk).

secretSize: number

The length in bytes of a KEM shared secret produced by this KEM (Nsecret).

Methods

  • Generates an ephemeral, fixed-length symmetric key and a fixed-length encapsulation of the key that can be decapsulated by the holder of the private key corresponding to pkR.

    If the error occurred, throws EncapError.

    Parameters

    Returns Promise<{
        enc: ArrayBuffer;
        sharedSecret: ArrayBuffer;
    }>

    A shared secret and an encapsulated key as the output of the encapsulation step.

    EncapError

  • Imports a public or private key and converts to a CryptoKey.

    Since key parameters for createSenderContext or createRecipientContext are CryptoKey format, you have to use this function to convert provided keys to CryptoKey.

    Basically, this is a thin wrapper function of SubtleCrypto.importKey.

    If the error occurred, throws DeserializeError.

    Parameters

    • format: "raw" | "jwk"

      For now, 'raw' and 'jwk' are supported.

    • key: ArrayBuffer | JsonWebKey

      A byte string of a raw key or A JsonWebKey object.

    • OptionalisPublic: boolean

      The indicator whether the provided key is a public key or not, which is used only for 'raw' format.

    Returns Promise<CryptoKey>

    A public or private CryptoKey.