UNPKG

tink-crypto

Version:

A multi-language, cross-platform library that provides cryptographic APIs that are secure, easy to use correctly, and hard(er) to misuse.

58 lines (57 loc) 2.65 kB
/** * @license * Copyright 2022 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { HpkeAead } from './hpke_aead'; import { HpkeKdf } from './hpke_kdf'; import { HpkeKem } from './hpke_kem'; import { NistCurvesHpkeKemPrivateKey } from './nist_curves_hpke_kem_private_key'; /** * Hybrid Public Key Encryption (HPKE) context for either a sender or a * recipient. * * @see https://www.rfc-editor.org/rfc/rfc9180.html#name-creating-the-encryption-con */ export declare class HpkeContext { private readonly encapsulatedKey; private readonly key; private readonly baseNonce; private readonly aead; private sequenceNumber; private readonly maxSequenceNumber; constructor(encapsulatedKey: Uint8Array, key: Uint8Array, baseNonce: Uint8Array, aead: HpkeAead); /** * Performs AEAD encryption of `plaintext` with `associatedData` * according to `ContextS.Seal()` as defined in * @see https://www.rfc-editor.org/rfc/rfc9180.html#section-5.2-8. */ seal(plaintext: Uint8Array, associatedData: Uint8Array): Promise<Uint8Array>; /** * Performs AEAD decryption of `ciphertext` with `associatedData` * according to `ContextR.Open()` as defined in * @see https://www.rfc-editor.org/rfc/rfc9180.html#section-5.2-10. */ open(ciphertext: Uint8Array, associatedData: Uint8Array): Promise<Uint8Array>; /** * Computes nonce according to `ComputeNonce` as defined in * @see https://www.rfc-editor.org/rfc/rfc9180.html#section-5.2-11. * for seal/open and increments the sequence number. */ private computeNonceAndIncrementSequenceNumber; getKey(): Uint8Array; getBaseNonce(): Uint8Array; getEncapsulatedKey(): Uint8Array; } /** Helper function factored out to facilitate unit testing. */ export declare function createContext(encapsulatedKey: Uint8Array, sharedSecret: Uint8Array, kem: HpkeKem, kdf: HpkeKdf, aead: HpkeAead, info: Uint8Array): Promise<HpkeContext>; /** * Creates HPKE sender context according to `KeySchedule` as defined in * @see https://www.rfc-editor.org/rfc/rfc9180.html#section-5.1-9. */ export declare function createSenderContext(recipientPublicKey: Uint8Array, kem: HpkeKem, kdf: HpkeKdf, aead: HpkeAead, info: Uint8Array): Promise<HpkeContext>; /** * Creates HPKE recipient context according to `KeySchedule` as defined in * @see https://www.rfc-editor.org/rfc/rfc9180.html#section-5.1-9. */ export declare function createRecipientContext(encapsulatedKey: Uint8Array, recipientPrivateKey: NistCurvesHpkeKemPrivateKey, kem: HpkeKem, kdf: HpkeKdf, aead: HpkeAead, info: Uint8Array): Promise<HpkeContext>;